I am currently working on testing a hybrid Angular and Angular.js app using Karma / Jasmine. The previous code utilized custom matchers which worked flawlessly, and these same matchers are being used in the new TypeScript code. Strangely, although the TypeScript compiler for Webpack compiles and runs the spec's without any issues, the WebStorm inspector is flagging them as errors with the message:
https://i.sstatic.net/mEoEH.png
The specific error reads:
TS2339: Property 'toBeNgVisible' does not exist on type 'ArrayLikeMatchers '.
The environment setup includes:
- "@types/angular-mocks": "^1.5.11",
- "@types/jasmine": "^3.3.1",
- "@types/jasmine-jquery": "^1.5.33",
- "@types/jquery": "^1.10.33",
- "@angular/upgrade": "^9.1.13",
- "@angular/core": "^9.1.13",
- "angular": "^1.8.2",
- "angular-mocks": "^1.8.2",
- "typescript": "^3.8.3",
- "karma": "^5.2.3",
- "karma-jasmine": "^3.3.1",
- "karma-webpack": "^4.0.2",
- "jasmine-core": "^3.5.0",
The custom matchers have been defined in JavaScript like so:
const matchers = {
toBeNgVisible: () => {
return {
compare: function (actual) {
return {
pass: actual && $(actual).closest('[hidden]').length === 0;,
message: 'Expected "' + actual + '," and all of its parents, to not have a hidden attribute.'
};
}
};
}
}
beforeEach(() => { jasmine.addMatchers(matchers); });
I also have a declaration file named matchers.d.ts
, which looks like:
declare namespace jasmine {
interface Matchers<T> {
toBeNgVisible(): boolean;
}
}
My tsconfig file does not contain any file includes/excludes, and the matchers.d.ts file is included in the files list.
This issue is causing confusion and hindering efficient development. If anyone has encountered this problem before, or has any advice on what I can try next, I would greatly appreciate it. I'm unsure whether the issue lies within my Webpack configuration or my WebStorm configuration, so any suggestions are welcome.