How to use the @tsed/testing.TestContext.invoke 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
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 / 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",
github TypedProject / ts-express-decorators / examples / aws / src / services / calendars / CalendarsService.spec.ts View on Github external
it("should get the service from InjectorService", async () => {
      // GIVEN
      const memoryStorage = {
        set: () => {
        },
        get: () => {
        }
      };

      const locals = new Map();
      locals.set(MemoryStorage, memoryStorage);

      // 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 / test / units / socketio / services / SocketIOService.spec.ts View on Github external
before(async () => {
        await TestContext.create();
        this.socketIOServer = {attach: Sinon.stub(), adapter: Sinon.stub()};
        this.httpServer = {type: "http", get: Sinon.stub().returns("httpServer")};
        this.httpsServer = {type: "https", get: Sinon.stub().returns("httpsServer")};

        socketIOService = TestContext.invoke(SocketIOService, [
          {provide: HttpServer, use: this.httpServer},
          {provide: HttpsServer, use: this.httpsServer},
          {provide: SocketIOServer, use: this.socketIOServer}
        ]);

        this.getWebsocketServicesStub = Sinon.stub(socketIOService, "getWebsocketServices");
        this.bindProviderStub = Sinon.stub(socketIOService, "bindProvider");
        this.printSocketEventsStub = Sinon.stub(socketIOService, "printSocketEvents");

        this.getWebsocketServicesStub.returns([{provider: "provider"}]);

        socketIOService.serverSettingsService.set("socketIO", {config: "config", adapter: "adapter"});
        socketIOService.$onServerReady();
      });
      after(() => {

@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