supertape
operator simplifies work with @cloudcmd/stub.
npm i @supertape/operator-stub -D
Adds next operators to work with:
import test, {stub} from 'supertape';
test('function call', (t) => {
const fn = stub();
fn('hello', 'world');
t.calledWith(fn, ['hello', 'world'], 'fn should be called with "hello", "world"');
t.end();
});
import test, {stub} from 'supertape';
test('function called with no args', (t) => {
const fn = stub();
fn();
t.calledWithNoArgs(fn);
t.end();
});
import test, {stub} from 'supertape';
test('function called count', (t) => {
const fn = stub();
fn();
fn();
t.calledCount(fn, 2);
t.end();
});
import test, {stub} from 'supertape';
test('function called once', (t) => {
const fn = stub();
fn('hello');
t.calledOnce(fn);
t.end();
});
import test, {stub} from 'supertape';
test('function called twice', (t) => {
const fn = stub();
fn('hello');
fn('world');
t.calledTwice(fn);
t.end();
});
import test, {stub} from 'supertape';
test('function called with new', (t) => {
const fn = stub();
new fn();
t.calledWithNew(fn);
t.end();
});
Check that fn1
called before fn2
.
Do not forget to set names of stubs.
import test, {stub} from 'supertape';
test('function called with new', (t) => {
const init = stub().withName('init');
const show = stub().withName('show');
init();
show();
t.calledBefore(show, init);
t.end();
});
Check that fn1
called after fn2
.
Do not forget to set names of stubs.
import test, {stub} from 'supertape';
test('function called with new', (t) => {
const init = stub().withName('init');
const show = stub().withName('show');
init();
show();
t.calledAfter(init, show);
t.end();
});
Check that array of stubs fns
called in order;
Do not forget to set names of stubs.
import test, {stub} from 'supertape';
test('function called with new', (t) => {
const init = stub().withName('init');
const show = stub().withName('show');
init();
show();
t.calledInOrder([init, show]);
t.end();
});
MIT