當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Sinon.test函數代碼示例

本文整理匯總了TypeScript中Sinon.test函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript test函數的具體用法?TypeScript test怎麽用?TypeScript test使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了test函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

    describe("update", () => {
        it("Success", sinon.test(function (done: any): any {
            // Assemble
            let user: User = TestObjects.user;
            this.stub(MongooseRepository.prototype, "update")
                .returns(Promise.resolve<Array<User>>([user]));

            // Act
            _userCont.updateUser(user)
                .then(res => {
                    // Assert
                    expect(res.username).to.be.eql(user.username);
                    expect(res.mobile_number).to.be.eql(user.mobile_number);

                    done();
                });
        }));

        it("randomError_Throws", sinon.test(function (done: any): any {
            // Assemble
            this.stub(MongooseRepository.prototype, "update")
                .throws(new APIError("Random error happened"));

            // Act
            _userCont.updateUser(TestObjects.user)
                .catch(res => {
                    // Assert
                    expect(res).to.be.an.instanceof(APIError);
                    expect(res.message.toString()).to.be.equal("APIError: Random error happened");

                    done();
                });
        }));
    });
開發者ID:abnoba12,項目名稱:codeSnippets,代碼行數:34,代碼來源:unitTest.example.ts

示例2: context

    context("checkFileType", function () {
        it("should return false if active doc is not JSON", sinon.test(function () {
            let docIsJSONStub = this.stub(utilities, "docIsJSON", () => { return false });
            let result = utilities.checkFileType();
            sinon.assert.calledOnce(docIsJSONStub);
            expect(result).to.equal(false);
        }))
        it("should return false if active JSON doc is not a valid manifest", sinon.test(function () {
            let docIsJSONStub = this.stub(utilities, "docIsJSON", () => { return true });
            let checkExtensionTypeStub = this.stub(utilities, "checkExtensionType", () => { return false });
            let result = utilities.checkFileType();
            sinon.assert.calledOnce(docIsJSONStub);
            sinon.assert.calledOnce(checkExtensionTypeStub);
            expect(result).to.equal(false);
        }))
        it("should return true on a valid manifest", sinon.test(function () {
            let docIsJSONStub = this.stub(utilities, "docIsJSON", () => { return true });
            let checkExtensionTypeStub = this.stub(utilities, "checkExtensionType", () => { return true });
            let result = utilities.checkFileType();
            sinon.assert.calledOnce(docIsJSONStub);
            sinon.assert.calledOnce(checkExtensionTypeStub);
            expect(result).to.equal(true);

        }))
    })
開發者ID:Microsoft,項目名稱:extension-manifest-editor,代碼行數:25,代碼來源:Utilities.test.ts

示例3: context

    context("generatePreview", function () {
        it("should return error on empty manifest", sinon.test(function () {
            
            let makePreviewSpy = this.spy(previewManager,"makePreview");
            let getManifestSpy = this.spy(previewManager,"getManifest");
            let isActiveStub = this.stub(previewManager.utilities, "isActive", function () { return false }); 
            previewManager.generatePreview().then(function (data) {

                expect(data).to.equal(ErrorMessages.NO_MANIFEST);
                sinon.assert.calledOnce(getManifestSpy);
                sinon.assert.calledOnce(makePreviewSpy);
                
            })
        }))
        it("should call getManifest then getReadMe", sinon.test(function () {

            let isActiveStub = this.stub(previewManager.utilities, "isActive", function () { return true });
            let deserializeJSONSpy = this.spy(previewManager, "deserializeJSON");
            let getReadMeStub = this.stub(previewManager, "getReadMe", function () { return ""; });
            previewManager.generatePreview().then(function () {
                try {
                    sinon.assert.calledOnce(isActiveStub);
                    sinon.assert.calledOnce(deserializeJSONSpy);
                    sinon.assert.calledOnce(getReadMeStub);
                }
                catch (error) {
                    console.log(error);
                }
            });
        }))
    })
開發者ID:Microsoft,項目名稱:extension-manifest-editor,代碼行數:31,代碼來源:TestPreviewManager.ts

示例4: context

    context("constructor", function () {

        it("should assign previewManager to previewManagerVSC ", sinon.test(function () {

            let checkExtensionTypeStub = this.stub(utilities, "checkExtensionType", function () {
                ExtensionConstants.EXTENSION_TYPE = ExtensionConstants.VSC_EXTENSION;
                return true;
            })

            let previewManagerVSCStub = sinon.createStubInstance(dummyPreviewManager);
            let previewManagerVSTSStub = this.stub();
            previewManagerController = new PreviewManagerController(utilities, previewManagerVSCStub, previewManagerVSTSStub);

            sinon.assert.calledOnce(checkExtensionTypeStub);
            sinon.assert.calledOnce(previewManagerVSCStub.generatePreview);
            expect(previewManagerController.previewManager).to.equal(previewManagerVSCStub);

        }))
        it("should assign previewManager to previewManagerVSTS ", sinon.test(function () {

            let checkExtensionTypeStub = this.stub(utilities, "checkExtensionType", function () {
                ExtensionConstants.EXTENSION_TYPE = ExtensionConstants.VSTS_EXTENSION;
                return true;
            })

            let previewManagerVSCStub = this.stub();
            let previewManagerVSTSStub = sinon.createStubInstance(dummyPreviewManager);
            previewManagerController = new PreviewManagerController(utilities, previewManagerVSCStub, previewManagerVSTSStub);

            sinon.assert.calledOnce(checkExtensionTypeStub);
            sinon.assert.calledOnce(previewManagerVSTSStub.generatePreview);
            expect(previewManagerController.previewManager).to.equal(previewManagerVSTSStub);

        }))
        it("should not assign previewManager ", sinon.test(function () {
            let checkExtensionTypeStub = this.stub(utilities, "checkExtensionType", function () {

                return false;
            })

            let previewManagerStub = sinon.createStubInstance(dummyPreviewManager);
            previewManagerController = new PreviewManagerController(utilities, previewManagerStub, previewManagerStub);

            sinon.assert.calledOnce(checkExtensionTypeStub);
            sinon.assert.notCalled(previewManagerStub.generatePreview);
            expect(previewManagerController.previewManager).to.equal();
        }))
    })
開發者ID:Microsoft,項目名稱:extension-manifest-editor,代碼行數:48,代碼來源:PreviewManagerController.test.ts

示例5: describe

describe('EmbeddedDocument Annotation', function() {

    class TestClass {
    }

    // -------------------------------------------------------------------------
    // Specifications
    // -------------------------------------------------------------------------

    it('should throw exception if annotation is set to a non constructor object', function () {
        expect(() => EmbeddedDocument()(null)).to.throw(WrongAnnotationUsageError);
        expect(() => EmbeddedDocument()(function() {})).to.throw(WrongAnnotationUsageError);
    });

    it('should add a new document metadata to the metadata storage', sinon.test(function () {
        var addDocumentMetadata = this.mock(defaultMetadataStorage).expects('addDocumentMetadata');

        let object = new TestClass();
        EmbeddedDocument()(object.constructor);
        addDocumentMetadata.should.have.been.calledWith({
            objectConstructor: object.constructor,
            name: ''
        });
    }));

});
開發者ID:mweels,項目名稱:typeodm,代碼行數:26,代碼來源:EmbeddedDocumentSpec.ts


注:本文中的Sinon.test函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。