本文整理汇总了TypeScript中chai.spy.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript spy.on方法的具体用法?TypeScript spy.on怎么用?TypeScript spy.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chai.spy
的用法示例。
在下文中一共展示了spy.on方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('broadcast(message, exclude) should send message to all players in the room', function() {
const gameRoom = new GameRoom(createGameRoomOptions(6));
const player1 = createPlayer('Player 1');
const player2 = createPlayer('Player 2');
gameRoom.addPlayer(player1);
gameRoom.addPlayer(player2);
chai.spy.on(player1.ws, 'send');
chai.spy.on(player2.ws, 'send');
gameRoom.broadcast({ msg: 'Hello' });
expect(player1.ws.send).to.have.been.called.exactly(1);
expect(player2.ws.send).to.have.been.called.exactly(1);
gameRoom.broadcast({ data: 'Hello again' });
expect(player1.ws.send).to.have.been.called.exactly(2);
expect(player2.ws.send).to.have.been.called.exactly(2);
// Exclude player1
gameRoom.broadcast({ prop: 'Wadup' }, player1);
expect(player1.ws.send).to.have.been.called.exactly(2);
expect(player2.ws.send).to.have.been.called.exactly(3);
});
示例2: it
it('should stop looking for errors on first fail', function (done) {
var ruleRegistry = new RuleRegistry();
ruleRegistry.registerRule(new RequiredValidationRule());
var maxLengthTreacherous = new MaxLengthValidationRule();
var spiedValidationMethod = spy.on(maxLengthTreacherous, 'validate');
ruleRegistry.registerRule(maxLengthTreacherous);
var fieldErrorProcessor = new FieldErrorProcessor(ruleRegistry);
var dummyModel = new ModelHelper(new PropertyResolver(),{});
var dummyField = null;
var dummyRules = [
new RuleLink("required", true),
new RuleLink("maxLength", 2)
];
fieldErrorProcessor
.checkFieldForErrors(dummyModel, dummyField, dummyRules)
.then(function(error){
expect(error).not.to.be.null;
expect(spiedValidationMethod).to.not.have.been.called;
done();
}).catch(done);
});
示例3: it
it("works correctly if in driving state", () => {
bmw.drive(5);
chai.spy.on(bmw, 'stop');
bmw.switchOff();
expect(bmw.stop).to.have.been.called.once;
expect(bmw.isRunning).to.be.false;
});
示例4: it
it('should call the default calculator when setting the value', () => {
const base = new BaseModifier();
const spy = chai.spy.on(BaseModifierCalculator);
base.value = 20;
expect(spy).to.have.been.called;
expect(base.value).to.equal(BaseModifierCalculator(20));
});
示例5: it
it('should NOT call console.log', () => {
const logMsg = 'I am a simple log message.';
const logSpy = spy.on(console, 'log');
logger.log(logMsg);
expect(logSpy).to.not.have.been.called();
});
示例6: it
it('Should not ask the gateway to delete the todo if it is not in the collection', done => {
let spy = chai.spy.on(gateway, 'removeTodo')
sut.deleteTodo(10)
.catch(() => {
expect(spy).not.to.have.been.called
done()
})
})
示例7: it
it('should reinitialize the generator with the 5489 magic seed if MTI = N + 1', () => {
const mt = new MersenneTwisterAlgorithm();
const spy = chai.spy.on(mt, 'initializeRandomGenerator');
mt.MTI = 625;
mt.generateRandomInteger();
expect(spy).to.have.been.called.with(5489);
});
示例8: it
it("should not call parent's updateValidity if there are no errors", () => {
const spy = chai.spy.on(parent, "updateValidity");
parent.child.clearIssue(ErrorCode.ID_ALL);
expect(spy).to.not.have.been.called;
expect(parent.errors).to.have.lengthOf(0);
});