Skip to content

Commit

Permalink
add redButton component jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domq077 committed Dec 31, 2020
1 parent a768b6b commit 49e7a58
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/app/redButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ export const redButton = (text) => {
const app = document.querySelector('#swquiz-app');
const button = document.createElement('button');
let buttonText = document.createTextNode(`${text}`);
button.setAttribute('id', 'red-button')
button.setAttribute('class', 'button button--red');
button.setAttribute('id', 'red-button');
button.setAttribute('class', 'button button--red button--uppercase');
button.setAttribute('data-testid', 'red-button');
button.appendChild(buttonText);
app.appendChild(button);
}
2 changes: 0 additions & 2 deletions styles/App.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import './components/redButton.css';

body {
font-family: 'Montserrat', sans-serif;
}
Expand Down
26 changes: 26 additions & 0 deletions test/redButton.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { redButton } from '../src/app/redButton'
import { screen } from '@testing-library/dom'
import '@testing-library/jest-dom/extend-expect';

test('button has class button button--red button--uppercase', () => {
document.body.innerHTML = `<div id="swquiz-app"></div>`;
const testText = 'play the game';
redButton(testText);
expect(screen.getByTestId('red-button')).toHaveClass('button button--red button--uppercase');
})

test('button has text', () => {
document.body.innerHTML = `<div id="swquiz-app"></div>`;
const testText = 'play the game';
redButton(testText);
expect(screen.getByTestId('red-button')).not.toBeEmptyDOMElement();
})

test('button has text - play the game', () => {
document.body.innerHTML = `<div id="swquiz-app"></div>`;
const testText = 'play the game';
redButton(testText);
expect(screen.getByTestId('red-button')).toHaveTextContent('play the game');
})


0 comments on commit 49e7a58

Please sign in to comment.