本文整理匯總了TypeScript中Sinon.createStubInstance函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createStubInstance函數的具體用法?TypeScript createStubInstance怎麽用?TypeScript createStubInstance使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了createStubInstance函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
});
示例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;
});
示例3: beforeEach
beforeEach(() => {
businessNetworkCardStore = new PlaygroundBusinessNetworkCardStore();
mockBrowserBusinessNetworkCardStore = sinon.createStubInstance(BrowserBusinessNetworkCardStore);
mockProxyBusinessNetworkCardStore = sinon.createStubInstance(ProxyBusinessNetworkCardStore);
businessNetworkCardStore.browserBusinessNetworkCardStore = mockBrowserBusinessNetworkCardStore;
businessNetworkCardStore.proxyBusinessNetworkCardStore = mockProxyBusinessNetworkCardStore;
});
示例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();
}));
示例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'
});
});
示例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);
}));
示例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}]
});
});
示例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;
});
示例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 };
}
示例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');
});
示例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);
}));
});
示例12: beforeEach
beforeEach(() => {
mockFileWallet = sinon.createStubInstance(FileWallet);
mockFileWallet.list.returns(Promise.resolve(['identity2', 'identity1']));
mockFileWallets = sinon.createStubInstance(Map);
TestBed.configureTestingModule({
providers: [WalletService]
});
});
示例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);
}));
示例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: {}
}};
});
示例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);
});