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

Getting "done is not a function" errors when updating to 8.1.0 #356

Closed
qdouble opened this issue Mar 11, 2020 · 13 comments · Fixed by #357
Closed

Getting "done is not a function" errors when updating to 8.1.0 #356

qdouble opened this issue Mar 11, 2020 · 13 comments · Fixed by #357
Labels

Comments

@qdouble
Copy link

qdouble commented Mar 11, 2020

Downgrading back to 8.0.0 removes the error, so there is something in this update that is causing done() not be recognized as a function in any of my spec files.

@wtho
Copy link
Collaborator

wtho commented Mar 11, 2020

Can you provide an example of your test?

@qdouble
Copy link
Author

qdouble commented Mar 11, 2020

The code below works fine on 8.0.0 but errors on 8.1.0. There were others, but I got rid of unnecessary uses of done, but I need to use it here.

  it('should call setTitle with activatedEventData', async done => {
    (fixture.ngZone as NgZone).run(async () => {
      await router.navigate(['']);
    });

    fixture.detectChanges();

    fixture.whenStable().then(() => {
      expect(activatedEventSpy).toHaveBeenCalled();
      expect(setTitleSpy).toHaveBeenCalledWith('Home');
      expect(setTitleServiceSpy).toHaveBeenCalled();
      done();
    });
  });

@wtho
Copy link
Collaborator

wtho commented Mar 11, 2020

@JiaLiPassion can you have a quick look at this?
It might be due to the usage of Promises + done, specifically the change from

return testBody.length === 0
? () => testProxyZone.run(testBody, null)
: done => testProxyZone.run(testBody, null, [done]);

to
return function(...args) {
return testProxyZone.run(testBody, null, args);
};

While I personally would not mix promises and done, but prefer a test as follows, still we should support these kind of tests.

    fixture.detectChanges();

    await fixture.whenStable()
    expect(activatedEventSpy).toHaveBeenCalled();
    expect(setTitleSpy).toHaveBeenCalledWith('Home');
    expect(setTitleServiceSpy).toHaveBeenCalled();

@JiaLiPassion
Copy link
Contributor

@wtho, sure, Got it, I will check it now.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Mar 11, 2020

probably related to changes in zone-patch with this test

import { async } from '@angular/core/testing';
import { Injectable } from '@angular/core';
import { fromEvent, Observable } from 'rxjs';
import { tap } from 'rxjs/operators';

@Injectable({
  providedIn: 'root',
})
class MessagingService {
  private readonly message$: Observable<MessageEvent>;

  constructor() {
    this.message$ = fromEvent<MessageEvent>(window, 'message').pipe(
      tap(data => {
        console.warn(data);
      }),
    );
  }

  getMessage$(): Observable<MessageEvent> {
    return this.message$;
  }
}

describe('Async test', () => {
  let messagingService = new MessagingService();

  beforeEach(() => {
    messagingService.getMessage$().subscribe();
  });

  test(`should print console warn`, async(() => {
    window.postMessage({
      foo: 'foo',
    }, '*');
  }));
});

8.1.0 console.warn doesn't print anything while 8.0.0 there is console.warn

@JiaLiPassion
Copy link
Contributor

Yeah, I know where the problem is, will need to find out how to fix it, because revert to original logic

 return testBody.length === 0 
   ? () => testProxyZone.run(testBody, null) 
   : done => testProxyZone.run(testBody, null, [done]); 

will not support the case like this.

it.each([[1, 2]])('it.each', (arg1, arg2) => {
  expect(arg1).toBe(1);
  expect(arg2).toBe(2);
  done();
});

@JiaLiPassion
Copy link
Contributor

Ok, I know how to fix this one, will create a PR now.

@wtho
Copy link
Collaborator

wtho commented Mar 11, 2020

Awesome!
Would be great if the PR includes a test case for this.

@JiaLiPassion
Copy link
Contributor

@wtho, I created a PR #357, please review. Thanks.

@wtho
Copy link
Collaborator

wtho commented Mar 12, 2020

@qdouble can you please confirm this is resolved in v8.1.1?

@qdouble
Copy link
Author

qdouble commented Mar 12, 2020

@wtho it appears to work just fine now, thanks.

@asaadedd
Copy link

@wtho This issue reemerged can you please reopen this issue?

@ahnpnl
Copy link
Collaborator

ahnpnl commented Oct 19, 2021

with Jest 27, default test runner is jest-circus which doesn't support done anymore. You can only use done with jest-jasmine2 test runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants