本文整理汇总了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: ''
});
}));
});