exception in Jest tests: `TypeError: Cannot read property 'module' of undefined` when using `forwardRef` in module `imports`
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When creating a testing module using Test#createTestingModule
method and importing a Module that has a circular dependency with another module(s) implemented using forwardRef
,
test fails with the following exception:
TypeError: Cannot read property 'module' of undefined
See the screen and the full exception text with a call stack in this gist
However the code itself compiles and works correctly. (see the screen)
Expected behavior
Tests should work
Minimal reproduction of the problem with instructions
Here is the repo of the example project.
Just run yarn test:single
to reproduce.
What is the motivation / use case for changing the behavior?
Can’t test the code containing the circular dependency.
Environment
Nest version: 4.6.6
For Tooling issues:
- Node version: 9.4.0
- Platform: Mac
Others:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Jest: Cannot read property of undefined when importing from ...
When imported to a new, empty React typescript app works perfectly. Problems start in Jest tests suites. The commonJS package version cause Jest...
Read more >Common errors - FAQ - A progressive Node.js framework
A common case would be a module file declaring a token and importing a provider, and the provider import the token constant from...
Read more >cannot read properties of null (reading 'usecontext') jest
Using Jest to test a react application using Axios. Getting TypeError: Cannot read properties of undefined (reading 'then').
Read more >Continuous integration for React applications using Jest and ...
Because you are testing the App component independently of redux , anything that is provided by redux (for example, the component's props ), ......
Read more >jest-environment-jsdom | Yarn - Package Manager
Jest will set process.env.NODE_ENV to 'test' if it's not set to something else. You can use that in your configuration to conditionally setup...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
v5.0.0-beta.4
is using rxjsv.6.0.0
now@alexandr2110pro keep in mind that Nest is not compatible with rxjs 6 yet (release took place yesterday)
Thanks for reporting, I’ll verify.