• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Sinon.createStubInstance函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: beforeEach

        beforeEach(() => {
            mockConnectionProfile1 = {name: 'myProfile'};
            mockIdCard1 = sinon.createStubInstance(IdCard);
            mockIdCard1.getUserName.returns('myId');
            mockIdCard1.getBusinessNetworkName.returns('myNetwork');
            mockIdCard1.getConnectionProfile.returns(mockConnectionProfile1);

            // different id
            mockConnectionProfile2 = {name: 'myProfile'};
            mockIdCard2 = sinon.createStubInstance(IdCard);
            mockIdCard2.getUserName.returns('myId2');
            mockIdCard2.getBusinessNetworkName.returns('myNetwork');
            mockIdCard2.getConnectionProfile.returns(mockConnectionProfile2);

            // different profile
            mockConnectionProfile3 = {name: 'myProfile2'};
            mockIdCard3 = sinon.createStubInstance(IdCard);
            mockIdCard3.getUserName.returns('myId1');
            mockIdCard3.getBusinessNetworkName.returns('myNetwork');
            mockIdCard3.getConnectionProfile.returns(mockConnectionProfile3);

            // different network
            mockConnectionProfile4 = {name: 'myProfile'};
            mockIdCard4 = sinon.createStubInstance(IdCard);
            mockIdCard4.getUserName.returns('myId');
            mockIdCard4.getBusinessNetworkName.returns('myNetwork2');
            mockIdCard4.getConnectionProfile.returns(mockConnectionProfile4);

            mockCardMap = new Map<string, IdCard>();
            mockCardMap.set('uuid2xxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', mockIdCard2);
            mockCardMap.set('uuid3xxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', mockIdCard3);
            mockCardMap.set('uuid4xxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', mockIdCard4);
            mockCardMap.set('uuid1xxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', mockIdCard1);
        });
开发者ID:marlonprudente,项目名称:composer,代码行数:34,代码来源:identity-card.service.spec.ts


示例2: beforeEach

    beforeEach(() => {
        mockBusinessNetworkConnection = sinon.createStubInstance(BusinessNetworkConnection);
        mockActiveModal = sinon.createStubInstance(NgbActiveModal);
        let mockBehaviourSubject = sinon.createStubInstance(BehaviorSubject);
        mockBehaviourSubject.next = sinon.stub();
        mockAlertService = sinon.createStubInstance(AlertService);
        mockAlertService.errorStatus$ = mockBehaviourSubject;
        mockAlertService.busyStatus$ = mockBehaviourSubject;
        mockAlertService.successStatus$ = mockBehaviourSubject;

        mockClientService = sinon.createStubInstance(ClientService);

        TestBed.configureTestingModule({
            // TODO mock imports?
            imports: [FormsModule],
            declarations: [
                IssueIdentityComponent,
                MockTypeaheadDirective
            ],
            providers: [
                {provide: NgbActiveModal, useValue: mockActiveModal},
                {provide: AlertService, useValue: mockAlertService},
                {provide: ClientService, useValue: mockClientService}
            ]
        })
            .compileComponents();

        fixture = TestBed.createComponent(IssueIdentityComponent);
        component = fixture.componentInstance;
    });
开发者ID:marlonprudente,项目名称:composer,代码行数:30,代码来源:issue-identity.component.spec.ts


示例3: beforeEach

 beforeEach(() => {
     businessNetworkCardStore = new PlaygroundBusinessNetworkCardStore();
     mockBrowserBusinessNetworkCardStore = sinon.createStubInstance(BrowserBusinessNetworkCardStore);
     mockProxyBusinessNetworkCardStore = sinon.createStubInstance(ProxyBusinessNetworkCardStore);
     businessNetworkCardStore.browserBusinessNetworkCardStore = mockBrowserBusinessNetworkCardStore;
     businessNetworkCardStore.proxyBusinessNetworkCardStore = mockProxyBusinessNetworkCardStore;
 });
开发者ID:marlonprudente,项目名称:composer,代码行数:7,代码来源:playgroundbusinessnetworkcardstore.spec.ts


