`processNewMacroTasksSynchronously: false` does not work well with rxjs' timer and interval functions
See original GitHub issue🐞 bug report
Affected Package
The issue is caused by package @angular/angular/core/testing
Is this a regression?
No
Description
Using tick(0, { processNewMacroTasksSynchronously: false })
with rxjs’ timer
and interval
does not worked as expected.
🔬 Minimal Reproduction
Example with timer, callback never been called
it('with timer', fakeAsync(() => {
const callback = jasmine.createSpy('callback');
timer(0, 0).pipe(skip(1), take(1)).subscribe(callback);
expect(callback).not.toHaveBeenCalled();
tick(undefined, { processNewMacroTasksSynchronously: false });
expect(callback).not.toHaveBeenCalled();
tick(undefined, { processNewMacroTasksSynchronously: false });
expect(callback).toHaveBeenCalledTimes(1);
}));
Same with interval, code in test file. Repo with this test
git clone git@github.com:artaommahe/tick-with-timer-and-interval.git
yarn install
yarn test
Even using tick()
does not work here.
🔥 Exception or Error
Chrome 83.0.4103.106 (Windows 10) tickWithTimerAndInterval with timer FAILED
Error: Expected spy callback to have been called once. It was called 0 times.
at <Jasmine>
at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/tickWithTimerAndInterval.spec.ts:24:22)
🌍 Your Environment
Angular Version:
Angular CLI: 10.0.0-rc.5
Node: 12.18.1
OS: win32 x64
Angular: 10.0.0-rc.6
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1000.0-rc.5
@angular-devkit/build-angular 0.1000.0-rc.5
@angular-devkit/build-optimizer 0.1000.0-rc.5
@angular-devkit/build-webpack 0.1000.0-rc.5
@angular-devkit/core 10.0.0-rc.5
@angular-devkit/schematics 10.0.0-rc.5
@angular/cli 10.0.0-rc.5
@ngtools/webpack 10.0.0-rc.5
@schematics/angular 10.0.0-rc.5
@schematics/update 0.1000.0-rc.5
rxjs 6.5.5
typescript 3.9.5
webpack 4.43.0
Anything else relevant?
Same case works well with jest fake timers
const callback = jest.fn();
jest.useFakeTimers();
timer(0, 0).pipe(skip(1), take(1)).subscribe(callback);
expect(callback).not.toHaveBeenCalled();
jest.runOnlyPendingTimers();
expect(callback).not.toHaveBeenCalled();
jest.runOnlyPendingTimers();
expect(callback).toBeCalledTimes(1);
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
tick - Angular
In the following case, processNewMacroTasksSynchronously is explicitly set to false, so the nested timeout function is not invoked. content_copy it ('test with ...
Read more >RXJS Timer continues to run after takeWhile operator returns ...
The idea is that the timer (2) should initially fetch the result after 100ms and then run every 2000 ms until the generation_status...
Read more >timer - RxJS
Creates an observable that will wait for a specified time period, ... You may want to start an interval immediately. timer works well...
Read more >RxJS: Testing with Fake Time - ncjamieson
To solve this problem, I've added a fakeSchedulers function to rxjs-marbles , so that tests can use fake time for situations in which...
Read more >Open Source Used In slido-test 22.06 - Cisco
Cisco has more than 200 offices worldwide. Addresses, phone numbers, and fax numbers are listed on the Cisco website at www.cisco.com/go/offices.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yes, just like you said,
jest.runOnlyPendingTimers()
is different withtick(x, {processNewMacroTAsksSynchronously: false})
, since tick has aadvancedTime
parameter.And
interval(0)
behave differently withtimer(0,0)
sincesetInterval
allow to pass anzero
interval. So when youtick
, theinterval
will be triggered twice and causeskip
andtake
to be triggered too.And also, here use
processNewMacroTasksSynchronously: false
will not work either sincefakeAsync
will always handleinterval
calls in the current tick. So if you have some use case need this case work asspy not called
, please tell me and we can discuss about it.Thanks.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.