How to use the @tsed/testing.inject 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 / 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 / test / units / swagger / SwaggerModule.spec.ts View on Github external
describe("SwaggerModule", () => {
  before(
    inject(
      [SwaggerModule, ServerSettingsService, ExpressApplication],
      (swaggerModule: SwaggerModule, serverSettingsService: ServerSettingsService, expressApp: ExpressApplication) => {
        this.swaggerModule = swaggerModule;
        this.settingsService = serverSettingsService;
        this.expressApp = expressApp;
      }
    )
  );

  describe("$afterRoutesInit()", () => {
    before(() => {
      this.config = [
        {
          path: "/doc1",
          doc: "doc1",
          options: "options",
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", () => {
      expect(spec.swagger).to.be.eq("2.0");
github TypedProject / ts-express-decorators / test / units / swagger / services / SwaggerService.spec.ts View on Github external
describe("SwaggerService", () => {
  before(
    inject([SwaggerService, ServerSettingsService], (swaggerService: SwaggerService, serverSettingsService: ServerSettingsService) => {
      this.swaggerService = swaggerService;
      this.settingsService = serverSettingsService;
    })
  );

  describe("getDefaultSpec()", () => {
    describe("when specPath is given", () => {
      before(() => {
        return (this.result = this.swaggerService.getDefaultSpec({specPath: __dirname + "/data/spec.json"}));
      });

      it("should return default spec", () => {
        this.result.should.be.deep.equals(require("./data/spec.expected.json"));
      });
    });
github TypedProject / ts-express-decorators / test / units / multipartfiles / filters / MultipartFileFilter.spec.ts View on Github external
describe("MultipartFileFilter", () => {
  before(
    inject([MultipartFileFilter], (filter: MultipartFileFilter) => {
      this.filter = filter;
    })
  );

  describe("transform()", () => {
    before(() => {
      this.result = this.filter.transform("", {files: [{}]});
    });

    it("should transform expression", () => {
      expect(this.result).to.be.an("object");
    });
  });
});
github TypedProject / ts-express-decorators / test / units / filters / components / QueryParamsFilter.spec.ts View on Github external
describe("QueryParamsFilter", () => {
  before(
    inject([QueryParamsFilter], (filter: QueryParamsFilter) => {
      this.filter = filter;
    })
  );

  describe("transform()", () => {
    before(() => {
      this.result = this.filter.transform("test", {query: {test: "test"}});
    });

    it("should transform expression", () => {
      expect(this.result).to.equal("test");
    });
  });
});
github TypedProject / ts-express-decorators / test / units / mongoose / services / MongooseService.spec.ts View on Github external
{options: "options"}
          )
          .then(() => {
            this.result = mongooseService.connect(
              "key",
              "mongodb://test",
              {options: "options"}
            );

            return this.result;
          });
      })
    );

    after(
      inject([ServerSettingsService], (serverSetttings: ServerSettingsService) => {
        serverSetttings.set("mongoose", {
          url: undefined,
          connectionOptions: undefined,
          urls: undefined
        });
        this.connectStub.restore();
      })
    );

    it("should call mongoose.connect", () => {
      this.connectStub.should.have.been.calledOnce;
      this.connectStub.should.have.been.calledWithExactly("mongodb://test", {options: "options"});
    });

    it("should return the instance of mongoose", () => {
      return this.result.should.eventually.eq("mongooseinstance");
github TypedProject / ts-express-decorators / test / units / converters / services / ConverterService.spec.ts View on Github external
describe("object", () => {
      it("should convert object", () => {
        expect(this.converterService.deserialize({}, Object)).to.be.an("object");
      });

      it("should convert a date", inject([ConverterService], (converterService: ConverterService) => {
        expect(converterService.deserialize(new Date().toISOString(), Date)).to.be.instanceof(Date);
      }));
    });
github TypedProject / ts-express-decorators / test / units / mvc / components / GlobalAcceptMimesMiddleware.spec.ts View on Github external
describe("GlobalAcceptMimesMiddleware", () => {
  before(
    inject([], () => {
      const settings = new ServerSettingsService();
      settings.acceptMimes = ["application/json"];

      this.middleware = new GlobalAcceptMimesMiddleware(settings);
      this.request = new FakeRequest();
    })
  );

  describe("accept", () => {
    before(() => {
      this.request.mime = "application/json";
    });
    it("should return nothing", () => {
      expect(this.middleware.use(this.request)).to.eq(undefined);
    });
  });
github TypedProject / ts-express-decorators / test / units / socketio / services / SocketIOService.spec.ts View on Github external
describe("getNsp()", () => {
    before(
      inject([InjectorService], (injector: InjectorService) => {
        this.namespace = {
          on: Sinon.stub()
        };
        this.ioStub = {
          of: Sinon.stub().returns(this.namespace)
        };
        this.instance = {
          onConnection: Sinon.stub(),
          onDisconnect: Sinon.stub()
        };
        this.socket = {
          on: Sinon.stub()
        };

        const service = new SocketIOService(injector, {} as any, {} as any, this.ioStub, {} as any, {} as any);
        const nspConf = service.getNsp("/");

@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