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

Add unit tests #13

Open
bonartm opened this issue Jul 1, 2021 · 5 comments · Fixed by #19
Open

Add unit tests #13

bonartm opened this issue Jul 1, 2021 · 5 comments · Fixed by #19
Labels
help wanted Extra attention is needed

Comments

@bonartm
Copy link
Owner

bonartm commented Jul 1, 2021

I'm not familiar with unit testing for typescript/ svelte projects but this projects needs some proper testing. I'm thankful for any examples and first implementations!

@bonartm bonartm added the help wanted Extra attention is needed label Jul 1, 2021
@kheitkamp
Copy link

kheitkamp commented Jan 13, 2022

Hi Malte,
I've created a unit test for the Button component. If you would give me the proper rights, I could push it into a new branch called issue13_add_unit_tests

@kheitkamp
Copy link

kheitkamp commented Jan 14, 2022

I used the following tutorial:
https://testing-library.com/docs/svelte-testing-library/intro

I had to add the following packages to the package.json to make the tutorial work:
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/svelte": "^3.0.3",

I also needed to add the following comment at the top of the test file:
/**

  • @jest-environment jsdom
    */

Jest-dom is described here:
https://github.com/testing-library/jest-dom#usage

You'll find an overview of testing queries here:
https://testing-library.com/docs/queries/byrole/

@kheitkamp
Copy link

I've created a new fork and added the changes there in the main branch.

@kheitkamp
Copy link

kheitkamp commented Jan 14, 2022

For better unit testing I would recommend to break the quiz.ts file into a module which imports all the classes currently included in the quiz.ts file. Like with java, where every class has it's own file.
It will make your code much more readable and force you to give your classes a clear structure and interdependency while preventing your code to become spaghetti ;-)
Also there are a lot of loose functions within the quiz.ts file which mostly seem to be methods that belong to the BaseQuestion class and therefore should be part of it. Quiz just seems to need a bit clean up ;-)
Also I would put each type declaration into its own model file which then should be imported by each class that needs it.
Drawing a UML class diagram could be very helpful for structuring the classes: https://www.tutorialspoint.com/uml/uml_class_diagram.htm
Typescript has a very detailed documentation of how to summarise different classes into one module: https://www.typescriptlang.org/docs/handbook/modules.html

@bonartm
Copy link
Owner Author

bonartm commented Jan 16, 2022

Thanks a lot, Kristian, for your work and suggestions. I will look into it in the upcoming weeks.

@bonartm bonartm linked a pull request Feb 6, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants