question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`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

test file

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:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JiaLiPassioncommented, Jun 23, 2020

yes, just like you said, jest.runOnlyPendingTimers() is different with tick(x, {processNewMacroTAsksSynchronously: false}), since tick has a advancedTime parameter.

And interval(0) behave differently with timer(0,0) since setInterval allow to pass an zero interval. So when you tick, the interval will be triggered twice and cause skip and take to be triggered too.

And also, here use processNewMacroTasksSynchronously: false will not work either since fakeAsync will always handle interval calls in the current tick. So if you have some use case need this case work as spy not called, please tell me and we can discuss about it.

Thanks.

0reactions
angular-automatic-lock-bot[bot]commented, Jul 24, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found