How to use @tsed/testing - 10 common examples

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
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 / 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 / examples / aws / src / services / storage / MemoryStorage.spec.ts View on Github external
describe("get()", () => {
    it("should return value stored in memoryStorage", inject([MemoryStorage], (memoryStorage: MemoryStorage) => {
      // GIVEN
      memoryStorage.set("key", "value");

      // WHEN
      memoryStorage.get("key").should.eq("value");
    }));
  });
});
github TypedProject / ts-express-decorators / examples / getting-started / src / services / calendars / CalendarsService.spec.ts View on Github external
it("should get the service from InjectorService", async () => {
      // GIVEN
      const memoryStorage = {
        set: () => {
        },
        get: () => {
        }
      };

      // WHEN
      const calendarsService: CalendarsService = await TestContext.invoke(CalendarsService, [
        {provide: MemoryStorage, use: memoryStorage}
      ]);

      // THEN
      expect(calendarsService).to.be.an.instanceof(CalendarsService);
      // @ts-ignore
      expect(calendarsService.memoryStorage).to.equal(memoryStorage);
    });
  });
github TypedProject / ts-express-decorators / examples / passportjs / src / services / calendars / CalendarsService.spec.ts View on Github external
it("should invoke a calendarService with a fake memoryStorage", () => {
      // GIVEN
      const memoryStorage = {
        set: () => {
        },
        get: () => {
        }
      };

      // WHEN
      const calendarsService = TestContext.invoke(CalendarsService, [
        {provide: MemoryStorage, use: memoryStorage}
      ]);

      // THEN
      expect(calendarsService.memoryStorage).to.equal(memoryStorage);
      expect(calendarsService).to.be.an.instanceof(CalendarsService);
    });
  });
github TypedProject / ts-express-decorators / examples / aws / src / controllers / calendars / CalendarsCtrl.spec.ts View on Github external
it("should return a result from mocked service", async () => {
          // GIVEN
          const calendarsService = {
            find: Sinon.stub().rejects({id: "1"})
          };

          const calendarsCtrl = await TestContext.invoke(CalendarsCtrl, [{
            provide: CalendarsService,
            use: calendarsService
          }]);

          // WHEN
          let actualError;
          try {
            await calendarsCtrl.get("1");
          } catch (er) {
            actualError = er;
          }

          // THEN
          actualError.should.be.instanceof(NotFound);
          calendarsService.find.should.be.calledWithExactly("1");
        });
github TypedProject / ts-express-decorators / examples / getting-started / src / controllers / calendars / CalendarsCtrl.spec.ts View on Github external
it("should return a result from mocked service", async () => {
        // GIVEN
        const calendarsService = {
          find: Sinon.stub().resolves({id: "1"})
        };

        const calendarsCtrl = await TestContext.invoke(CalendarsCtrl, [{
          provide: CalendarsService,
          use: calendarsService
        }]);

        // WHEN
        const result = await calendarsCtrl.get("1");

        // THEN
        result.should.deep.equal({id: "1"});
        calendarsService.find.should.be.calledWithExactly("1");

        calendarsCtrl.should.be.an.instanceof(CalendarsCtrl);
        calendarsCtrl.calendarsService.should.deep.equal(calendarsService);
      });
    });
github TypedProject / ts-express-decorators / examples / passportjs / src / controllers / calendars / CalendarCtrl.spec.ts View on Github external
it("should return the expected result", () => {
      // GIVEN
      const calendarsService = {
        find: Sinon.stub().returns(Promise.resolve({id: "1"}))
      };

      const calendarController = TestContext.invoke(CalendarCtrl, [
        {provide: CalendarsService, use: calendarsService}
      ]);

      // WHEN
      const result = calendarController.get("1");

      // THEN
      result.should.eventually.deep.equal({id: "1"});
      calendarsService.find.should.be.calledWithExactly("1");
      expect(calendarController.calendarsService).to.equal(calendarsService);
    });
  });
github TypedProject / ts-express-decorators / examples / getting-started / src / middlewares / CheckCalendarIdMiddleware.spec.ts View on Github external
it("should throw an error", async () => {
      // GIVEN
      const calendarsService = {
        find: Sinon.stub().resolves()
      };

      const middleware: CheckCalendarIdMiddleware = await TestContext.invoke(CheckCalendarIdMiddleware, [{
        provide: CalendarsService,
        use: calendarsService
      }]);

      // WHEN
      let actualError;
      try {
        await middleware.use("1");
      } catch (er) {
        actualError = er;
      }
      // THEN
      // @ts-ignore
      calendarsService.find.should.be.calledWithExactly("1");
      actualError.should.instanceOf(NotFound);
      actualError.message.should.eq("Calendar not found");
github TypedProject / ts-express-decorators / examples / getting-started / src / controllers / events / EventsCtrl.spec.ts View on Github external
it("should return a result from mocked service", async () => {
      // GIVEN
      const eventsCtrl: EventsCtrl = await TestContext.invoke(EventsCtrl, []);
      const calendarId = "2";
      const startDate = "startDate";
      const endDate = "endDate";
      const name = "name";
      const id = "7";

      // WHEN
      const result = await eventsCtrl.update(calendarId, id, startDate, endDate, name);

      // THEN
      result.should.deep.equal({
        "calendarId": "2",
        "endDate": "name",
        "id": "7",
        "name": "name",
        "startDate": "name",

@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