sinon: add typed args tests

This commit is contained in:
James Garbutt
2018-12-12 19:02:32 +00:00
committed by 43081j
parent 56b611f687
commit 91e0fb8638
+35
View File
@@ -288,6 +288,41 @@ function testAssert() {
sinon.assert.expose(obj, { includeFail: true });
}
function testTypedSpy() {
const cls = class {
foo(a: number, b: string): number {
return 3;
}
}
const instance = new cls();
const spy = sinon.spy(instance, 'foo');
spy.calledWith(5, 'x');
spy.calledWith(sinon.match(5), 'x');
spy.calledWithExactly(5, 'x');
spy.calledWithExactly(5, sinon.match('x'));
spy.calledOnceWith(5, 'x');
spy.calledOnceWith(sinon.match(5), 'x');
spy.notCalledWith(5, 'x');
spy.notCalledWith(sinon.match(5), 'x');
spy.returned(5);
spy.returned(sinon.match(5));
spy.withArgs(sinon.match(5), 'x').calledWith(5, 'x');
spy.alwaysCalledWith(sinon.match(5), 'x');
spy.alwaysCalledWith(5, 'x');
spy.alwaysCalledWithExactly(sinon.match(5), 'x');
spy.alwaysCalledWithExactly(5, 'x');
spy.neverCalledWith(sinon.match(5), 'x');
spy.neverCalledWith(5, 'x');
const stub = sinon.stub(instance, 'foo');
stub.withArgs(5, 'x').returns(3);
stub.withArgs(sinon.match(5), 'x').returns(5);
}
function testSpy() {
const fn = () => { };
const obj = class {