How to use the sinon.createStubInstance function in sinon

To help you get started, we’ve selected a few sinon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github accordproject / concerto / test / serializer / jsonpopulator.js View on Github external
it('should create a new relationship from an array of objects if permitted', () => {
            jsonPopulator = new JSONPopulator(true); // true to enable acceptResourcesForRelationships
            let options = {
                jsonStack: new TypedStack([{
                    $class: 'org.acme.MyAsset1',
                    assetId: 'asset1'
                }, {
                    $class: 'org.acme.MyAsset1',
                    assetId: 'asset2'
                }]),
                resourceStack: new TypedStack({}),
                factory: mockFactory,
                modelManager: modelManager
            };
            let mockResource1 = sinon.createStubInstance(Resource);
            mockFactory.newResource.withArgs('org.acme', 'MyAsset1', 'asset1').returns(mockResource1);
            let mockResource2 = sinon.createStubInstance(Resource);
            mockFactory.newResource.withArgs('org.acme', 'MyAsset1', 'asset2').returns(mockResource2);
            let subResources = jsonPopulator.visitRelationshipDeclaration(relationshipDeclaration2, options);
            subResources.should.have.length.of(2);
            subResources[0].should.be.an.instanceOf(Resource);
            subResources[1].should.be.an.instanceOf(Resource);
        });