示例4: beforeEach

    beforeEach(async(() => {
        swUpdateStub = sinon.createStubInstance(SwUpdate);
        swUpdateStub.checkForUpdate.returns(new Promise((resolve) => resolve()));
        swUpdateStub.activateUpdate.returns(new Promise((resolve) => resolve()));
        swUpdateStub.available = updates;
        swUpdateStub.activated = activated;

        windowStub = sinon.createStubInstance(WindowRef);
        windowStub._window = {
            navigator: {
                userAgent: 'test'
            },
            location: {
                reload: () => { const sth = 1 + 1; }
            }
        };

        snackBarServiceStub = sinon.createStubInstance(SnackBarService);

        TestBed.configureTestingModule({
            declarations: [AppComponent],
            imports: [RouterTestingModule],
            providers: [
                {provide: WindowRef, useValue: windowStub},
                {provide: SwUpdate, useValue: swUpdateStub},
                {provide: SnackBarService, useValue: snackBarServiceStub}
            ],
            schemas: [ NO_ERRORS_SCHEMA ]
        });

        fixture = TestBed.createComponent(AppComponent);
        fixture.detectChanges();
    }));
开发者ID:yantrixs,项目名称:angular-universal-pwa,代码行数:33,代码来源:app.component.spec.ts


示例5: beforeEach

    beforeEach(() => {
        fixture = TestBed.createComponent(ViewTransactionComponent);
        component = fixture.componentInstance;

        mockEvent1 = sinon.createStubInstance(Resource);
        mockEvent1.getIdentifier.returns('event1');
        mockEvent2 = sinon.createStubInstance(Resource);
        mockEvent2.getIdentifier.returns('event2');

        mockTransaction = sinon.createStubInstance(Resource);
        mockTransaction.getIdentifier.returns('transaction');

        mockSerializer.toJSON.onFirstCall().returns({
            $class: 'mock.class',
            timestamp: 'now',
            transactionId: 'transaction'
        });

        mockSerializer.toJSON.onSecondCall().returns({
            $class: 'mock.event',
            timestamp: 'now',
            eventId: 'event1'
        });

        mockSerializer.toJSON.onThirdCall().returns({
            $class: 'mock.event',
            timestamp: 'now',
            eventId: 'event2'
        });
    });
开发者ID:bloonbullet,项目名称:composer,代码行数:30,代码来源:view-transaction.component.spec.ts


示例6: it

        it('should create a sorted list of participantFQIs', fakeAsync(() => {

            // Set up mocked/known items to test against
            let mockParticpantRegistry = sinon.createStubInstance(ParticipantRegisty);
            let mockParticipant1 = sinon.createStubInstance(Resource);
            mockParticipant1.getFullyQualifiedIdentifier.returns('org.doge.Doge#DOGE_1');
            let mockParticipant2 = sinon.createStubInstance(Resource);
            mockParticipant2.getFullyQualifiedIdentifier.returns('org.doge.Doge#DOGE_2');
            mockParticpantRegistry.getAll.returns([mockParticipant2, mockParticipant1]);
            mockBusinessNetworkConnection = sinon.createStubInstance(BusinessNetworkConnection);
            mockBusinessNetworkConnection.getAllParticipantRegistries.returns(Promise.resolve([mockParticpantRegistry]));
            mockClientService.getBusinessNetworkConnection.returns(mockBusinessNetworkConnection);

            // Starts Empty
            component['participantFQIs'].should.be.empty;

            // Run method
            component['loadParticipants']();

            tick();

            // Check we load the participants
            let expected = ['org.doge.Doge#DOGE_1', 'org.doge.Doge#DOGE_2'];
            component['participantFQIs'].should.deep.equal(expected);

        }));
开发者ID:bloonbullet,项目名称:composer,代码行数:26,代码来源:issue-identity.component.spec.ts


示例7: beforeEach

    beforeEach(() => {
        sandbox = sinon.sandbox.create();

        businessNetworkDefMock = sinon.createStubInstance(BusinessNetworkDefinition);
        adminMock = sinon.createStubInstance(AdminService);
        alertMock = sinon.createStubInstance(AlertService);
        connectionProfileMock = sinon.createStubInstance(ConnectionProfileService);
        identityMock = sinon.createStubInstance(IdentityService);
        businessNetworkConMock = sinon.createStubInstance(BusinessNetworkConnection);
        modelFileMock = sinon.createStubInstance(ModelFile);
        scriptFileMock = sinon.createStubInstance(Script);
        aclFileMock = sinon.createStubInstance(AclFile);
        queryFileMock = sinon.createStubInstance(QueryFile);

        alertMock.errorStatus$ = {next: sinon.stub()};
        alertMock.busyStatus$ = {next: sinon.stub()};

        TestBed.configureTestingModule({
            providers: [ClientService,
                {provide: AdminService, useValue: adminMock},
                {provide: AlertService, useValue: alertMock},
                {provide: ConnectionProfileService, useValue: connectionProfileMock},
                {provide: IdentityService, useValue: identityMock}]
        });
    });
