Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe("Mock dependencies", () => {
// bootstrap your Server to load all endpoints before run your test
before(bootstrap(FakeServer));
after(TestContext.reset);
it("should do something", async () => {
// give the locals map to the invoke method
const instance: MyCtrl = await TestContext.invoke(MyCtrl, [{
provide: DbService,
use: {
getData: () => {
return "test";
}
}
}]);
// and test it
expect(!!instance).to.eq(true);
expect(instance.getData()).to.equals("test");
describe("Swagger", () => {
let request: SuperTest.SuperTest;
before(bootstrap(FakeServer));
before(inject([ExpressApplication], (expressApplication: ExpressApplication) => (request = SuperTest(expressApplication))));
after(TestContext.reset);
describe("GET /api-doc/swagger.json", () => {
let spec: any;
before(done => {
request
.get("/api-doc/swagger.json")
.expect(200)
.end((err: any, response: any) => {
spec = JSON.parse(response.text);
done();
});
});
it("should have a swagger version", () => {
describe("Response", () => {
let request: SuperTest.SuperTest;
before(bootstrap(FakeServer));
before(
inject([ExpressApplication], (expressApplication: ExpressApplication) => {
request = SuperTest(expressApplication);
})
);
after(TestContext.reset);
describe("Scenario1: when multiple endpoint for the same path (classic)", () => {
describe("GET /rest/response/scenario1/:id", () => {
it("should return the id + test", async () => {
const response = await request.get("/rest/response/scenario1/10").expect(200);
response.text.should.be.equal("10value");
});
});
});
describe("bootstrap()", () => {
const fn = bootstrap(FakeServer);
beforeEach(fn);
afterEach(TestContext.reset);
it("should return before function", () => {
expect(fn).to.be.a("function");
});
it("should return promise after executing the function", () => {
expect(fn()).instanceOf(Promise);
});
it("should attach injector instance to TestContext", () => {
expect(TestContext.injector).to.eq("Injector");
});
before(async () => {
await bootstrap(FakeServer)();
await inject([InjectorService], (injector: InjectorService) => {
this.locals = new Map();
const provider = injector.getProvider(ProductsCtrl)!;
const target = provider.useClass;
this.rebuildHandler = provider.scope !== ProviderScope.SINGLETON;
this.instance = injector.invoke(target, this.locals, undefined, true);
})();
});