-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from kheitkamp/unit_tests
Unit tests
- Loading branch information
Showing
10 changed files
with
53,619 additions
and
4,229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ | |
.cache | ||
.eslintcache | ||
dist/*.map | ||
.env | ||
.env | ||
report.*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', {targets: {node: 'current'}}], | ||
'@babel/preset-typescript', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
presets: [ | ||
'@testing-library/jest-dom/extend-expect', | ||
], | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import '@testing-library/jest-dom' | ||
|
||
import {render, fireEvent} from '@testing-library/svelte' | ||
|
||
import Button from "./Button.svelte"; | ||
describe("Button component", () => { | ||
window.alert = jest.fn(); | ||
window.alert.mockClear(); | ||
|
||
test("should confirm there is a button in the Button component ", () => { | ||
const { container } = render(Button); | ||
expect(container).toContainHTML("<button"); | ||
expect(container).toContainHTML("</button>"); | ||
}); | ||
|
||
test('show alert when the button gets clicked', async () => { | ||
const { getByRole, findByRole } = render(Button, {title: 'testButton'}); | ||
const button = getByRole('button'); | ||
|
||
// Using await when firing events is unique to the svelte testing library because | ||
// we have to wait for the next `tick` so that Svelte flushes all pending state changes. | ||
await fireEvent.click(button) | ||
|
||
const alertBox = findByRole('alert'); | ||
|
||
expect(alertBox).toBeInTheDocument; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters