@types/chai-spies
- Version 1.0.6
- Published
- 22.2 kB
- 1 dependency
- MIT license
Install
npm i @types/chai-spies
yarn add @types/chai-spies
pnpm add @types/chai-spies
Overview
TypeScript definitions for chai-spies
Index
Variables
Namespaces
Variables
variable spies
var spies: ChaiSpies.Spy;
Namespaces
namespace Chai
namespace Chai {}
interface Assertion
interface Assertion {}
property been
been: ChaiSpies.Been;
* ####.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.
property called
called: ChaiSpies.Called;
####.called Assert that a spy has been called. Negation passes through.
expect(spy).to.have.been.called();spy.should.have.been.called();Note that ```called``` can be used as a chainable method.
property spy
spy: Assertion;
####.spy Asserts that object is a spy.
expect(spy).to.be.spy;spy.should.be.spy;
method nth
nth: (index: number) => Assertion;
* ####.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.
interface ChaiStatic
interface ChaiStatic {}
property spy
spy: ChaiSpies.Spy;
interface LanguageChains
interface LanguageChains {}
property on
on: Assertion;
namespace chai-spies
module 'chai-spies' {}
variable spies
var spies: ChaiSpies.Spy;
namespace ChaiSpies
namespace ChaiSpies {}
interface AlwaysWith
interface AlwaysWith {}
method exactly
exactly: ( a?: any, b?: any, c?: any, d?: any, e?: any, f?: any, g?: any, h?: any, i?: any, j?: any) => Chai.Assertion;
####.always.with.exactly Assert that the spy has never been called with a different list of arguments than the one provided.
spy('foo');spy('foo');expect(spy).to.have.been.called.always.with.exactly('foo');spy.should.have.been.called.always.with.exactly('foo');
call signature
( a: any, b?: any, c?: any, d?: any, e?: any, f?: any, g?: any, h?: any, i?: any, j?: any): Chai.Assertion;
####.always.with Assert that every time the spy has been called the argument list contained the given arguments.
spy('foo');spy('foo', 'bar');spy(1, 2, 'foo');expect(spy).to.have.been.called.always.with('foo');spy.should.have.been.called.always.with('foo');
interface At
interface At {}
method least
least: (n: number) => Chai.Assertion;
####.min(n) / .at.least(n) Assert that a spy has been called minimum of ```n``` times.
expect(spy).to.have.been.called.min(3);expect(spy).to.not.have.been.called.at.least(3);spy.should.have.been.called.at.least(3);spy.should.not.have.been.called.min(3);
method most
most: (n: number) => Chai.Assertion;
####.max(n) / .at.most(n) Assert that a spy has been called maximum of ```n``` times.
expect(spy).to.have.been.called.max(3);expect(spy).to.not.have.been.called.at.most(3);spy.should.have.been.called.at.most(3);spy.should.not.have.been.called.max(3);
interface Been
interface Been extends Chai.Assertion {}
property called
called: Called;
property first
first: Chai.Assertion;
####.first Assert that a spy has been called first.
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;
property second
second: Chai.Assertion;
####.second Assert that a spy has been called second.
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;
property third
third: Chai.Assertion;
####.third Assert that a spy has been called third.
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;
call signature
(): Chai.Assertion;
interface Called
interface Called {}
property always
always: Always;
property at
at: At;
property once
once: Chai.Assertion;
####.once Assert that a spy has been called exactly once.
expect(spy).to.have.been.called.once;expect(spy).to.not.have.been.called.once;spy.should.have.been.called.once;spy.should.not.have.been.called.once;
property twice
twice: Chai.Assertion;
####.twice Assert that a spy has been called exactly twice.
expect(spy).to.have.been.called.twice;expect(spy).to.not.have.been.called.twice;spy.should.have.been.called.twice;spy.should.not.have.been.called.twice;
property with
with: With;
method above
above: (n: number) => Chai.Assertion;
####.above(n) / .gt(n) Assert that a spy has been called more than ```n``` times.
expect(spy).to.have.been.called.above(3);spy.should.not.have.been.called.above(3);
method below
below: (n: number) => Chai.Assertion;
####.below(n) / .lt(n) Assert that a spy has been called fewer than ```n``` times.
expect(spy).to.have.been.called.below(3);spy.should.not.have.been.called.below(3);
method exactly
exactly: (n: number) => Chai.Assertion;
####.exactly(n) Assert that a spy has been called exactly ```n``` times.
expect(spy).to.have.been.called.exactly(3);expect(spy).to.not.have.been.called.exactly(3);spy.should.have.been.called.exactly(3);spy.should.not.have.been.called.exactly(3);
method gt
gt: (n: number) => Chai.Assertion;
####.above(n) / .gt(n) Assert that a spy has been called more than ```n``` times.
expect(spy).to.have.been.called.gt(3);spy.should.not.have.been.called.gt(3);
method lt
lt: (n: number) => Chai.Assertion;
####.below(n) / .lt(n) Assert that a spy has been called fewer than ```n``` times.
expect(spy).to.have.been.called.lt(3);spy.should.not.have.been.called.lt(3);
method max
max: (n: number) => Chai.Assertion;
####.max(n) / .at.most(n) Assert that a spy has been called maximum of ```n``` times.
expect(spy).to.have.been.called.max(3);expect(spy).to.not.have.been.called.at.most(3);spy.should.have.been.called.at.most(3);spy.should.not.have.been.called.max(3);
method min
min: (n: number) => Chai.Assertion;
####.min(n) / .at.least(n) Assert that a spy has been called minimum of ```n``` times.
expect(spy).to.have.been.called.min(3);expect(spy).to.not.have.been.called.at.least(3);spy.should.have.been.called.at.least(3);spy.should.not.have.been.called.min(3);
call signature
(): Chai.Assertion;
interface Resetable
interface Resetable {}
method reset
reset: () => this;
#### proxy.reset (function)
Resets __spy object parameters for instantiation and reuse
Returns
proxy spy object
interface Sandbox
interface Sandbox {}
method on
on: ( object: Object, methodNames: string | string[], fn?: (...parameters: any[] | any) => any) => any;
#### chai.spy.on (function)
Wraps an object method into spy. All calls will pass through to the original function.
Parameter object
Parameter methodNames
names to spy on
Parameter fn
replacement function
Returns
function to actually call
method restore
restore: (object?: Object, methodNames?: string | string[]) => void;
#### chai.spy.restore (function)
Restores previously wrapped object's method. Restores all spied objects of a sandbox if called without parameters.
Parameter object
Parameter methods
name or names {Sandbox} Sandbox instance
interface Spy
interface Spy {}
method interface
interface: { (name: string, methods: string[]): any; (methods: string[]): any; <T>(name: string, methods: T): T; <T>(methods: T): T;};
#### chai.spy.interface (function)
Creates an object with spied methods.
var object = chai.spy.interface('Array', [ 'push', 'pop' ]);Parameter name
object name
Parameter method
names or method definitions
Returns
object with spied methods
method on
on: ( object: Object, methodNames: string | string[], fn?: (...parameters: any[] | any) => any) => any;
#### chai.spy.on (function)
Wraps an object method into spy. All calls will pass through to the original function.
var spy = chai.spy.on(Array, 'isArray');Parameter object
Parameter method
names to spy on
Parameter fn
replacement function
Returns
function to actually call
method restore
restore: (object?: Object, methodNames?: string | string[]) => void;
#### chai.spy.restore (function)
Restores spy assigned to DEFAULT sandbox
Restores previously wrapped object's method. Restores all spied objects of a sandbox if called without parameters.
Parameter object
Parameter methods
name or names {Sandbox} Sandbox instance
method returns
returns: <T>(value: T) => SpyFunc0Proxy<T>;
#### chai.spy.returns (function)
Creates a spy which returns static value.
var method = chai.spy.returns(true);Parameter value
static value which is returned by spy
Returns
new spy function which returns static value public
method sandbox
sandbox: () => Sandbox;
### chai.spy.sandbox
Creates a sandbox.
Sandbox is a set of spies. Sandbox allows to track methods on objects and restore original methods with on restore call.
Returns
{Sandbox}
call signature
(): SpyFunc0Proxy<void>;
#### chai.spy (function)
Wraps a function in a proxy function. All calls will pass through to the original function.
function original() {}var spy = chai.spy(original), e_spy = chai.spy();Parameter fn
function to spy on. ```function () {}```
Returns
function to actually call
call signature
<R>(fn: SpyFunc0<R>): SpyFunc0Proxy<R>;
call signature
<A1, A2, A3, A4, A5, A6, A7, A8, A9, R>( fn: SpyFunc9<A1, A2, A3, A4, A5, A6, A7, A8, A9, R>): SpyFunc9Proxy<A1, A2, A3, A4, A5, A6, A7, A8, A9, R>;
call signature
<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R>( fn: SpyFunc10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R>): SpyFunc10Proxy<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R>;
call signature
<R>(name: string, fn: SpyFunc0<R>): SpyFunc0Proxy<R>;
call signature
<A1, R>(name: string, fn: SpyFunc1<A1, R>): SpyFunc1Proxy<A1, R>;
call signature
<A1, A2, R>(name: string, fn: SpyFunc2<A1, A2, R>): SpyFunc2Proxy<A1, A2, R>;
call signature
<A1, A2, A3, R>(name: string, fn: SpyFunc3<A1, A2, A3, R>): SpyFunc3Proxy< A1, A2, A3, R>;
call signature
<A1, A2, A3, A4, R>( name: string, fn: SpyFunc4<A1, A2, A3, A4, R>): SpyFunc4Proxy<A1, A2, A3, A4, R>;
call signature
<A1, A2, A3, A4, A5, R>( name: string, fn: SpyFunc5<A1, A2, A3, A4, A5, R>): SpyFunc5Proxy<A1, A2, A3, A4, A5, R>;
call signature
<A1, A2, A3, A4, A5, A6, R>( name: string, fn: SpyFunc6<A1, A2, A3, A4, A5, A6, R>): SpyFunc6Proxy<A1, A2, A3, A4, A5, A6, R>;
call signature
<A1, A2, A3, A4, A5, A6, A7, R>( name: string, fn: SpyFunc7<A1, A2, A3, A4, A5, A6, A7, R>): SpyFunc7Proxy<A1, A2, A3, A4, A5, A6, A7, R>;
call signature
<A1, R>(fn: SpyFunc1<A1, R>): SpyFunc1Proxy<A1, R>;
call signature
<A1, A2, A3, A4, A5, A6, A7, A8, R>( name: string, fn: SpyFunc8<A1, A2, A3, A4, A5, A6, A7, A8, R>): SpyFunc8Proxy<A1, A2, A3, A4, A5, A6, A7, A8, R>;
call signature
<A1, A2, A3, A4, A5, A6, A7, A8, A9, R>( name: string, fn: SpyFunc9<A1, A2, A3, A4, A5, A6, A7, A8, A9, R>): SpyFunc9Proxy<A1, A2, A3, A4, A5, A6, A7, A8, A9, R>;
call signature
<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R>( name: string, fn: SpyFunc10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R>): SpyFunc10Proxy<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R>;
call signature
<A1, A2, R>(fn: SpyFunc2<A1, A2, R>): SpyFunc2Proxy<A1, A2, R>;
call signature
<A1, A2, A3, R>(fn: SpyFunc3<A1, A2, A3, R>): SpyFunc3Proxy<A1, A2, A3, R>;
call signature
<A1, A2, A3, A4, R>(fn: SpyFunc4<A1, A2, A3, A4, R>): SpyFunc4Proxy< A1, A2, A3, A4, R>;
call signature
<A1, A2, A3, A4, A5, R>(fn: SpyFunc5<A1, A2, A3, A4, A5, R>): SpyFunc5Proxy< A1, A2, A3, A4, A5, R>;
call signature
<A1, A2, A3, A4, A5, A6, R>( fn: SpyFunc6<A1, A2, A3, A4, A5, A6, R>): SpyFunc6Proxy<A1, A2, A3, A4, A5, A6, R>;
call signature
<A1, A2, A3, A4, A5, A6, A7, R>( fn: SpyFunc7<A1, A2, A3, A4, A5, A6, A7, R>): SpyFunc7Proxy<A1, A2, A3, A4, A5, A6, A7, R>;
call signature
<A1, A2, A3, A4, A5, A6, A7, A8, R>( fn: SpyFunc8<A1, A2, A3, A4, A5, A6, A7, A8, R>): SpyFunc8Proxy<A1, A2, A3, A4, A5, A6, A7, A8, R>;
interface SpyFunc0
interface SpyFunc0<R> {}
call signature
(): R;
interface SpyFunc0Proxy
interface SpyFunc0Proxy<R> extends SpyFunc0<R>, Resetable {}
interface SpyFunc1
interface SpyFunc1<A1, R> {}
call signature
(a: A1): R;
interface SpyFunc10
interface SpyFunc10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R> {}
call signature
(a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8, i: A9, j: A10): R;
interface SpyFunc10Proxy
interface SpyFunc10Proxy<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R> extends SpyFunc10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, R>, Resetable {}
interface SpyFunc1Proxy
interface SpyFunc1Proxy<A1, R> extends SpyFunc1<A1, R>, Resetable {}
interface SpyFunc2
interface SpyFunc2<A1, A2, R> {}
call signature
(a: A1, b: A2): R;
interface SpyFunc2Proxy
interface SpyFunc2Proxy<A1, A2, R> extends SpyFunc2<A1, A2, R>, Resetable {}
interface SpyFunc3
interface SpyFunc3<A1, A2, A3, R> {}
call signature
(a: A1, b: A2, c: A3): R;
interface SpyFunc3Proxy
interface SpyFunc3Proxy<A1, A2, A3, R> extends SpyFunc3<A1, A2, A3, R>, Resetable {}
interface SpyFunc4
interface SpyFunc4<A1, A2, A3, A4, R> {}
call signature
(a: A1, b: A2, c: A3, d: A4): R;
interface SpyFunc4Proxy
interface SpyFunc4Proxy<A1, A2, A3, A4, R> extends SpyFunc4<A1, A2, A3, A4, R>, Resetable {}
interface SpyFunc5
interface SpyFunc5<A1, A2, A3, A4, A5, R> {}
call signature
(a: A1, b: A2, c: A3, d: A4, e: A5): R;
interface SpyFunc5Proxy
interface SpyFunc5Proxy<A1, A2, A3, A4, A5, R> extends SpyFunc5<A1, A2, A3, A4, A5, R>, Resetable {}
interface SpyFunc6
interface SpyFunc6<A1, A2, A3, A4, A5, A6, R> {}
call signature
(a: A1, b: A2, c: A3, d: A4, e: A5, f: A6): R;
interface SpyFunc6Proxy
interface SpyFunc6Proxy<A1, A2, A3, A4, A5, A6, R> extends SpyFunc6<A1, A2, A3, A4, A5, A6, R>, Resetable {}
interface SpyFunc7
interface SpyFunc7<A1, A2, A3, A4, A5, A6, A7, R> {}
call signature
(a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7): R;
interface SpyFunc7Proxy
interface SpyFunc7Proxy<A1, A2, A3, A4, A5, A6, A7, R> extends SpyFunc7<A1, A2, A3, A4, A5, A6, A7, R>, Resetable {}
interface SpyFunc8
interface SpyFunc8<A1, A2, A3, A4, A5, A6, A7, A8, R> {}
call signature
(a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8): R;
interface SpyFunc8Proxy
interface SpyFunc8Proxy<A1, A2, A3, A4, A5, A6, A7, A8, R> extends SpyFunc8<A1, A2, A3, A4, A5, A6, A7, A8, R>, Resetable {}
interface SpyFunc9
interface SpyFunc9<A1, A2, A3, A4, A5, A6, A7, A8, A9, R> {}
call signature
(a: A1, b: A2, c: A3, d: A4, e: A5, f: A6, g: A7, h: A8, i: A9): R;
interface SpyFunc9Proxy
interface SpyFunc9Proxy<A1, A2, A3, A4, A5, A6, A7, A8, A9, R> extends SpyFunc9<A1, A2, A3, A4, A5, A6, A7, A8, A9, R>, Resetable {}
interface With
interface With {}
method exactly
exactly: ( a?: any, b?: any, c?: any, d?: any, e?: any, f?: any, g?: any, h?: any, i?: any, j?: any) => Chai.Assertion;
####.with.exactly Similar to .with, but will pass only if the list of arguments is exactly the same as the one provided.
spy();spy('foo', 'bar');expect(spy).to.have.been.called.with.exactly('foo', 'bar');spy.should.have.been.called.with.exactly('foo', 'bar');Will not pass for ```spy('foo')```, ```spy('bar')```, ```spy('bar'); spy('foo')```, ```spy('foo'); spy('bar')```, ```spy('bar', 'foo')``` or ```spy('foo', 'bar', 1)```. Can be used for calls with a single argument too.
call signature
( a: any, b?: any, c?: any, d?: any, e?: any, f?: any, g?: any, h?: any, i?: any, j?: any): Chai.Assertion;
####.with Assert that a spy has been called with a given argument at least once, even if more arguments were provided.
spy('foo');expect(spy).to.have.been.called.with('foo');spy.should.have.been.called.with('foo');Will also pass for ```spy('foo', 'bar')``` and ```spy(); spy('foo')```. If used with multiple arguments, assert that a spy has been called with all the given arguments at least once.
spy('foo', 'bar', 1);expect(spy).to.have.been.called.with('bar', 'foo');spy.should.have.been.called.with('bar', 'foo');
Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/chai-spies
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/chai-spies)
- HTML<a href="https://www.jsdocs.io/package/@types/chai-spies"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3246 ms. - Missing or incorrect documentation? Open an issue for this package.