开发者ID:GitWhiskey,项目名称:composer,代码行数:25,代码来源:client.service.spec.ts


示例8: beforeEach

    beforeEach(() => {
        mockActiveModal = sinon.createStubInstance(NgbActiveModal);
        mockIdentityCardService = sinon.createStubInstance(IdentityCardService);
        mockIdCard = sinon.createStubInstance(IdCard);
        mockIdCard.getBusinessNetworkName.returns('dan-net');
        mockConnectionProfile = {
            name: 'dan-profile'
        };
        mockIdCard.getConnectionProfile.returns(mockConnectionProfile);
        mockIdentityCardService.getCurrentIdentityCard.returns(mockIdCard);

        TestBed.configureTestingModule({
            imports: [FormsModule],
            declarations: [
                IdentityIssuedComponent,
                MockClipboardDirective,
                MockAccordionComponent,
                MockPanelComponent,
                MockIdentityCardComponent
            ],
            providers: [
                {provide: NgbActiveModal, useValue: mockActiveModal},
                {provide: IdentityCardService, useValue: mockIdentityCardService},
            ]
        });

        fixture = TestBed.createComponent(IdentityIssuedComponent);
        component = fixture.componentInstance;
    });
开发者ID:bloonbullet,项目名称:composer,代码行数:29,代码来源:identity-issued.component.spec.ts


示例9: spellStubs

	/**
	 * Creates a stubs for testing algorithms
	 * that make use of Spell.js dependency
	 * modules
	 * @returns {ISpellStubs}
	 */
	function spellStubs(): ISpellStubs {
		const spell = sinon.createStubInstance(Spell);
		const ell = sinon.createStubInstance(Ell);
		spell.ell = ell as any;
		const elld = sinon.createStubInstance(Elld);
		elld.getSpell.returns(spell);
		return { spell, ell, elld };
	}
开发者ID:,项目名称:,代码行数:14,代码来源:


示例10: beforeEach

        beforeEach(() => {
            mockModelFile = sinon.createStubInstance(ModelFile);
            mockModelFile.getName.returns('model.cto');
            mockClassDeclaration = sinon.createStubInstance(ClassDeclaration);
            mockClassDeclaration.getModelFile.returns(mockModelFile);
            mockClassDeclaration.getName.returns('class.declaration');
            mockClassDeclaration.getIdentifierFieldName.returns('resourceId');

        });
开发者ID:KlausSchwartz,项目名称:composer,代码行数:9,代码来源:resource.component.spec.ts


示例11: describe

    describe('modelNamespaceCollides', () => {

        let modelManagerMock;
        let mockCreateBusinessNetwork;
        let mockFile0 = sinon.createStubInstance(ModelFile);
        mockFile0.getNamespace.returns('name0');
        let mockFile1 = sinon.createStubInstance(ModelFile);
        mockFile1.getNamespace.returns('name1');
        let mockFile2 = sinon.createStubInstance(ModelFile);
        mockFile2.getNamespace.returns('name2');
        let mockFile3 = sinon.createStubInstance(ModelFile);
        mockFile3.getNamespace.returns('name3');
        let mockFile4 = sinon.createStubInstance(ModelFile);
        mockFile4.getNamespace.returns('name4');

        beforeEach(inject([ClientService], (service: ClientService) => {
            modelManagerMock = {
                getModelFiles: sinon.stub().returns([mockFile0, mockFile1, mockFile2, mockFile3, mockFile4])
            };

            businessNetworkDefMock.getModelManager.returns(modelManagerMock);
            sinon.stub(service, 'getBusinessNetwork').returns(businessNetworkDefMock);
            mockCreateBusinessNetwork = sinon.stub(service, 'createBusinessNetwork').returns(businessNetworkDefMock);
            service['currentBusinessNetwork'] = businessNetworkDefMock;
        }));

        it('should return true if namespace collision detected', inject([ClientService], (service: ClientService) => {

            let result = service.modelNamespaceCollides('name1', 'something-different');
            result.should.be.equal(true);

        }));

        it('should return false if no namespace collision detected with new name', inject([ClientService], (service: ClientService) => {

            let result = service.modelNamespaceCollides('not-in-list', 'something-different');
            result.should.be.equal(false);

        }));

        it('should handle no previousNamespace being passed', inject([ClientService], (service: ClientService) => {

            let result = service.modelNamespaceCollides('new-namespace', null);
            result.should.be.equal(false);

        }));

        it('should handle no model files existing in BND', inject([ClientService], (service: ClientService) => {
            modelManagerMock = {
                getModelFiles: sinon.stub().returns([])
            };

            let result = service.modelNamespaceCollides('not-in-list', 'something-different');
            result.should.be.equal(false);
        }));

    });
