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


TypeScript Sinon.mock函数代码示例

本文整理汇总了TypeScript中Sinon.mock函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mock函数的具体用法?TypeScript mock怎么用?TypeScript mock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mock函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

        it("sends a command to the command bus", (done) => {
            const commandBusMock = sinon.mock(commandBus);
            commandBusMock.expects("send")
                .once()
                .withArgs(command)
                .returns(new Promise<void>(resolve => resolve()));

            const gateway = new DefaultCommandGateway(commandBus);

            expect(gateway.send(command)).to.eventually.be.fulfilled.and.satisfy(() => {
                commandBusMock.verify();
                return true;
            }).and.notify(done);
        });
开发者ID:martyn82,项目名称:aphajs,代码行数:14,代码来源:DefaultCommandGateway.spec.ts

示例2: it

        it("publishes event only once to the same listener", () => {
            const event = new SimpleEventBusEvent();
            const listener = new SimpleEventBusEventListener();

            const listenerMock = sinon.mock(listener);
            listenerMock.expects("on").once().withArgs(event);

            eventBus.subscribe(listener);
            eventBus.subscribe(listener, SimpleEventBusEvent);

            expect(eventBus.publish(event)).to.equal(true);

            listenerMock.verify();
        });
开发者ID:martyn82,项目名称:aphajs,代码行数:14,代码来源:SimpleEventBus.spec.ts

示例3: it

        it("removes an existing saga from repository if it is inactive", () => {
            const sagaId = "id";
            const saga = new SagaRepositorySpecSaga(sagaId, new AssociationValues());
            const sagaMock = sinon.mock(saga);

            sagaMock.expects("isActive").returns(false);
            storageMock.expects("remove")
                .once()
                .withArgs(sagaId);

            repository.commit(saga);

            storageMock.verify();
        });
开发者ID:mweels,项目名称:aphajs,代码行数:14,代码来源:SagaRepository.spec.ts

示例4: it

        it("unregisters a handler by command type", (done) => {
            const command = new SimpleCommandBusCommand();
            const handler = new SimpleCommandBusCommandHandler();

            const handlerMock = sinon.mock(handler);
            handlerMock.expects("handle").never();

            commandBus.registerHandler(SimpleCommandBusCommand, handler);
            commandBus.unregisterHandler(SimpleCommandBusCommand);

            expect(commandBus.send(command)).to.be.rejectedWith(NoCommandHandlerException).and.notify(() => {
                handlerMock.verify();
                done();
            });
        });
开发者ID:martyn82,项目名称:aphajs,代码行数:15,代码来源:SimpleCommandBus.spec.ts

示例5: it

        it("removes an existing saga from repository if it is inactive", (done) => {
            const sagaId = "id";
            const saga = new SagaRepositorySpecSaga(sagaId, new AssociationValues());
            const sagaMock = sinon.mock(saga);

            sagaMock.expects("isActive").returns(false);
            storageMock.expects("remove")
                .once()
                .withArgs(sagaId)
                .returns(new Promise<void>(resolve => resolve()));

            expect(repository.commit(saga)).to.eventually.be.fulfilled.and.satisfy(() => {
                sagaMock.verify();
                storageMock.verify();
                return true;
            }).and.notify(done);
        });
开发者ID:martyn82,项目名称:aphajs,代码行数:17,代码来源:SagaRepository.spec.ts

示例6: beforeEach

      beforeEach(() => {
        requestMock = sinon.mock(request.httpRequest);
        responseMock = generateResponseMock(200);

        const args: any = parse("http://localhost:8888/");
        args.method = "GET";
        args.headers = {
          "Content-Type": "application/json",
          "X-Pact-Mock-Service": "true",
        };

        requestMock
          .expects("request")
          .once()
          .withArgs(args)
          .returns(requestLibMock)
          .callsArgWith(1, responseMock);
      });
开发者ID:elliottmurray,项目名称:pact-js,代码行数:18,代码来源:request.spec.ts

