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

[Feature]: Allow configuring errorOnUnknownElements and errorOnUnknownProperties for setup test env #1656

Closed
cedricduffournet opened this issue Jun 24, 2022 · 10 comments · Fixed by #1657

Comments

@cedricduffournet
Copy link
Contributor

🚀 Feature Proposal

Allow configuring errorOnUnknownElements and errorOnUnknownProperties is test environment option

see: https://angular.io/api/core/testing/TestEnvironmentOptions

Motivation

This new properties has been introduce in angular V14. This is usefull to throw errors on unknown elements or properties found in a template

Example

like destroyAfterEach option, we could add errorOnUnknownElements and errorOnUnknownProperties

globalThis.ngJest = {
  errorOnUnknownElements: true,
  errorOnUnknownProperties: true,
};

As TestEnvironmentOptions may introduce more properties in the future, we could add testEnvironmentOptions property in config:

globalThis.ngJest = {
  testEnvironmentOptions: {
    errorOnUnknownElements: true,
    errorOnUnknownProperties: true,
    teardown: { destroyAfterEach: false },
  },
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 24, 2022

PR is welcome, should be similar to #1475

I like this option

As TestEnvironmentOptions may introduce more properties in the future, we could add testEnvironmentOptions property in config:

globalThis.ngJest = {
  testEnvironmentOptions: {
    errorOnUnknownElements: true,
    errorOnUnknownProperties: true,
    teardown: { destroyAfterEach: false },
  },

@cedricduffournet
Copy link
Contributor Author

Yes, I'll do the PR

@Yohandah
Copy link

Yohandah commented Aug 23, 2022

@cedricduffournet @ahnpnl Can you guide me on how to use this ? I can't find docs about this
I've added the following in my setup-jest.js

setup-jest.js

globalThis.ngJest = {
  testEnvironmentOptions: {
    errorOnUnknownElements: true,
    errorOnUnknownProperties: true,
    teardown: { destroyAfterEach: false },
  }
}

and in jest.config.js

module.exports = {
  ...
  setupFilesAfterEnv: ['<rootDir>/setup-jest.js'],
  ...

But it doesn't work when I execute ng test

@cedricduffournet
Copy link
Contributor Author

@Yohandah this should work.
Could you please provide a reproduce scenario with https://github.com/thymikee/jest-preset-angular/tree/main/examples

@Yohandah
Copy link

@cedricduffournet I have a reproduction here : but using @angular-builders/jest ... https://github.com/Yohandah/angular-builder-jest-errorOnUnknownElementsr

It could come from this package then ...

@cedricduffournet
Copy link
Contributor Author

cedricduffournet commented Aug 23, 2022

@Yohandah I don't know about @angular-builders/jest, but I can't see any reference to setupFilesAfterEnv in your example, neither thesetup-jest.js file where you should add testEnvironmentOptions

@Yohandah
Copy link

Yohandah commented Aug 23, 2022

@cedricduffournet yeah that's because I've added the options directly inside jest.config.js, I pushed the change. I will try to see with @angular-builders/jest maintainer. He's saying I should pass the setup file as a CLI arg but I can't see why since the setup file is already referenced inside jest.config.js just-jeb/angular-builders#1245 (comment)

Thanks anyway for trying to help !

@Yohandah
Copy link

@cedricduffournet I tried to enable these options using jest-preset-angular only but it's not working :/ I can't find docs on how to use these.

checkout the repo (jest-preset-angular-only branch): https://github.com/Yohandah/angular-builder-jest-errorOnUnknownElementsr/tree/jest-preset-angular-only

@ahnpnl
Copy link
Collaborator

ahnpnl commented Oct 18, 2022

Doc is here https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment

@Yohandah
Copy link

ohhh I had to import AFTER declaring .ngJest OK !! nice thank you

left: wrong -- right: right
image

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 a pull request may close this issue.

3 participants