开发者ID:KlausSchwartz,项目名称:composer,代码行数:57,代码来源:client.service.spec.ts


示例12: beforeEach

    beforeEach(() => {
        mockFileWallet = sinon.createStubInstance(FileWallet);
        mockFileWallet.list.returns(Promise.resolve(['identity2', 'identity1']));

        mockFileWallets = sinon.createStubInstance(Map);

        TestBed.configureTestingModule({
            providers: [WalletService]
        });
    });
开发者ID:GitWhiskey,项目名称:composer,代码行数:10,代码来源:wallet.service.spec.ts


示例13: it

        it('should create a new business network and notify on success', inject([ClientService], (service: ClientService) => {
            let businessNetworkChangedSpy = sinon.spy(service.businessNetworkChanged$, 'next');
            let filterSpy = sinon.spy(service, 'filterModelFiles');

            let mockFile0 = sinon.createStubInstance(ModelFile);
            mockFile0.isSystemModelFile.returns(false);
            let mockFile1 = sinon.createStubInstance(ModelFile);
            mockFile1.isSystemModelFile.returns(false);
            let mockFile2 = sinon.createStubInstance(ModelFile);
            mockFile2.isSystemModelFile.returns(false);
            let mockFile3 = sinon.createStubInstance(ModelFile);
            mockFile3.isSystemModelFile.returns(false);
            let mockFile4 = sinon.createStubInstance(ModelFile);
            mockFile4.isSystemModelFile.returns(true);

            let modelManagerMock = {
                getModelFiles: sinon.stub().returns([mockFile0, mockFile1, mockFile2, mockFile3, mockFile4]),
                addModelFiles: sinon.stub()
            };

            let aclManagerMock = {
                setAclFile: sinon.stub(),
                getAclFile: sinon.stub().returns(aclFileMock)
            };

            let scriptManagerMock = {
                getScripts: sinon.stub().returns([scriptFileMock, scriptFileMock]),
                addScript: sinon.stub()
            };

            let queryManagerMock = {
                setQueryFile: sinon.stub(),
                getQueryFile: sinon.stub().returns(queryFileMock)
            };

            businessNetworkDefMock.getModelManager.returns(modelManagerMock);
            businessNetworkDefMock.getScriptManager.returns(scriptManagerMock);
            businessNetworkDefMock.getAclManager.returns(aclManagerMock);
            businessNetworkDefMock.getQueryManager.returns(queryManagerMock);

            sinon.stub(service, 'getBusinessNetwork').returns(businessNetworkDefMock);

            let mockCreateBusinessNetwork = sinon.stub(service, 'createBusinessNetwork').returns(businessNetworkDefMock);

            // Call function
            service.createNewBusinessNetwork('myBND', '1.0', 'description', '{}', null);

            // We filter system namespaces
            filterSpy.should.have.been.calledWith([mockFile0, mockFile1, mockFile2, mockFile3, mockFile4]);
            let filterReturn = filterSpy.returnValues[0];
            filterReturn.should.deep.equal([mockFile0, mockFile1, mockFile2, mockFile3]);

            // We alert on success
            businessNetworkChangedSpy.should.have.been.calledWith(true);
        }));
开发者ID:GitWhiskey,项目名称:composer,代码行数:55,代码来源:client.service.spec.ts


示例14: beforeEach

    beforeEach(() => {
        httpStub = sinon.createStubInstance(HttpClient);
        windowStub = sinon.createStubInstance(WindowRef);
        swPushStub = sinon.createStubInstance(SwPush);
        swPushStub.subscription = new BehaviorSubject(null);
        swPushStub.requestSubscription.returns(new Promise((resolve) => resolve(pushSubscription1)));

        windowStub._window = {navigator: {
            userAgent: 'test',
            serviceWorker: {}
        }};
    });
开发者ID:yantrixs,项目名称:angular-universal-pwa,代码行数:12,代码来源:notification.service.spec.ts


示例15: beforeEach

        beforeEach(() => {
            mockField = {
                getValidator: sinon.stub ().returns(null)
            };

            component['updateExistingJSON'] = sandbox.stub();
            mockModelFile = sinon.createStubInstance(ModelFile);
            mockModelFile.getName.returns('model.cto');
            mockClassDeclaration = sinon.createStubInstance(ClassDeclaration);
            mockClassDeclaration.getModelFile.returns(mockModelFile);
            mockClassDeclaration.getName.returns('class.declaration');
            mockClassDeclaration.getIdentifierFieldName.returns('resourceId');
            mockClassDeclaration.getProperty.returns(mockField);
        });
