-
Notifications
You must be signed in to change notification settings - Fork 405
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
fix(store): silence console hints in tests #706
fix(store): silence console hints in tests #706
Conversation
Waiting for feedback from the angular team on my approach to checking if Angular is in Test mode. |
Also still trying to figure out how to write tests for this! |
cd65d12
to
18a65ec
Compare
@@ -34,6 +35,8 @@ export class InternalStateOperations { | |||
} | |||
|
|||
private verifyDevMode() { | |||
if (isAngularInTestMode()) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a difficult operation if the number of iterations in this method is more than it seemed. I think this is a difficult operation if the number of iterations in this method is more than it seemed.
{
developmentMode: false,
silentWarning: true // disabled recommend
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is memoized, so it will run only once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not want to require developers to add options to all their test setups. This would not be a good experience at all. My aim is to reduce the boilerplate required in the tests.
packages/store/src/utils/angular.ts
Outdated
const compilerOptions = platformRef.injector.get(COMPILER_OPTIONS, null); | ||
if (!compilerOptions) return false; | ||
const isInTestMode = compilerOptions.some((item: CompilerOptions) => { | ||
const providers = (item && item.providers) || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how hard is the operation? How many iterations will be in production mode?
the number of providers may be a huge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These compiler options will iterate over no more than 10 providers and this list does not get affected by the providers in your app. These are stock standard.
@markwhitfeld @splincode |
@markwhitfeld ping |
@eranshmil Nice find but unfortunately it assumes karma and jasmine: private _isTestEnv() {
const window = this._window as any;
return window && (window.__karma__ || window.jasmine);
} People could be using jest, tape, ava, mocha, etc. |
@markwhitfeld I believe you need to use the solution, which is found @eranshmil |
So, my tweet received a few interesting answers: Some of the options are:
Which approach do you prefer? |
For me, the last one seems better than the others. |
good platformRef.injector.get(TestBed, null) !== null; |
Great, I'll make the change and run it through the tests I wrote for it. Holding thumbs! |
Used the simpler mechanism of checking for the test mode. |
* fix: prevent guidance messages in console during tests run * chore: user simpler mechanism for determining test mode * fix: injected TestBed must be optional * chore: silence the recommendation in the integration app # Conflicts: # integration/app/app.module.ts # packages/store/src/utils/memoize.ts
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently when tests are run with NGXS the console is filled with noise regarding the hint to turn on the
developmentMode
during Angular dev mode.Issue Number: #701
What is the new behavior?
When NGXS is being run during tests the console hints will be supressed.
Does this PR introduce a breaking change?