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

Request for mocks for unit-tests #22

Closed
batbrain9392 opened this issue May 27, 2021 · 5 comments
Closed

Request for mocks for unit-tests #22

batbrain9392 opened this issue May 27, 2021 · 5 comments
Assignees

Comments

@batbrain9392
Copy link
Contributor

batbrain9392 commented May 27, 2021

🚀 Feature request

Could we get mocks like how you've provided it in your universal package? Ref - link

import '@ng-web-apis/universal/mocks';

@waterplea
Copy link
Collaborator

Hey 👋 You mean like for testing with jest? I believe you can already just use mocks from universal, as well as tokens from it. Please let me know if that works for you.

@batbrain9392
Copy link
Contributor Author

For Jasmine/Karma. But will check with the mocks from universal.

But the mocks and tokens can be taken from universal, why maintain 2 repos with the same functionalities?

@waterplea
Copy link
Collaborator

This library is just a library of token so you make your apps without any direct access to global entities, because they might not be available in some environments. Universal package is the package of substitutes for those tokens for server side which also might work in other environments where they are missing. For example jest testing is a lot like universal as it is also emulated DOM. Is Jasmine/Karma you don't need mocks, because tokens are available as is. But you can easily mock them with spies etc. in unit tests.

@batbrain9392
Copy link
Contributor Author

@waterplea Do you have an example of how these tokens can be mocked in Jasmine/Karma unit tests?

@waterplea
Copy link
Collaborator

waterplea commented Jun 2, 2021

When you configure TestBed you can add to providers something like this:

{
  provide: WINDOW,
  useValue: { 
    matchMedia(query: string): boolean {
      return query === '(min-width: 400px)';
    }
  }
}

for example, if your code depends on screen size by running window.matchMedia and you want to test particular configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants