-
Notifications
You must be signed in to change notification settings - Fork 26.2k
regression: jasmine.clock() inside fakeAsync() doesn't work anymore since 0.8.21 #31708
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
Comments
@jnizet , in it('should fake the clock in fakeAsync', () => {
const fakeTime = 12345678;
jasmine.clock().mockDate(new Date(fakeTime));
expect(new Date().getTime()).toBe(fakeTime);
}); |
@JiaLiPassion this is a dumb-down version of my real test. In the actual test, I also use
And call Since 0.8.21, this doesn't work anymore. Based on your comments, I tried:
Please tell me if you need more information, and when I have some time, I'll try to provide a reproduction of the actual problem. |
@jnizet , please provide a reproduce repo, in new version, you don't need to |
@JiaLiPassion Here's a repo reproducing the issue: https://github.com/jnizet/zonejsbug The bug is illustrated in https://github.com/jnizet/zonejsbug/blob/master/src/app/clock.spec.ts. Switching back to 0.8.20 in package.json, then executing The app.component.spec.ts file illustrates another regression, for which I'll post another issue. |
OK, thanks. BTW, I had the impression that 0.8.21 was supposed to support the RxJS but this simple test doesn't pass:
and I haven't been able to understand how to use your example at #10127 (comment). Native support, without having to import a ts file out of the project, would be nice. |
@jnizet , you need to import an additional file |
@jnizet, please update to And I also create a which describes that you can also test like this, because |
@JiaLiPassion thanks for looking into this. The reproduction test I gave you now doesn't fail anymore, but unfortunately, I must have oversimplified the actual test a little, because my actual test still doesn't pass:
To help figuring out the actual issue, it would be great if you could look into the actual test case (which is a bit more complex than the repro I gave before, but not that much). Here's the github repo: https://github.com/Ninja-Squad/globe42 To reproduce the issue, you'll have to:
The version of zone.js in this branch is 0.8.25, and the problematic test uses This test passed fine before, when using version 0.8.20 (which you can check by checkouting the master branch, or just changing the version in package.json, if you want to). |
@jnizet, sure, I have created a commit here, JiaLiPassion/globe42@31b1151 with new version of And after |
Thanks a lot for your help @JiaLiPassion. By "next version of Angular", do you mean the next minor/patch 5.x version, or the next major 6.0 version? |
@jnizet, I am not sure which version is, I believe it will be if it will cost some time to upgrade to |
Thanks. I definitely plan to migrate ASAP, and I've already prepared the migration in a different branch. Just wanted to know. Thanks again. |
@jnizet, glad to help! |
@JiaLiPassion you not only helped me and the rest of the Angular community, but you also indirectly helped a small local non-profit organization that cares about old, poor immigrants. 👏 |
@jnizet , thank you! very glad and proud to know that! |
|
@ohjames, please provide a reproduce repo . |
@JiaLiPassion The reproduction is simple, merely call |
@ohjames , you mean beforeEach(() => {
jasmine.clock().install();
jasmine.clock().mockDate(2017, 1,1);
});
it (() => {
expect(Date.now.getFullYear()).toBe(2017); // will fail
}); this case will fail, beforeEach(() => {
jasmine.clock().install();
});
it (() => {
jasmine.clock().mockDate(2017, 1,1);
expect(Date.now.getFullYear()).toBe(2017); // will success
}); this will success. is that right ? Please paste some sample test codes here, it will help a lot. |
I ported all our tests over to |
@ohjames , thanks for the update, I will check |
@JiaLiPassion then just add one test case at the first after the
Then can reproduce as following(with changes just for the
then move the
While, if with But when I want to test the added spec only with 'fit', this added spec can always pass, but if with one case with |
@Teamop see my previous comment, you can't use those methods anymore. Write your own that uses |
@ohjames yes, but for me, this just happens with |
Yeah it can't be used in any hook other than the test itself since angular 6. |
@ohjames, @Teamop, I will check this issue again, thank you for posting the issue. |
Closing as obsolete - there's been no activity on this issue since 2018, and it's unlikely we'll make any changes to the Zone Jasmine patch at this point. If you're still encountering this problem, feel free to open a new issue with a reproduction. |
This happens in an Angular application.
Simple steps to reproduce
ng new
Run
ng test
to execute the test. It fails when zone.js version 0.8.21 is being used (default dependency to zone.js in package.json is^0.8.19
, which now resolves to 0.8.21. If you change it to0.8.20
and executenpm install
oryarn install
to make sure the previous version of zone.js is used, the test passes.The text was updated successfully, but these errors were encountered: