Skip to content
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

Merged
merged 5 commits into from
Mar 20, 2022
Merged

Unit tests #19

merged 5 commits into from
Mar 20, 2022

Conversation

kheitkamp
Copy link

Hi Malte,

you can find an example unit test in this pull request.

regards

Kristian

@bonartm
Copy link
Owner

bonartm commented Jan 16, 2022

Thanks a lot! I will look into it in the upcoming weeks!

@bonartm bonartm linked an issue Feb 6, 2022 that may be closed by this pull request
@bonartm bonartm changed the base branch from main to 13_unit_tests February 6, 2022 10:14
Copy link
Owner

@bonartm bonartm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the base branch to 13_unit_tests and added some comments. Thanks!

});

test('show alert when the button gets clicked', async () => {
const { getByTestId, findByRole } = render(Button, {title: 'testButton'});
Copy link
Owner

@bonartm bonartm Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the spirit of the guiding principles, it is recommended to use this only after the other queries don't work for your use case. Using data-testid attributes do not resemble how your software is used and should be avoided if possible. (https://testing-library.com/docs/queries/bytestid)

I would recommend to use getByRole as the button element has the default role button

@@ -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}">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we use getByRole we also don't need to introduce data-testid

.babelrc Outdated
@@ -0,0 +1,6 @@
{
Copy link
Owner

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 and babel.config.js? Can we delete .babelrc?

Copy link
Author

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.

babel.config.js Outdated
@@ -0,0 +1,6 @@
module.exports = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to rename babel.config.js to babel.config.cjs to make it work. Otherwise I get error error while loading config - You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works for me either

@bonartm bonartm mentioned this pull request Feb 6, 2022
Copy link
Author

@kheitkamp kheitkamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed my PR – the next test goes to you ;-)

@kheitkamp
Copy link
Author

Hope you are fine?

@kheitkamp kheitkamp requested a review from bonartm March 17, 2022 23:21
@bonartm bonartm merged commit eb25a4f into bonartm:13_unit_tests Mar 20, 2022
@bonartm
Copy link
Owner

bonartm commented Mar 20, 2022

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add unit tests
2 participants