當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。