本文整理汇总了TypeScript中chai.spy类的典型用法代码示例。如果您正苦于以下问题:TypeScript spy类的具体用法?TypeScript spy怎么用?TypeScript spy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了spy类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it("should not propagate if stopPropagation is passed", () => {
const spy = chai.spy.on(parent, "updateValidity");
parent.child.setIssue({
[parent.child.loc]: {
message: "",
type: "error",
code: ErrorCode.ID_INVALID_CHAR
}
}, true);
expect(spy).to.not.have.been.called;
expect(parent.errors).to.be.empty;
expect(parent.child.errors).to.have.lengthOf(1);
});
示例2: it
it('should clear everything using #remove', () => {
const spyRemove = chai.spy.on(collection, 'remove');
collection.removeAll();
const eventListeners: string[] = collection.eventNames() as string[]
expect(eventListeners.filter(
(eventName: string) => /foo/.test(eventName)
)).to.be.empty;
expect(eventListeners.filter(
(eventName: string) => /bar/.test(eventName)
)).to.be.empty;
expect(spyRemove).to.have.been.called.twice;
expect(collection.count).to.equal(0);
});
示例3: it
it('Should not delete the todo from the interactor nor set the collection if the gateway rejected the Promise', done => {
const spy = chai.spy.on(controller, 'setTodoCollection')
gateway.removeTodo = id => Promise.reject('Spec rejected the Promise intentionnaly')
sut.deleteTodo(todo.id)
.catch(() => {
expect(sut.todos).to.deep.equal([
todo,
todo_
])
expect(spy).not.to.have.been.called
done()
})
})
示例4: it
it('should call challengeResolver when checking for challenge', () => {
const spy = chai.spy.on(combat, 'challengeResolver');
expect(combat.challenge()).to.be.true;
expect(spy).to.have.been.called;
});
示例5: afterEach
afterEach(() => spy.restore(console));
示例6: on
on(name: string, fn: () => void) {
}
};
let spiedFn = chai.spy(original);
// then use in place of original
ee.on('some event', spiedFn);
// or use without original
let spy_again = chai.spy();
ee.on('some other event', spy_again);
// or you can track an object's method
let array = [ 1, 2, 3 ];
chai.spy.on(array, 'push');
// or you can track multiple object's methods
chai.spy.on(array, 'push', 'pop');
array.push(5);
// and you can reset the object calls
// array.push.reset();
// or you can create spy object
let object = chai.spy.object([ 'push', 'pop' ]);
object.push(5);
// or you create spy which returns static value
spiedFn = chai.spy.returns(true);
示例7: on
on(name: string, fn: () => void) {
}
};
let spiedFn = chai.spy(original);
// then use in place of original
ee.on('some event', spiedFn);
// or use without original
let spy_again = chai.spy();
ee.on('some other event', spy_again);
// or you can track an object's method
let array = [ 1, 2, 3 ];
chai.spy.on(array, 'push');
// or you can track multiple object's methods
chai.spy.on(array, ['push', 'pop']);
// or you can track multiple object's methods
chai.spy.on(array, 'push', function(item) {
array.push(item);
});
array.push(5);
// and you can reset the object calls
// array.push.reset();
// or you can create spy object
示例8: it
it('should do nothing if setting value without changes', () => {
const modifier = new Modifier('foo', 10);
const spyEmit = chai.spy.on(modifier, 'emit');
modifier.value = 10;
expect(spyEmit).to.not.have.been.called;
});