当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript spy.on方法代码示例

本文整理汇总了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);
    });
开发者ID:asrytis,项目名称:dice-game,代码行数:27,代码来源:game-room.ts

示例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);
    });
开发者ID:jsobell,项目名称:treacherous,代码行数:25,代码来源:field-error-processor-tests.ts

示例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;
	});
开发者ID:lgeorgieff,项目名称:javascript,代码行数:7,代码来源:Car.spec.ts

示例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));
 });
开发者ID:joelalejandro,项目名称:xethya,代码行数:7,代码来源:base-modifier.test.ts

示例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();
    });
开发者ID:vladjerca,项目名称:imgstry,代码行数:8,代码来源:logger.test.ts

示例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()
        })
    })
开发者ID:Evgeniia0511,项目名称:clean-todo,代码行数:9,代码来源:todo.interactor.spec.ts

示例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);
  });
开发者ID:joelalejandro,项目名称:xethya,代码行数:9,代码来源:mersenne-twister.test.ts

示例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);
        });
开发者ID:mayacoda,项目名称:cwl-ts,代码行数:9,代码来源:ValidationBase.spec.ts


注:本文中的chai.spy.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。