当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript testing.bootstrap函数代码示例

本文整理汇总了TypeScript中@tsed/testing.bootstrap函数的典型用法代码示例。如果您正苦于以下问题:TypeScript bootstrap函数的具体用法?TypeScript bootstrap怎么用?TypeScript bootstrap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bootstrap函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: describe

describe("Calendars", () => {

    // bootstrap your expressApplication in first
    before(bootstrap(Server));

    // then run your test
    describe("GET /rest/calendars", () => {
        it("should return all calendars", inject([ExpressApplication, Done], (expressApplication: ExpressApplication, done: Done) => {

            SuperTest(expressApplication)
                .get("/rest/calendars")
                .expect(200)
                .end((err, response: any) => {
                    if (err) {
                        throw (err);
                    }

                    let obj = JSON.parse(response.text);

                    expect(obj).to.be.an("array");

                    done();
                });

        }));
    });

});
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:28,代码来源:calendars.spec.ts

示例2: before

  before(async () => {
    await bootstrap(FakeServer)();
    await inject([InjectorService], (injector: InjectorService) => {
      this.locals = new Map<string | Function, any>();
      const provider = injector.getProvider(ProductsCtrl)!;
      const target = provider.useClass;

      this.rebuildHandler = provider.scope !== ProviderScope.SINGLETON;

      this.instance = injector.invoke(target, this.locals, undefined, true);
    })();
  });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:12,代码来源:di.spec.ts

示例3: describe

describe("Swagger", () => {
  before(bootstrap(FakeServer));
  before(inject([ExpressApplication], (expressApplication: ExpressApplication) => (this.app = SuperTest(expressApplication))));
  after(TestContext.reset);

  describe("GET /api-doc/swagger.json", () => {
    before(done => {
      this.app
        .get("/api-doc/swagger.json")
        .expect(200)
        .end((err: any, response: any) => {
          this.spec = JSON.parse(response.text);
          done();
        });
    });

    it("should have a swagger version", () => {
      expect(this.spec.swagger).to.be.eq("2.0");
    });

    it("should have informations field ", () => {
      expect(this.spec.swagger).to.be.eq("2.0");
    });

    it("should have paths field", () => {
      expect(this.spec.paths).to.be.a("object");
    });

    it("should have securityDefinitions field", () => {
      expect(this.spec.securityDefinitions).to.be.a("object");
    });

    it("should have definitions field", () => {
      expect(this.spec.definitions).to.be.a("object");
    });

    it("should have consumes field", () => {
      expect(this.spec.consumes).to.be.an("array");
      expect(this.spec.consumes[0]).to.be.eq("application/json");
    });

    it("should have produces field", () => {
      expect(this.spec.produces).to.be.an("array");
      expect(this.spec.produces[0]).to.be.eq("application/json");
    });

    it("should be equals to the expected swagger.spec.json", () => {
      expect(this.spec).to.deep.eq(require("./data/swagger.spec.json"));
    });
  });
});
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:51,代码来源:swagger.spec.ts

示例4: describe

  describe("CalendarCtrl2", () => {
    let instance: any;
    // bootstrap your Server to load all endpoints before run your test
    before(bootstrap(FakeServer));

    before(
      inject([InjectorService], (injectorService: InjectorService) => {
        instance = injectorService.invoke(CalendarCtrl);
      })
    );
    after(TestContext.reset);

    it("should do something", () => {
      expect(!!instance).to.be.true;
    });
  });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:16,代码来源:testing-example.spec.ts

示例5: describe

