Closed michaelw85 closed 5 years ago
But isn't the approach with mocking a dependency via the mocks folder that they are automatically loaded. In that case it would make sense since the mock file is empty and thus leading to an error since nothing is exported
@zewa666 Thanks for the info, I was under the impression mock are not automatically loaded since automock is false by default. Reading the documentation you are linking states differently for node modules. This gives me some new insight and I will have another look.
P.S I also had a complete mock with content and it also failed so I figured it was not related.
@zewa666 This documentation pointed me into the right direction!
To get StageComponent (quickly) working again I added:
jest.unmock('aurelia-router');
The jest docs really confused me I was not expecting automatic mocks which made me think something went wrong in the StageComponent module.
Yeah Jest docs are massive but somewhat hard to digest. Anyway Im glad you found the issue
Thanks allot for your help this resolved multiple issues (seemingly unrelated) I was struggling with. I finished a PR to the jest docs today adding a note to the automock setting.
I'm submitting a bug report
Please tell us about your environment:
Operating System: Windows [10]
Node Version: v10.15.1
NPM Version: 6.4.1
Webpack "webpack": "^4.27.0",
Browser: N/A
Language: TypeScript 3.3.1
Current behavior: Error occurs when using
StageComponent
in combination with a aurelia-router mock.Steps to reproduce 1) Create a new project using latest cli, choose custom and select a TS+Jest setup 2) Create folder
__mocks__
in the root of the project 3) Add empty fileaurelia-router.ts
4) Replace app.spec.ts with the following test:5) run tests
au jest
To successfully run the "test" rename the aurelia-router.ts to anything else and rerun.
Expected/desired behavior: I should be able to use StageComponent and have a aurelia-router mock in place. This mock file should not affect this test unless I specifically want to use the mock.