示例7: it

    it('register succeeds (verify function calls) @unit', async () => {

        let reqMock = sinon.mock({
            body: userSkeleton
        });

        serviceMock
            .expects('findUserByName')
            .once()
            .withArgs('the@email.address');

        serviceMock
            .expects('create')
            .once()
            .withArgs(sinon.match.any, 'the Password$123')
                // the first argument is an object containing an unknown timestamp (createdOn)
                // and thus cannot be tested
            .returns(userSkeleton);

        actionMailServiceMock
            .expects('createActivationEmail')
            .once()
            .withArgs(userSkeleton)
            .returns({
                hash: 'the hash'
            });

        mailServiceMock
            .expects('sendActivationMail')
            .once()
            .withArgs(userSkeleton.lastName, userSkeleton.email, 'the hash');

        let userController = new UserController(loggerMock.object,
                                                serviceMock.object,
                                                mailServiceMock.object,
                                                actionMailServiceMock.object,
                                                userMapper);

        await userController.register(reqMock.object);

        serviceMock.verify();
        mailServiceMock.verify();

    });
开发者ID:Uter1007,项目名称:sumobase.core,代码行数:44,代码来源:user.controller.spec.ts

示例8: it

        it("create new saga if none found because of saga creation policy", (done) => {
            const associationValue = new AssociationValue("foo", "bar");
            const associationValues = new AssociationValues([associationValue]);
            const sagaId = "sagaId";

            const saga = new SimpleSagaManagerSpecSaga(sagaId, associationValues);
            const sagaMock = sinon.mock(saga);

            const event = new SimpleSagaManagerSpecEvent();

            resolverMock.expects("extractAssociationValues")
                .once()
                .returns(associationValues);

            repositoryMock.expects("find")
                .once()
                .withArgs(SimpleSagaManagerSpecSaga, associationValue)
                .returns(new Promise<string[]>(resolve => resolve([])));

            repositoryMock.expects("load").never();

            repositoryMock.expects("commit")
                .once()
                .withArgs(saga)
                .returns(new Promise<void>(resolve => resolve()));

            sagaMock.expects("on")
                .once()
                .withArgs(event);

            factoryMock.expects("createSaga")
                .once()
                .returns(saga);

            expect(manager.on(event)).to.eventually.be.fulfilled.and.satisfy(() => {
                resolverMock.verify();
                repositoryMock.verify();
                sagaMock.verify();
                factoryMock.verify();
                return true;
            }).and.notify(done);
        });
开发者ID:martyn82,项目名称:aphajs,代码行数:42,代码来源:SimpleSagaManager.spec.ts

示例9: describe

describe("transmitter", () => {
  const actions: string[] = ["addUser", "cursorMove"];
  const emit: any = () => true;
  const mockSocket: any = {emit};
  const mockedSocket: SinonMock = mock(mockSocket);
  const transmitters: Transmitters = getTransmitters(mockSocket);
  it("initializes routes for pub sub to call socket.io emit from.", () => {
    transmitters.add(...actions);
    actions.forEach((action: string): any => expect(transmitters[action]).to.be.a("function"));
  });
  it("Triggers a socket emit when calling a transmitter.", () => {
    const value: string = "OkOkOkOK";
    actions.forEach((transmitter: string): any => {
      mockedSocket.expects("emit").withExactArgs(transmitter, value);
      transmitters[transmitter](value);
    });
    mockedSocket.verify();
    mockedSocket.restore();
  });
});
开发者ID:Ruddickmg,项目名称:js-wars,代码行数:20,代码来源:transmitter.spec.ts

示例10: beforeEach

    beforeEach(() => {
      gateway = new Test();
      explorer = new GatewayMetadataExplorer(new MetadataScanner());
      mockExplorer = sinon.mock(explorer);
      (instance as any).metadataExplorer = explorer;

      handlers = ['test'];
      server = { server: 'test' };

      mockExplorer.expects('explore').returns(handlers);
      mockProvider.expects('scanForSocketServer').returns(server);

      hookServerToProperties = sinon.spy();
      subscribeEvents = sinon.spy();

      (instance as any).hookServerToProperties = hookServerToProperties;
      (instance as any).subscribeEvents = subscribeEvents;

      sinon.stub(instance, 'injectMiddleware').returns(0);
    });
开发者ID:SARAVANA1501,项目名称:nest,代码行数:20,代码来源:web-sockets-controller.spec.ts


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