-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
MockProvider does not reset the token value of MockInstance #1256
Comments
Hi @AE1NS, if you don't install scopes for If you use jasmine, then everything is every easy, you need to add a global reportor: https://ng-mocks.sudo.eu/extra/install#default-customizations // auto restore for jasmine and jest <27
// declare const jasmine: any;
jasmine.getEnv().addReporter({
specDone: MockInstance.restore,
specStarted: MockInstance.remember,
suiteDone: MockInstance.restore,
suiteStarted: MockInstance.remember,
}); The same solution works for jest < 27, if you are using jest 27+, then please support this issue: jestjs/jest#11483. describe('suite', () => {
beforeAll(MockInstance.remember);
afterAll(MockInstance.restore);
// ...
}); Please let me know if it helps, or you need further assistance. |
Thank you for your response. |
I updated to latest now and tested it with both approaches, but still have the same issue. When I use MockPovider/MockInstance with a DI service, everything works fine, but when I use it with an injection token, it seems not to get resettet. I can only reset it, when I do another MockInstance with the default value in the beforeEach right now. |
Hi @AE1NS, I see, might you provide a test with the issue? Also, could you try to use describe('suite', () => {
afterEach(MockInstance);
// ...
}); |
My test does not finish when I add this. I get this output in karma: I think the problem can be reproduced with something like the following suite:
Component:
When running the tests synchronously, I expect the 'test' property in the token to be 1, but its in both cases 2 because its not resettet, so the if statement in the implementation is never entered. |
Ah sorry. My mistake. It should be afterEach(MockReset); |
Well, with the MockReset it works now. But does it mean that there is an issue with MockInstance, because it must be reset automatically? |
Hi there, a happy new year! :) I'm back to business and was able to reproduce your issue. It should be fixed soon. |
the issue here is that for now, you could use |
feat(MockInstance): resets root overrides likewise properties #1256
v13.1.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems. |
First of all, thank you for this awesome plugin. We integrated it in our solutions and its working really great! Unfortunately one thing is not working as I expect it, but maybe its not a bug, but i missunderstood it.
I created an angular injection token and mock it with MockProvider, i.e.
Inside an 'it' I override it with another value:
MockInstance(myToken, () => ({ test: 2 }));
When the next 'it' runs, I expect the value to be resettet to '{ test: 1 }' again by the MockProvider call in beforeEach, but I still get the value '{ test: 2 }' here.
Am I using this the wrong way or is this a bug of the framework?
The text was updated successfully, but these errors were encountered: