I have a react/typescript project, using jest, where I have a custom matcher like:
export const MyCustomMatchers = {
toBeTheSameAsRemote: function(_util: any, _customEqualityTesters: any) {
return {
compare: function(actual: Brand, expected: RemoteBrand) {
const pass: boolean = attributesMatch(actual, expected);
const message: string = pass
? 'Local matches Remote'
: 'Local does not match Remote';
return { pass, message: () => message };
}
};
}
};
which I reference in my tests by doing inside the describe
function:
beforeEach(() => {
jasmine.addMatchers(MyCustomMatchers);
});
And use like this in it
functions:
expect(localValue).toBeTheSameAsRemote(remoteValue);
Tests run properly, but typescript compiler does not recognize the matcher, which makes sense cuz I haven't defined it anywhere in the types system
Property 'toBeTheSameAsRemote' does not exist on type 'JestMatchersShape<Matchers<void, MyType[]>, Matchers<Promise<void>, MyType[]>>'.ts(2339)
What I have found so far relates to extending the namespace for jasmine and/or jest, e.g.
declare namespace jasmine {
interface Matchers {
toBeTheSameAsRemote(remote: any): any;
}
}
which hasn't worked for me.
Do you have any idea?