When using InversifyJS with Jest, creating a container with mock dependencies results in the error:
TypeError: Cannot read property 'constructor' of null.
A container should be able to handle mock depenencies and resolve them without errors.
A container cannot handle mock depenencies and resolve them without errors.
Seems related to this issue: https://github.com/inversify/InversifyJS/issues/984
I've created a minimal example that reproduces the issue:
https://github.com/peasey/minimal-typescript-inversify-jest
I cant use InversifyJS and Jest together, so unless this can be fixed I'll need to find another DI container or test framework, neither of which are ideal.
TypeError: Cannot read property 'constructor' of null
at getClassPropsAsTargets (node_modules/inversify/lib/planning/reflection_utils.js:82:75)
at Array.forEach (<anonymous>)
I've been able to get this working by binding with toDynamicValue instead. I've updated the minimal example on a new branch: https://github.com/peasey/minimal-typescript-inversify-jest/tree/using-dynamic-value
Leaving the issue open for now.
I am having the same problem in this environment:
^ Frankly I cannot use toDynamicValue... :-/ Do you have an idea when this may be fixed?
Also appears in jest 24.1.0
typescript 3.3.3
node 10.15.0
I cannot use toDynamicValue
Same problem.
Helped this quick hack in test file Object.getPrototypeOf(EventEmitter.prototype).constructor = Object;
Same problem.
- Mint 19
- Node 8.9.4
- [email protected]
- [email protected]
- [email protected]
Helped this quick hack in test file
Object.getPrototypeOf(EventEmitter.prototype).constructor = Object;
You are a genius.
Most helpful comment
Same problem.
Helped this quick hack in test file
Object.getPrototypeOf(EventEmitter.prototype).constructor = Object;