I extend Chai with a helper in my TypeScript test.
import * as chai from 'chai';
chai.use((_chai) => {
let Assertion = _chai.Assertion;
Assertion.addMethod('sortedBy', function(property) {
// ...
});
});
const expect = chai.expect;
In the same file test case makes use of this method:
expect(tasks).to.have.been.sortedBy('from');
Compiler gives error that "Property 'sortedBy' does not exist on type 'Assertion'".
How can I add declaration of sortedBy to Chai.Assertion?
I've tried to add module declaration, just like other Chai plugin modules do, but it doesn't work.
declare module Chai {
interface Assertion {
sortedBy(property: string): void;
}
}
I don't want to make the helper an individual module, because it's trivial.