Added missing iteration assertions (#25606)

This commit is contained in:
Harm van der Werf
2018-05-08 19:29:33 +02:00
committed by Sheetal Nandi
parent 96e3ca2355
commit a58126129b
2 changed files with 88 additions and 0 deletions

View File

@@ -88,6 +88,27 @@ spyStringArg('foo');
expect(spyStringArg).to.have.been.called.always.with.exactly('foo');
spyStringArg.should.have.been.called.always.with.exactly('foo');
// .first / .second / .third
const spyStringIteratedArg = chai.spy((arg: string) => arg);
spyStringIteratedArg('foo');
spyStringIteratedArg('bar');
spyStringIteratedArg('baz');
expect(spyStringIteratedArg).to.have.been.first.called.with('foo');
spyStringIteratedArg.should.have.been.first.called.with('foo');
expect(spyStringIteratedArg).to.have.been.first.called.with('bar');
spyStringIteratedArg.should.have.been.first.called.with('bar');
expect(spyStringIteratedArg).to.have.been.first.called.with('baz');
spyStringIteratedArg.should.have.been.first.called.with('baz');
// .nth
const spyStringNthArg = chai.spy((arg: string) => arg);
spyStringNthArg('foo');
spyStringNthArg('bar');
expect(spyStringNthArg).on.nth(1).be.called.with('foo');
spyStringNthArg.should.on.nth(1).be.called.with('foo');
expect(spyStringNthArg).on.nth(2).be.called.with('bar');
spyStringNthArg.should.on.nth(2).be.called.with('bar');
// .once
expect(spy).to.have.been.called.once;
expect(spy).to.not.have.been.called.once;

View File

@@ -10,6 +10,10 @@ declare namespace Chai {
spy: ChaiSpies.Spy;
}
interface LanguageChains {
on: Assertion;
}
interface Assertion {
/**
* ####.spy
@@ -31,6 +35,28 @@ declare namespace Chai {
* Note that ```called``` can be used as a chainable method.
*/
called: ChaiSpies.Called;
/**
* * ####.been
* * Assert that something has been spied on. Negation passes through.
* * ```ts
* * expect(spy).to.have.been.called();
* * spy.should.have.been.called();
* ```
* Note that ```been``` can be used as a chainable method.
*/
been: ChaiSpies.Been;
/**
* * ####.nth (function)
* * Assert that something has been spied on on a certain index. Negation passes through.
* * ```ts
* * expect(spy).on.nth(5).be.called.with('foobar');
* * spy.should.on.nth(5).be.called.with('foobar');
* ```
* Note that ```nth``` can be used as a chainable method.
*/
nth(index: number): Assertion;
}
}
@@ -224,6 +250,47 @@ declare namespace ChaiSpies {
lt(n: number): Chai.Assertion;
}
interface Been extends Chai.Assertion {
(): Chai.Assertion;
called: Called;
/**
* ####.first
* Assert that a spy has been called first.
* ```ts
* expect(spy).to.have.been.called.first;
* expect(spy).to.not.have.been.called.first;
* spy.should.have.been.called.first;
* spy.should.not.have.been.called.first;
* ```
*/
first: Chai.Assertion;
/**
* ####.second
* Assert that a spy has been called second.
* ```ts
* expect(spy).to.have.been.called.second;
* expect(spy).to.not.have.been.called.second;
* spy.should.have.been.called.second;
* spy.should.not.have.been.called.second;
* ```
*/
second: Chai.Assertion;
/**
* ####.third
* Assert that a spy has been called third.
* ```ts
* expect(spy).to.have.been.called.third;
* expect(spy).to.not.have.been.called.third;
* spy.should.have.been.called.third;
* spy.should.not.have.been.called.third;
* ```
*/
third: Chai.Assertion;
}
interface With {
/**
* ####.with