getsaf / shallow-render

Angular testing made easy with shallow rendering and easy mocking. https://getsaf.github.io/shallow-render
MIT License
273 stars 25 forks source link

Cannot successfully Mock or Render components in existing project #244

Closed firebait closed 1 year ago

firebait commented 1 year ago

Hi all, this is more of a question than a bug. We have a large project with no testing and I was hoping to encourage more testing by using this library. I'm not sure why but shallow seems to struggle trying to render any component in the application. When I first try to render I get the following error. Note: SharedModule is one of the modules in our application as well as SharedUtilsModule.

    Unhandled Promise rejection: Shallow ran into some trouble mocking SharedModule. Try skipping it with dontMock or neverMock.
    ------------- MOCK ERROR -------------
    Error: Shallow ran into some trouble mocking SharedUtilsModule. Try skipping it with dontMock or neverMock.
    ------------- MOCK ERROR -------------
    TypeError: (0 , core_1.ɵisEnvironmentProviders) is not a function
...

I followed the recommendations and did .neverMock and after several rounds of Whac-a-mole and adding more .neverMock for a lot of other modules I now get this error:

    Unhandled Promise rejection: (0 , core_1.ɵisEnvironmentProviders) is not a function ; Zone: ProxyZone ; Task: null ; Value: TypeError: (0 , core_1.ɵisEnvironmentProviders) is not a function
...

I assume this is not normal as the issue with Angular testing was that you had to setup a bunch of boilerplate in order to get the tests to run but now I seem to need to setup a lot of boilerplate to prevent mocking modules.

Any ideas on where should I start my debugging?

getsaf commented 1 year ago

It looks like this might be a version mismatch issue Which version of Angular and shallow-render are you using?

getsaf commented 1 year ago

For example, EnvironmentProviders were just added in Angular v15 so if the isEnvironmentProviders function is not available it would suggest you're using v15 of shallow-render but < v15 of Angular.

See the compatibility table and make sure you align versions properly.

For example, if you're on Angular 14, install shallow-render@14:

$> npm i -D shallow-render@14
getsaf commented 1 year ago

Closed due to inactivity. I feel there is a high chance the comment above was the solution.