github accordproject / concerto / packages / composer-playground / src / app / services / file.service.spec.ts View on Github external
it('should validate a given query file', fakeAsync(inject([FileService], (fileService: FileService) => {
            let id = '1';
            let type = 'query';

            let testScripts = new Map();
            let testModels = new Map();

            fileService['currentBusinessNetwork'] = businessNetworkDefMock;

            let mockQueryFile = sinon.createStubInstance(EditorFile);
            mockQueryFile.validate.returns(null);

            // cases to throw if validation slips in to incorrect case.

            let mockScriptFile = sinon.createStubInstance(EditorFile);
            mockScriptFile.validate.throws('should not be called');

            let mockAclFile = sinon.createStubInstance(EditorFile);
            mockAclFile.validate.throws('should not be called');

            let mockModelFile = sinon.createStubInstance(EditorFile);
            mockModelFile.validate.throws('should not be called');

            testModels.set('1', mockModelFile);
            testScripts.set('1', mockScriptFile);

            fileService['modelFiles'] = testModels;
            fileService['scriptFiles'] = testScripts;
            fileService['aclFile'] = mockAclFile;
            fileService['queryFile'] = mockQueryFile;
github LeanKit-Labs / seriate / spec / unit / TransactionContext-Success.spec.js View on Github external
// mssql Request Stub & callback execution setup
		reqStub = sinon.createStubInstance( sql.Request );
		reqStub.query.callsArgWith( 1, null, records );
		reqStub.execute.callsArgWith( 1, null, records );

		// mssql Connection Stub
		connStub = sinon.createStubInstance( sql.Connection );

		// mssql PreparedStatement Stub & callback execution setup
		prepStub = sinon.createStubInstance( sql.PreparedStatement );
		prepStub.prepare.callsArgWith( 1, null );
		prepStub.execute.callsArgWith( 1, null, records );
		prepStub.unprepare.callsArgWith( 0, null );

		// mssql Transaction Stub & callback execution setup
		tranStub = sinon.createStubInstance( sql.Transaction );
		tranStub.begin.callsArgWith( 0, null );
		tranStub.commit.callsArgWith( 0, null );
		tranStub.rollback.callsArgWith( 0, null );

		// Now that we have stub instances, we need to stub
		// the calls to the constructor functions to return
		// our stubs instead
		sinon.stub( sql, "Connection", function( opt, fn ) {
			process.nextTick( fn );
			return connStub;
		} );

		sinon.stub( sql, "Request", function() {
			return reqStub;
		} );
github accordproject / concerto / test / webconnection.js View on Github external
it('should call the engine invoke method', () => {
            let mockDataService = sinon.createStubInstance(DataService);
            let mockContainer = sinon.createStubInstance(WebContainer);
            mockContainer.getDataService.returns(mockDataService);
            let mockEngine = sinon.createStubInstance(Engine);
            mockEngine.getContainer.returns(mockContainer);
            WebConnection.addBusinessNetwork('org.acme.Business', 'devFabric1', '6eeb8858-eced-4a32-b1cd-2491f1e3718f');
            WebConnection.addChaincode('6eeb8858-eced-4a32-b1cd-2491f1e3718f', mockContainer, mockEngine);
            mockSecurityContext.getChaincodeID.returns('6eeb8858-eced-4a32-b1cd-2491f1e3718f');
            mockEngine.invoke.resolves({ test: 'data from engine' });
            return connection.invokeChainCode(mockSecurityContext, 'testFunction', ['arg1', 'arg2'])
                .then((result) => {
                    sinon.assert.calledOnce(mockEngine.invoke);
                    sinon.assert.calledWith(mockEngine.invoke, sinon.match.instanceOf(Context), 'testFunction', ['arg1', 'arg2']);
                    should.equal(result, undefined);
                });
        });
github accordproject / concerto / test / engine.resources.js View on Github external
it('should add the specified resources', () => {
            let mockResource1 = sinon.createStubInstance(Resource);
            let mockResource2 = sinon.createStubInstance(Resource);
            mockRegistry.addAll.withArgs([mockResource1, mockResource2]).resolves();
            mockSerializer.fromJSON.withArgs({
                $class: 'org.doge.Doge',
                assetId: 'doge1'
            }).returns(mockResource1);
            mockSerializer.fromJSON.withArgs({
                $class: 'org.doge.Doge',
                assetId: 'doge2'
            }).returns(mockResource2);
            return engine.invoke(mockContext, 'addAllResourcesToRegistry', ['Asset', 'doges', JSON.stringify([
                {
                    $class: 'org.doge.Doge',
                    assetId: 'doge1'
                },
                {
github accordproject / concerto / test / engine.resources.js View on Github external
beforeEach(() => {
        mockContainer = sinon.createStubInstance(Container);
        mockLoggingService = sinon.createStubInstance(LoggingService);
        mockContainer.getLoggingService.returns(mockLoggingService);
        mockContext = sinon.createStubInstance(Context);
        mockContext.initialize.resolves();
        mockRegistryManager = sinon.createStubInstance(RegistryManager);
        mockRegistry = sinon.createStubInstance(Registry);
        mockRegistryManager.get.withArgs('Asset', 'doges').resolves(mockRegistry);
        mockContext.getRegistryManager.returns(mockRegistryManager);
        mockSerializer = sinon.createStubInstance(Serializer);
        mockContext.getSerializer.returns(mockSerializer);
        mockResolver = sinon.createStubInstance(Resolver);
        mockContext.getResolver.returns(mockResolver);
        mockQueryExecutor = sinon.createStubInstance(QueryExecutor);
        mockContext.getQueryExecutor.returns(mockQueryExecutor);
        engine = new Engine(mockContainer);
    });
github TryGhost / Ghost-CLI / test / unit / commands / setup-spec.js View on Github external
function getTasks(stubs = {}, steps = []) {
            const Command = proxyquire(modulePath, stubs);
            const ui = sinon.createStubInstance(UI);
            const system = sinon.createStubInstance(System);
            const setup = new Command(ui, system);
            ui.confirm.resolves(false);

            const tasks = setup.tasks(steps);
            return {tasks, ui, system, setup};
        }
github accordproject / concerto / packages / composer-playground / src / app / basic-modals / replace-confirm / replace-confirm.component.spec.ts View on Github external
describe('ReplaceComponent', () => {
    let component: TestHostComponent;
    let fixture: ComponentFixture;

    let mockActiveModal = sinon.createStubInstance(NgbActiveModal);

    let replaceElement: DebugElement;

    beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [ReplaceComponent, TestHostComponent],
            providers: [{provide: NgbActiveModal, useValue: mockActiveModal}]
        });
        fixture = TestBed.createComponent(TestHostComponent);
        component = fixture.componentInstance;

        replaceElement = fixture.debugElement.query(By.css('replace-confirm'));
    });

    it('should create', () => {
        component.should.be.ok;
github accordproject / concerto / packages / composer-playground / src / app / services / identity-card.service.spec.ts View on Github external
beforeEach(() => {
            mockConnectionProfile1 = {name: 'myProfile'};
            mockIdCard1 = sinon.createStubInstance(IdCard);
            mockIdCard1.getUserName.returns('card1');
            mockIdCard1.getConnectionProfile.returns(mockConnectionProfile1);
            mockIdCard1.getRoles.returns(['myRole']);

            mockConnectionProfile2 = {name: 'myOtherProfile'};
            mockIdCard2 = sinon.createStubInstance(IdCard);
            mockIdCard2.getUserName.returns('card2');
            mockIdCard2.getConnectionProfile.returns(mockConnectionProfile2);
            mockIdCard2.getRoles.returns(['myOtherRole']);

            mockConnectionProfile3 = {name: 'myProfile'};
            mockIdCard3 = sinon.createStubInstance(IdCard);
            mockIdCard3.getUserName.returns('card3');
            mockIdCard3.getConnectionProfile.returns(mockConnectionProfile3);
            mockIdCard3.getRoles.returns(['myRole']);

            mockCardMap = new Map();
            mockCardMap.set('uuid1xxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', mockIdCard1);
            mockCardMap.set('uuid2xxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', mockIdCard2);
            mockCardMap.set('uuid3xxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', mockIdCard3);
        });