本文整理匯總了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();
});
}));
});
示例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);
}))
})
示例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);
}
});
}))
})
示例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();
}))
})
示例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: ''
});
}));
});