开发者ID:bloonbullet,项目名称:composer,代码行数:14,代码来源:resource.component.spec.ts


示例16: beforeEach

    beforeEach(() => {
        snackbarStub = sinon.createStubInstance(MatSnackBar);
        snackbarRefStub = sinon.createStubInstance(MatSnackBarRef);

        snackbarStub.open.returns(snackbarRefStub);
        snackbarRefStub.afterDismissed.returns(Observable.of(true));

        TestBed.configureTestingModule({
            providers: [
                {provide: MatSnackBar, useValue: snackbarStub},
                SnackBarService
            ]
        });
    });
开发者ID:yantrixs,项目名称:angular-universal-pwa,代码行数:14,代码来源:snack-bar.service.spec.ts


示例17: beforeEach

    beforeEach(async(() => {
        localStorageServiceMock = sinon.createStubInstance(LocalStorageService);
        identityCardServiceMock = sinon.createStubInstance(IdentityCardService);

        TestBed.configureTestingModule({
            declarations: [VersionCheckComponent],
            providers: [
                {provide: NgbActiveModal, useValue: ngbActiveModalMock},
                {provide: NgZone, useValue: new NgZone({})},
                {provide: LocalStorageService, useValue: localStorageServiceMock},
                {provide: IdentityCardService, useValue: identityCardServiceMock}
            ]
        }).compileComponents();
    }));
开发者ID:bloonbullet,项目名称:composer,代码行数:14,代码来源:version-check.component.spec.ts


示例18: beforeEach

    beforeEach(() => {
        mockIdentityCardStorageService = sinon.createStubInstance(IdentityCardStorageService);
        mockConnectionProfileService = sinon.createStubInstance(ConnectionProfileService);
        mockIdentityService = sinon.createStubInstance(IdentityService);
        mockWalletService = sinon.createStubInstance(WalletService);

        TestBed.configureTestingModule({
            providers: [IdentityCardService,
                {provide: IdentityCardStorageService, useValue: mockIdentityCardStorageService},
                {provide: ConnectionProfileService, useValue: mockConnectionProfileService},
                {provide: IdentityService, useValue: mockIdentityService},
                {provide: WalletService, useValue: mockWalletService}
            ]
        });
    });
开发者ID:GitWhiskey,项目名称:composer,代码行数:15,代码来源:identity-card.service.spec.ts


示例19: beforeEach

    beforeEach(() => {
        mockLocalStorageService = sinon.createStubInstance(LocalStorageService);
        mockConnectionProfileService = sinon.createStubInstance(ConnectionProfileService);
        mockWalletService = sinon.createStubInstance(WalletService);

        mockFileWallet = sinon.createStubInstance(FileWallet);
        mockFileWallet.list.returns(Promise.resolve(['identity2', 'identity1']));
        mockWalletService.getWallet.returns(mockFileWallet);

        TestBed.configureTestingModule({
            providers: [IdentityService,
                {provide: LocalStorageService, useValue: mockLocalStorageService},
                {provide: ConnectionProfileService, useValue: mockConnectionProfileService},
                {provide: WalletService, useValue: mockWalletService}]
        });
    });
开发者ID:GitWhiskey,项目名称:composer,代码行数:16,代码来源:identity.service.spec.ts


示例20: test

test('requests should be sequential', async () => {
  // @ts-ignore
  const proxyStub = sinon.createStubInstance(LanguageServerProxy, {
    handleRequest: sinon.stub().callsFake(() => {
      const start = Date.now();
      return new Promise(resolve => {
        setTimeout(() => {
          resolve({ result: { start, end: Date.now() } });
        }, 100);
      });
    }),
  });
  const expander = new RequestExpander(proxyStub, false, 1, options);
  const request1 = {
    method: 'request1',
    params: [],
  };
  const request2 = {
    method: 'request2',
    params: [],
  };
  const response1Promise = expander.handleRequest(request1);
  const response2Promise = expander.handleRequest(request2);
  const response1 = await response1Promise;
  const response2 = await response2Promise;
  // response2 should not be started before response1 ends.
  expect(response1.result.end).toBeLessThanOrEqual(response2.result.start);
});
开发者ID:elastic,项目名称:kibana,代码行数:28,代码来源:request_expander.test.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Sinon.fake函数代码示例发布时间:2022-05-25
下一篇:
TypeScript Sinon.createSandbox函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap