InversifyJS
InversifyJS copied to clipboard
Decorators cannot be used to decorate parameters
Expected Behavior
I expect to implement unit test and unit tests to pass without errors.
Current Behavior
I got this error "Decorators cannot be used to decorate parameters" when implementing unit testing in my app. I expect that unit tests to pass with pointing to the line where I implement the "@inject" All errors says "Decorators cannot be used to decorate parameters" and pointing to the "@inject" in the constructor of the class.
Possible Solution
by removing the "@inject" from constructor, unit tests pass.
Steps to Reproduce (for bugs)
Got the error with this syntex:
@injectable()
export default class MutationHandler implements IMutationHandler {
private _observers = new Map<string, MutationObserver>();
private _sharePointPageHandler: ISharePointPageHandler;
public constructor(
@inject(TYPES.ISharePointPageHandler) sharePointPageHandler: ISharePointPageHandler
) {
this._sharePointPageHandler = sharePointPageHandler;
this.handleActionsSubcellMutation = this.handleActionsSubcellMutation.bind(this);
}
}
Test passes with this syntex
export default class MutationHandler implements IMutationHandler {
private _observers = new Map<string, MutationObserver>();
private _sharePointPageHandler: ISharePointPageHandler;
public constructor(
sharePointPageHandler: ISharePointPageHandler
) {
this._sharePointPageHandler = sharePointPageHandler;
this.handleActionsSubcellMutation = this.handleActionsSubcellMutation.bind(this);
}
Context
It prevent us from building unit tests for the project.
Your Environment
- Version used: inversify version: 6.0.2
- Environment name and version: nodeVersion: 18.19.1
- Operating System and version (windows desktop) 11
- Jest version: 29.7.0
Another Environment for another project where unit test passes but with different versions:
- Version used: inversify version: 5.1.1
- Environment name and version: nodeVersion: 14.17.0
- Operating System and version (windows desktop) 11
- Jest version: 25.5.4