本文整理匯總了TypeScript中@tsed/testing.TestContext類的典型用法代碼示例。如果您正苦於以下問題:TypeScript TestContext類的具體用法?TypeScript TestContext怎麽用?TypeScript TestContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TestContext類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe("Calendars", () => {
// bootstrap your expressApplication in first
before(TestContext.bootstrap(Server));
before(TestContext.inject([ExpressApplication], (expressApplication: ExpressApplication) => {
this.app = expressApplication;
}));
after(TestContext.reset);
// then run your test
describe("GET /rest/calendars", () => {
it("should return all calendars", (done) => {
SuperTest(this.app)
.get("/rest/calendars")
.expect(200)
.end((err, response: any) => {
if (err) {
throw (err);
}
let obj = JSON.parse(response.text);
expect(obj).to.be.an("array");
done();
});
});
});
});
示例2: describe
describe("Upload", () => {
// bootstrap the express application
before(TestContext.bootstrap(Server));
before(TestContext.inject([ExpressApplication], (expressApplication: ExpressApplication) => {
this.app = expressApplication;
}));
after(TestContext.reset);
describe("PUT /rest/upload", () => { // work if you enable the MultipartFileMiddlewareOverrided ;)
it("should return 400", (done) => {
SuperTest(this.app)
.put("/rest/upload")
.attach("file", Path.join(__dirname, "/test.txt"))
.expect(400)
.end((err, res: any) => {
if (err) {
throw (err);
}
expect(res.text).to.eq("This should be thrown and seen on the test failure.");
done();
});
});
});
});
示例3: it
it("should call attach method", inject([ServerSettingsService], async (serverSettingsService: ServerSettingsService) => {
// GIVEN
const socketIOServer = {attach: Sinon.stub(), adapter: Sinon.stub()};
const httpServer = {type: "http", get: Sinon.stub().returns("httpServer")};
const httpsServer = {type: "https", get: Sinon.stub().returns("httpsServer")};
const socketIOService = {addSocketProvider: Sinon.stub()};
serverSettingsService.set("socketIO", {config: "config"});
serverSettingsService.set("http", false);
const socketIOModule = TestContext.invoke(SocketIOModule, [
{provide: HttpServer, use: httpServer},
{provide: HttpsServer, use: httpsServer},
{provide: SocketIOServer, use: socketIOServer},
{provide: SocketIOService, use: socketIOService}
]);
this.getWebsocketServicesStub.returns([{provider: "provider"}]);
// WHEN
await socketIOModule.$onServerReady();
socketIOServer.attach.should.have.been.calledWithExactly(httpsServer, {
config: "config"
});
this.getWebsocketServicesStub.should.have.been.calledWithExactly();
socketIOService.addSocketProvider.should.have.been.calledWithExactly({provider: "provider"});
}));
示例4: after
after(() => {
TestContext.reset();
sandbox.restore();
});
示例5: after
after(() => {
TestContext.reset();
this.getWebsocketServicesStub.restore();
this.printSocketEventsStub.restore();
});
示例6: after
after(() => {
TestContext.reset();
this.connectStub.restore();
});
示例7: inject
inject([ServerSettingsService], (settings: ServerSettingsService) => {
settings.set("typeorm", {});
this.createConnectionStub.restore();
TestContext.reset();
})