Skip to content
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

WIP: add test sample with zone-testing #3701

Closed

Conversation

JiaLiPassion
Copy link

@JiaLiPassion JiaLiPassion commented May 16, 2018

Description:

This PR is based on @benlesh 's document here. https://docs.google.com/document/d/1sIUgRVRgcsLcC8B5sbCAPDvA_lrYcACzh9Q80vxFTbw/

This is a experimental PR to try to let rxjs test with zone-testing, this PR will use the experimental version of zone.js (angular/zone.js#1084) . So with adding more test cases, we will find more use cases and find out current zone-testing APIs satisfy the rxjs requirements or not.

Current status:

  1. add zone-testing fakeAsync test cases for combineLatest, use setInterval to create Observable, those async test cases was originally handled by TestScheduler.
function createIntervalObservable(interval: number) {
  return new Observable<number>(subscriber => {
    let i = 0;
    const id = setInterval(() => {
      subscriber.next(i++);
    }, interval);
    return () => clearInterval(id);
  });
}

it('should combine the latest values of multiple observables with fakeAsync', fakeAsyncTest(() => {
    const results: any[] = [];
    const s1 = createIntervalObservable(1000);
    const s2 = createIntervalObservable(1500);
    const s3 = createIntervalObservable(1800);
    combineLatest(s1, s2, s3).subscribe({
      next(value) { results.push(value); },
      complete() { results.push('done'); },
    });
    expect(results).toEqual([]);
    tick(1000);
    expect(results).toEqual([]);
    tick(500);
    expect(results).toEqual([]);
    tick(300);
    expect(results).toEqual([[0, 0, 0]]);
    tick(300);
    expect(results).toEqual([[0, 0, 0], [1, 0, 0]]);
    clearAllMacrotasks();
  }));
  1. TODO: try to add marble test sample with zone-testing later.

Related issue (if exists):

@benlesh
Copy link
Member

benlesh commented May 21, 2018

This is awesome! Thanks, @JiaLiPassion! I'm going to take this example and try to work out what the next generation of marble testing looks like. We're likely to have to change a few things to accommodate the fact that async/await cannot be hooked ala zones.

@benlesh
Copy link
Member

benlesh commented May 21, 2018

(Marked as "blocked", because I'm not sure I'll merge this straight in, or just use it as an example.)

@JiaLiPassion
Copy link
Author

JiaLiPassion commented May 21, 2018

@benlesh, thanks, I just use this PR as a discussion place, so we can discuss whether zone-testing can satisfy rxjs requirement or not.

We're likely to have to change a few things to accommodate the fact that async/await cannot be hooked ala zones.

in nodejs with asynchooks, we can hooks with zone, here I created a POC PR, angular/zone.js#795
But in browser, it will not work...

@benlesh
Copy link
Member

benlesh commented Jul 26, 2018

@JiaLiPassion ... I'm closing this, but only to unclutter the pulls list. This is definitely going to be used as a reference for future work on the test scheduler, which there is still ongoing design work for.

@benlesh benlesh closed this Jul 26, 2018
@JiaLiPassion
Copy link
Author

@benlesh, sure, if there is anything need to do in zone-testing, please let me know.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants