chai icon indicating copy to clipboard operation
chai copied to clipboard

Typescript test says error TS2339: Property 'by' does not exist on type 'Assertion'.

Open crystalfp opened this issue 6 years ago • 1 comments

I'm trying to test if an array increases in length by 1 after executing a certain operation. The test is written in typescript and runs with the usual mocha -r ts-node/register mytest.ts. The chai version is 4.2.0. Unfortunately, it does not compile with the error: TS2339: Property 'by' does not exist on type 'Assertion'. Here is a simplified test to reproduce the error:

import {expect} from "chai";

describe("OneTest", function() {
	it("bugz", function(done) {

		const aa = [1, 2, 3];

		const len = aa.length;

		expect(aa.push(88)).to.increase({len}, "len").by(1);

		done();
	});
});

I don't see any definition for by() in @types/chai file index.d.ts and if I add the line by(delta: number): Assertion; at the end of interface Assertion it compiles. Well, the test fails, but this is another problem.

Thanks for investigating! mario

crystalfp avatar Jan 10 '20 16:01 crystalfp

Hey @crystalfp; this is a great find. What do you think about opening up a PR with these changes?

koddsson avatar Oct 07 '21 22:10 koddsson