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

Adding jest support #99

Closed
kylecannon opened this issue Apr 4, 2019 · 9 comments · Fixed by #100
Closed

Adding jest support #99

kylecannon opened this issue Apr 4, 2019 · 9 comments · Fixed by #100

Comments

@kylecannon
Copy link
Contributor

I did see that in #76 that you were thinking about adding Jest support. Is this something that is on the roadmap?

@duck-nukem
Copy link
Collaborator

👋🏼 I’m using jest with shallow-render on multiple projects (both personal and work related) and it works perfectly fine. Is there anything specific you need help with?

@kylecannon
Copy link
Contributor Author

It seems to be related to when I use the .mock methods. I have it working in some instances where I don't have to mock anything. However, if you look at the code base, you'll see that jasmine is used in some parts of the codebase https://github.com/getsaf/shallow-render/search?utf8=%E2%9C%93&q=jasmine&type=

This is also an issue: https://github.com/getsaf/shallow-render/blob/a30d987633530c442ef6480e7985599094826747/lib/models/mock-of-provider.ts

@getsaf
Copy link
Owner

getsaf commented Apr 4, 2019

Yeah, so I hadn't used Jest for Angular tests before but I have been using it more in other projects. I just learned that Jest ships with a "monkeypatched" version of Jasmine which means Jasmine spys work with Jest out-of-the-box.

I think this means that Shallow already supports Jest because it uses Jest-compatible Jasmine spys (as @kylecannon pointed out).

@kreatemore, It seems that there's no work to do on this one unless you have experienced any quirks on your end.

@kylecannon
Copy link
Contributor Author

I tried running Jest today on a project that was using .mock and it was failing using jest.

 TypeError: jasmine.isSpy is not a function

      32 | 
      33 |     it('renders', async () => {
    > 34 |         const { element } = await shallow.render('<app-dashboards-page></app-dashboards-pag
e>');
         |                                           ^
      35 |         expect(element).toBeTruthy();
      36 |     });
      37 | });

      at ../../node_modules/shallow-render/lib/models/mock-of-provider.ts:7:73
          at Array.forEach (<anonymous>)
      at MockProvider.MockOfProvider (../../node_modules/shallow-render/lib/models/mock-of-provider.ts
:6:24)

Some jasmine methods work out of the box but not all.

@duck-nukem
Copy link
Collaborator

duck-nukem commented Apr 4, 2019

Seems right, this reproduces the above: https://github.com/kreatemore/shallow-render-hammerjs/blob/master/src/app/app.component.spec.ts#L9

I've found similar code in one of our private projects (with more dependencies, like jest-preset-angular) that has passing tests, maybe it's a case of another package fixing this.

Edit:

Probably these are incompatible with jest:

  • (jasmine as any).isSpy(...)
  • jasmine.createSpy()

@duck-nukem
Copy link
Collaborator

duck-nukem commented Apr 4, 2019

@getsaf I'm going to have quite a busy weekend, but I'd still like to give this a go - if you don't mind of course

@getsaf
Copy link
Owner

getsaf commented Apr 4, 2019 via email

@kylecannon
Copy link
Contributor Author

ts-mockery handles this nicely. Taking a look at it might not be a bad idea.

@getsaf
Copy link
Owner

getsaf commented Apr 4, 2019 via email

duck-nukem added a commit to duck-nukem/shallow-render that referenced this issue Apr 5, 2019
duck-nukem added a commit to duck-nukem/shallow-render that referenced this issue Apr 5, 2019
duck-nukem added a commit to duck-nukem/shallow-render that referenced this issue Apr 5, 2019
duck-nukem added a commit to duck-nukem/shallow-render that referenced this issue Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants