本文整理汇总了TypeScript中chai.spy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript spy函数的具体用法?TypeScript spy怎么用?TypeScript spy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spy函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should match and call function', async () => {
let inc = 1;
function getMatchRoot(req: ServerRequest, res: ServerResponse) {}
function getMatchRootId(req: ServerRequest, res: ServerResponse, id: string) {
assert.isTrue(id === inc.toString());
++inc;
}
let spyFunctionRoot = spy(getMatchRoot);
let spyFunctionRootId = spy(getMatchRootId);
helloRoute.get('/spy', spyFunctionRoot);
helloRoute.get('/spy/:id', spyFunctionRootId);
helloRoute.get('/spy/:id/hello', spyFunctionRootId);
helloRoute.get('/spy/:id/hello/world', spyFunctionRootId);
assert.isTrue(
await helloRoute.parse({ url: '/spy' }, new MockReq({ method: 'GET' }), null)
);
assert.isTrue(
await helloRoute.parse({ url: '/spy/1' }, new MockReq({ method: 'GET' }), null)
);
assert.isTrue(
await helloRoute.parse({ url: '/spy/2' }, new MockReq({ method: 'GET' }), null)
);
expect(spyFunctionRoot).to.have.been.called.exactly(1);
expect(spyFunctionRootId).to.have.been.called.exactly(2);
});
示例2: it
it('should not re-pause if countdown was already paused', () => {
const spyClearInterval = chai.spy(clearInterval);
countdown.pauseCountdown();
clock.tick(5000);
countdown.pauseCountdown();
expect(spyClearInterval).to.not.have.been.called;
});
示例3: it
it('should correctly notice array size changes', function (done) {
var dummyModel = {
foo: 10,
bar: [ 10, 20 ]
};
var rulesetBuilder = new RulesetBuilder();
var ruleset = rulesetBuilder.create()
.forProperty("foo")
.addRule("required", true)
.forProperty("bar")
.addRule("minLength", 1)
.addRuleForEach("maxValue", 20)
.build();
var modelWatcher = new ModelWatcher();
modelWatcher.setupWatcher(dummyModel, ruleset, 50);
var spySubscription = spy(function(eventArgs){});
modelWatcher.onPropertyChanged.subscribe(spySubscription);
dummyModel.bar.push(30);
setTimeout(function(){
expect(spySubscription).to.have.been.called.exactly(2);
modelWatcher.stopWatching();
done();
}, 250);
});
示例4: it
it('should call find of model', () => {
const spy = chai.spy();
const model = {
find: spy
};
findAll(model);
expect(spy).to.have.been.called();
});