-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests #19
Unit tests #19
Changes from 4 commits
0138b73
7b1a783
b562c26
f5d561b
b53f94e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", {"targets": {"node": "current"}}], | ||
'@babel/preset-typescript', | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this works for me either |
||
presets: [ | ||
['@babel/preset-env', {targets: {node: 'current'}}], | ||
'@babel/preset-typescript', | ||
], | ||
}; |
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.
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 { getByTestId, findByRole } = render(Button, {title: 'testButton'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I would recommend to use |
||
const button = getByTestId('testButton'); | ||
|
||
// 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; | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
export let title = ''; | ||
</script> | ||
|
||
<button title="{title}" disabled="{disabled}" on:click="{buttonAction}"> | ||
<button data-testid="testButton" title="{title}" disabled="{disabled}" on:click="{buttonAction}"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we use |
||
<slot /> | ||
</button> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need both the file
.babelrc
andbabel.config.js
? Can we delete.babelrc
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think so. I will delete it.