I have a hybrid Angular and Angular.js app testing with Karma / Jasmine. The old code used custom matchers and it works great, the same matchers are used in the new TypeScript code as well. The TypeScript compiler for Webpack compiles and runs the spec's just fine, but the WebStorm inspector underlines them as errors like so:
With the error message:
TS2339: Property 'toBeNgVisible' does not exist on type 'ArrayLikeMatchers '.
The environment looks like:
- "@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",
My custom matchers are written 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); });
There is a declaration file, matchers.d.ts, that looks like:
declare namespace jasmine {
interface Matchers<T> {
toBeNgVisible(): boolean;
}
}
My tsconfig file does not have any file includes/excludes and my matchers.d.ts file is included in the files list.
This issue obfuscates real problems and gets in the way of efficient development. Has anyone experienced this? Is there any guidance into what I can try next? I am not even sure if the issue is when my Webpack configuration or my WebStorm configuration so any suggestions would be welcome.