describe("Response", () => {
  let request: SuperTest.SuperTest<SuperTest.Test>;
  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("Scenario2: when multiple endpoint for the same path (with next)", () => {
    describe("GET /rest/response/scenario1/:id", () => {
      it("should return the id + test", async () => {
        const response = await request.get("/rest/response/scenario2/10").expect(200);

        response.text.should.be.equal("10value");
      });
    });
  });

  describe("Scenario3: when response is empty or created", () => {
    describe("GET /rest/response/scenario3/:id?", () => {
      it("should return nothing with a 204 status", async () => {
        const response = await request.post("/rest/response/scenario3/10").expect(204);

        response.text.should.be.equal("");
      });

      it("should return a body with ", async () => {
        const response = await request
          .post("/rest/response/scenario3")
          .expect(201);

        response.body.should.deep.equal({id: 1});
      });
    });
  });
  describe("Scenario4: when endpoint use a promise and next", () => {
    describe("GET /rest/response/scenario4/10", () => {
      it("should return a body with ", async () => {
        const response = await request.get("/rest/response/scenario4/10");

        response.text.should.deep.equal("10value");
      });
    });
  });

  describe("Scenario5: when endpoint return a function", () => {
    describe("GET /rest/response/scenario5", () => {
      it("should return a body with ", async () => {
        const response = await request.get("/rest/response/scenario5");

        response.body.should.deep.equal({id: 1});
      });
    });
  });

  describe("Scenario6: when endpoint return an observable", () => {
    describe("GET /rest/response/scenario6", () => {
      it("should return a body with ", async () => {
        const response = await request.get("/rest/response/scenario6");

        response.body.should.deep.equal({id: 1});
      });
    });

    describe("GET /rest/response/scenario6b", () => {
      it("should return a body with ", async () => {
        const response = await request.get("/rest/response/scenario6b");

        response.body.should.deep.equal({id: 1});
      });
    });
  });

  describe("Scenario7: when endpoint return a stream", () => {
    describe("GET /rest/response/scenario7", () => {
      it("should return a body with ", async () => {
        const response = await request.get("/rest/response/scenario7");

        response.body.should.deep.equal({id: "1"});
      });
    });

    describe("GET /rest/response/scenario7b", () => {
      it("should return a body with ", async () => {
        const response = await request.get("/rest/response/scenario7b");

        response.body.should.deep.equal({id: "1"});
      });
//.........这里部分代码省略.........
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:101,代码来源:response.spec.ts

示例6: describe

describe("Rest", () => {
  let app: SuperTest.SuperTest<SuperTest.Test>;
  before(bootstrap(FakeServer));
  before(
    inject([ExpressApplication], (expressApplication: ExpressApplication) => {
      app = SuperTest(expressApplication);
    })
  );
  after(TestContext.reset);
  describe("integration", () => {
    describe("GET /rest", () => {
      it("should return html content", done => {
        app
          .get("/rest/html")
          .expect(200)
          .end((err: any, response: any) => {
            if (err) {
              throw err;
            }

            expect(response.text).to.be.an("string");

            done();
          });
      });
    });

    describe("GET /rest/calendars", () => {
      it("should return an object (without annotation)", done => {
        app
          .get("/rest/calendars/classic/1")
          .expect(200)
          .end((err: any, response: any) => {
            if (err) {
              throw err;
            }
            const obj = JSON.parse(response.text);

            expect(obj).to.be.an("object");
            expect(obj.id).to.equal("1");
            expect(obj.name).to.equal("test");

            done();
          });
      });

      it("should return an object (PathParamsType annotation)", (done: Function) => {
        app
          .get("/rest/calendars/annotation/test/1")
          .expect(200)
          .end((err: any, response: any) => {
            if (err) {
              throw err;
            }

            const obj = JSON.parse(response.text);
            expect(obj).to.be.an("object");
            expect(obj.id).to.equal("1");
            expect(obj.name).to.equal("test");

            done();
          });
      });

      it("should return an object (Via promised response)", (done: Function) => {
        app
          .get("/rest/calendars/annotation/promised/1")
          .expect(200)
          .end((err: any, response: any) => {
            if (err) {
              throw err;
            }
            const obj = JSON.parse(response.text);

            expect(obj).to.be.an("object");
            expect(obj.id).to.equal("1");
            expect(obj.name).to.equal("test");

            done();
          });
      });

      it("should return an object status (Via promised response)", (done: Function) => {
        app
          .get("/rest/calendars/annotation/status/1")
          .expect(202)
          .end((err: any, response: any) => {
            if (err) {
              throw err;
            }

            const obj = JSON.parse(response.text);

            expect(obj).to.be.an("object");
            expect(obj.id).to.equal("1");
            expect(obj.name).to.equal("test");

            done();
          });
      });
//.........这里部分代码省略.........
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:101,代码来源:rest.spec.ts

示例7: describe

describe("Passport", () => {

    // bootstrap your expressApplication in first
    before(bootstrap(Server));
    before(inject([ExpressApplication], (expressApplication: ExpressApplication) => {

        this.app = SuperTest(expressApplication);

        this.done = (done) => (err, response: any) => {
            this.err = err;
            this.response = response;
            done();
        };

    }));

    describe("POST /rest/passport/login", () => {

        describe("when credential isn't given", () => {
            before((done) => {
                this.app
                    .post("/rest/passport/login")
                    .send({})
                    .expect(403)
                    .end(this.done(done));
            });
            it("should respond 403", () => {
                expect(this.response.badRequest).to.be.true;
                expect(this.response.text).to.eq("Bad request, parameter request.body.email is required.");
            });
        });

        describe("when credential is given but is wrong", () => {
            before((done) => {
                this.app
                    .post("/rest/passport/login")
                    .send({email: "test@test.fr", password: "12345"})
                    .expect(404)
                    .end(this.done(done));
            });
            it("should respond 404", () => {
                expect(this.response.notFound).to.be.true;
                expect(this.response.text).to.eq("User not found");
            });
        });

        describe("when credential is given but email is invalid", () => {
            before((done) => {
                this.app
                    .post("/rest/passport/login")
                    .send({email: "test_test.fr", password: "12345"})
                    .expect(403)
                    .end(this.done(done));
            });
            it("should respond 403", () => {
                expect(this.response.text).to.eq("Email is invalid");
            });
        });

        describe("when credential is given", () => {
            before((done) => {
                this.app
                    .post("/rest/passport/login")
                    .send({email: "amy.riley@undefined.io", password: "583538ea97489c137ad54db5"})
                    .expect(200)
                    .end(this.done(done));
            });
            it("should respond 200 and return the user", () => {
                expect(JSON.parse(this.response.text)).to.deep.eq({
                    "_id": "583538ea678f0ce762d3ce62",
                    "firstName": "Amy",
                    "lastName": "Riley",
                    "password": "583538ea97489c137ad54db5",
                    "email": "amy.riley@undefined.io",
                    "phone": "+1 (841) 438-3631",
                    "address": "399 Pilling Street, Verdi, North Carolina, 5810"
                });
            });
        });

    });

    describe("POST /rest/passport/signup", () => {
        describe("when credential isn't given", () => {
            before((done) => {
                this.app
                    .post("/rest/passport/signup")
                    .send({})
                    .expect(403)
                    .end(this.done(done));
            });
            it("should respond 403", () => {
                expect(this.response.text).to.eq("Bad request, parameter request.body.email is required.");
            });
        });

        describe("when credential is given but email is invalid", () => {
            before((done) => {
                this.app
                    .post("/rest/passport/signup")
//.........这里部分代码省略.........
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:101,代码来源:passport.spec.ts


注:本文中的@tsed/testing.bootstrap函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。