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