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

chore: setup unit testing tools #2

Merged
merged 1 commit into from
Jan 13, 2022

Conversation

theoklitosBam7
Copy link
Contributor

  • Add and configure Jest for unit testing.
  • Remove Karma and Jasmine related packages.
  • Add @angular-builders/jest that allows us running ng test with Jest instead of Karma & Jasmine.
  • Add @ngneat/spectator to simplify unit tests.

Partially resolves #1

- Add and configure Jest for unit testing.
- Remove Karma and Jasmine related packages.
- Add @angular-builders/jest that allows us running `ng test` with Jest instead of Karma & Jasmine.
- Add @ngneat/spectator to simplify unit tests.

Partially resolves nikosanif#1
@netlify
Copy link

netlify bot commented Jan 11, 2022

✔️ Deploy Preview for angular-authentication ready!

🔨 Explore the source changes: 472bc65

🔍 Inspect the deploy log: https://app.netlify.com/sites/angular-authentication/deploys/61ddea5dce3f9e000a68d420

😎 Browse the preview: https://deploy-preview-2--angular-authentication.netlify.app/

@nikosanif
Copy link
Owner

Hey @theoklitosBam7! Many thanks for your contribution. It's a big step towards writing tests! 👏

However, I have a generic question before the code review. As I am new to writing tests, I noticed a new file jest-global-mocks.ts. Can you explain in short what this file is? Alternatively, you can provide resources (e.g documentation links, articles) where I can find more information about this file.

@theoklitosBam7
Copy link
Contributor Author

Hi @nikosanif !

Because jest-preset-angular uses JSDOM, which is different from normal browsers, we might need some global browser mocks to stimulate the behaviors of real browsers in JSDOM. To add global mocks, we can create jest-global-mocks.ts (name doesn’t matter) and use it in our Jest setup. For example, I had to mock IntersectionObserver because of Taiga UI problems during unit tests run. As Karna uses a real browser we didn’t need that.

You may find more information about jest-preset-angular in official docs and about Jest and JSDOM in this article.

@nikosanif
Copy link
Owner

Thanks, @theoklitosBam7 for your answer! 💯

Copy link
Owner

@nikosanif nikosanif left a comment

Choose a reason for hiding this comment

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

LGTM

@nikosanif nikosanif merged commit 61695a9 into nikosanif:main Jan 13, 2022
@theoklitosBam7 theoklitosBam7 deleted the setup-unit-testing-tools branch January 13, 2022 11:41
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.

Unit tests
2 participants