How to use the @tsed/testing.bootstrap function in @tsed/testing

To help you get started, we’ve selected a few @tsed/testing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / test / integration / testing-example.spec.ts View on Github external
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");
github TypedProject / ts-express-decorators / test / integration / swagger.spec.ts View on Github external
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", () => {
github TypedProject / ts-express-decorators / test / integration / response.spec.ts View on Github external
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");
      });
    });
  });
github TypedProject / ts-express-decorators / test / units / testing / bootstrap.spec.ts View on Github external
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");
  });
github TypedProject / ts-express-decorators / test / integration / di.spec.ts View on Github external
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);
    })();
  });

@tsed/testing

A TypeScript Framework on top of Express

MIT
Latest version published 4 years ago

Package Health Score

62 / 100
Full package analysis

Similar packages