稳住

最简单 sinon.stub( ) (中文( ) ) 备选案文。 支持显示 diff 在 calleddWith。 。 。 .
安装
npm i @cloudcmd/stub
API 密码
stub( 缩写)
impl- 支架执行
import {stub} from '@cloudcmd/stub';
const fn = stub();
// fn contains stubbed function
const asyncFn = stub(async () => {
throw Error('hi');
}); // asyncFn contains stub async function
stub (). 返回([值])
const fn = stub().returns('hello');
fn();
// returns
'hello';
stub (. srows ([ 错误])
const fn = stub().throws(Error('hello'));
fn();
// throws
Error('hello');
stub (). rejects ([error]) (中文(简体) )
const fn = stub().rejects(Error('hello'));
await fn();
// rejects
Error('hello');
stub (. resolves ([值])
const fn = stub().resolves('hello');
await fn();
// resolves
'hello';
stub (). called With ([args]) (德语)
const fn = stub();
fn('hello', 'world');
fn.calledWith('hello', 'world');
// returns true
stub (). 称为 With New ()
const fn = stub();
new fn();
fn.calledWithNew();
// returns
true;
stub (). 之前称为 (fn)
const fn1 = stub();
const fn2 = stub();
fn1();
fn2();
fn1.calledBefore(fn2);
// returns
true;
stub (). 称为 After( fn)
const fn1 = stub();
const fn2 = stub();
fn1();
fn2();
fn2.calledAfter(fn1);
// returns
true;
stub( ). 所谓的
const fn = stub();
fn.called;
// returns
false;
fn();
fn.called;
// returns
true;
stub (.). callCount (英语)
const fn = stub();
fn.callCount;
// returns
0;
fn();
fn.callCount;
// returns
1;
stub (. args) (英语)
const fn = stub();
fn.args;
// returns
[];
fn(1);
fn.args;
// returns
[
[1],
];
stub (. callId) (英语)
每个 stub 拿着 callId,用于确定 stub 电话:
const fn1 = stub();
const fn2 = stub();
fn1();
fn2();
fn1.callId;
// returns
1;
fn2.callId;
// returns
2;
是斯图( fn)
检查是否提供了函数为 stub .
const {stub, isStub} = require('@cloudcmd/stub');
const fn = stub();
isStub(fn);
// returns
true;
isStub(() => {});
// returns
false;
相关
- {\fn黑体\fs22\bord1\shad0\3ahbe\4ah00\fscx67\fscy66\2chffffff\3ch808080}我被叫作"无所事事" {\fn黑体\fs22\bord1\shad0\3ahbe\4ah00\fscx67\fscy66\2chffffff\3ch808080}我.. - 西农
calledWith微调 - 尝试到磁带 - 说吧
try catch用于合成磁带测试 - 渔获量 - 实用的试捕包装.
- 试捕 - 实用的捕捉口袋以兑现承诺.
许可证
麻省理工学院