• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript testing.inject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: describe

  describe("$onInit()", () => {
    before(
      inject([TypeORMModule, ServerSettingsService], (service: TypeORMModule, settings: ServerSettingsService) => {
        this.service = service;
        settings.set("typeorm", {
          db1: {
            config: "config"
          }
        });

        this.createConnectionStub = Sinon.stub(this.service.typeORMService, "createConnection").resolves("connection" as any);

        return (this.result = this.service.$onInit());
      })
    );

    after(
      inject([ServerSettingsService], (settings: ServerSettingsService) => {
        settings.set("typeorm", {});
        this.createConnectionStub.restore();
        TestContext.reset();
      })
    );

    it("should call the connect method", () => {
      this.createConnectionStub.should.have.been.calledWithExactly("db1", {config: "config"});
    });

    it("should return a promise", () => {
      this.result.should.eventually.deep.eq(["connection"]);
    });
  });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:32,代码来源:TypeORMModule.spec.ts


示例2: describe

describe("ParseService :", () => {
  it("should clone object", () => {
    const source = {};

    expect(ParseService.clone(source)).not.to.be.equal(source);
  });

  it("should not clone object", inject([ParseService], (parserService: ParseService) => {
    const source = {test: {}};

    expect(parserService.eval(undefined!, source, false)).to.equal(source);
    expect(parserService.eval("test", source, false)).to.equal(source.test);
  }));

  it("should eval expression with a scope and return value", inject([ParseService], (parserService: ParseService) => {
    expect(
      parserService.eval(undefined!, {
        test: "yes"
      }).test
    ).to.equal("yes");

    expect(parserService.eval(undefined!, "test")).to.equal("test");
  }));

  it("should eval expression with a scope and return value", inject([ParseService], (parserService: ParseService) => {
    expect(
      parserService.eval("test", {
        test: "yes"
      })
    ).to.equal("yes");
  }));

  it("should eval expression with a scope and return value", inject([ParseService], (parserService: ParseService) => {
    expect(
      parserService.eval("test.foo", {
        test: "yes"
      })
    ).to.equal(undefined);
  }));

  it("should eval expression with a scope and return a new object", inject([ParseService], (parserService: ParseService) => {
    const scope = {
      test: {
        foo: "yes"
      }
    };

    const value = parserService.eval("test", scope);

    expect(value.foo).to.equal("yes");

    value.foo = "test";

    expect(value.foo).to.not.equal(scope.test.foo); // New instance
  }));
});
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:56,代码来源:ParseService.spec.ts


示例3: describe

    describe("middleware error", () => {
      class Test {
      }

      before(
        inject([InjectorService], (injector: InjectorService) => {
          Sinon.stub(injector as any, "getProvider");
        })
      );
      after(inject([InjectorService], (injector: InjectorService) => {
        // @ts-ignore
        injector.getProvider.restore();
      }));

      it("should call build handler from metadata", inject([InjectorService], async (injector: InjectorService) => {
        // GIVEN
        const instance = new Test();
        const provider = {
          store: {
            get: Sinon.stub()
          }
        };

        Store.from(Test).set("socketIO", {
          type: ProviderType.MIDDLEWARE,
          error: true,
          handlers: {
            use: "use"
          }
        });

        // @ts-ignore
        injector.getProvider.returns({
          instance,
          type: ProviderType.MIDDLEWARE
        });

        const scope = {scope: "scope", args: undefined};
        const error = new Error("test");
        const builder: any = new SocketHandlersBuilder(provider as any, {} as any, injector);
        Sinon.stub(builder, "invoke").returns({result: "result"});

        // WHEN
        await builder.bindMiddleware({target: "target"}, scope, Promise.reject(error));

        // THEN
        injector.getProvider.should.have.been.calledWithExactly({target: "target"});
        builder.invoke.should.have.been.calledWithExactly(instance, "use", {error, ...scope});
      }));
    });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:50,代码来源:SocketHandlersBuilder.spec.ts


示例4: describe

describe("RouteService", () => {
  it("should inject RouteService and return routes", inject([RouteService], (routeService: RouteService) => {
    const routes = routeService.getAll();

    expect(routes).to.be.an("array");
  }));

  it("should inject RouteService and print routes", inject([InjectorService, RouteService], (injector: InjectorService, routeService: RouteService) => {
    (injector.logger.info as any).resetHistory();
    // tslint:disable-next-line: no-unused-variable
    routeService.printRoutes();

    injector.logger.info.should.have.been.calledWithExactly(Sinon.match.string);
  }));
});
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:15,代码来源:RouteService.spec.ts


示例5: describe

  describe("when error", () => {
    before(
      inject([AcceptMimesMiddleware], (middleware: AcceptMimesMiddleware) => {
        this.middleware = middleware;

        const acceptStub = Sinon.stub();
        acceptStub.withArgs("application/xml").returns(false);
        acceptStub.withArgs("application/json").returns(false);

        this.request = {
          accepts: acceptStub
        };
        this.endpoint = {
          get: () => {
            return ["application/json", "application/xml"];
          }
        };

        try {
          this.result = this.middleware.use(this.endpoint, this.request);
        } catch (er) {
          this.error = er;
        }
      })
    );

    it("should call request.accepts methods", () => {
      this.request.accepts.should.have.been.calledWithExactly("application/json").and.calledWithExactly("application/xml");
    });

    it("shouldn't emit error", () => {
      expect(this.error.message).to.equal("You must accept content-type application/json, application/xml");
    });
  });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:34,代码来源:AcceptMimesMiddleware.spec.ts


示例6: describe

    describe("when didn't use converter", () => {
      before(
        inject([InjectorService], (injector: InjectorService) => {
          this.pipeStub = Sinon.stub(FilterBuilder as any, "pipe");
          this.pipeStub.returns("filter2");

          this.injectorStub = Sinon.stub(injector, "get");
          this.injectorStub.returns({
            deserialize: () => {
            }
          });

          this.result = (new FilterBuilder(injector) as any).appendConverterFilter("filter", {
            useValidation: false,
            type: "type",
            collectionType: "collection"
          });
        })
      );
      after(() => {
        this.injectorStub.restore();
        this.pipeStub.restore();
      });
      it("should not have been called pipe method", () => {
        return this.pipeStub.should.not.be.called;
      });
      it("shouldn't have called injector.get method", () => {
        return this.injectorStub.should.not.be.called;
      });
      it("should return a filter wrapped", () => {
        expect(this.result).to.eq("filter");
      });
    });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:33,代码来源:FilterBuilder.spec.ts


示例7: describe

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);
    });
  });

  describe("not accept", () => {
    before(() => {
      this.request.mime = "text/html";
    });

    it("should throws NotAcceptable", () => {
      assert.throws(() => {
        this.middleware.use(this.request);
      }, "You must accept content-type application/json");
    });
  });
});
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:32,代码来源:GlobalAcceptMimesMiddleware.spec.ts


示例8: describe

describe("SymbolConverter", () => {
  before(
    inject([ConverterService], (converterService: ConverterService) => {
      this.symbolConverter = converterService.getConverter(Symbol);
    })
  );
  after(TestContext.reset);

  it("should do something", () => {
    expect(!!this.symbolConverter).to.be.true;
  });

  describe("deserialize()", () => {
    it("should deserialize data as symbol when a string is given", () => {
      expect(this.symbolConverter.deserialize("testSymbol")).to.be.a("symbol");
    });
  });

  describe("serialize()", () => {
    before(() => {
      this.symbolTest = this.symbolConverter.serialize(Symbol("testSymbol2"));
    });

    it("should serialize data to a string", () => {
      expect(this.symbolTest).to.be.a("string");
    });
    it("should serialize data to a string that equals to testSymbol2", () => {
      expect(this.symbolTest).to.be.equal("testSymbol2");
    });
  });
});
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:31,代码来源:SymbolConverter.spec.ts


示例9: describe

  describe("via InjectorService to mock other service", () => {
    before(inject([ControllerService], (controllerService: ControllerService) => {

      this.calendarsService = {
        find: Sinon.stub().returns(Promise.resolve({id: "1"}))
      };

      const locals = new Map<any, any>();
      locals.set(CalendarsService, this.calendarsService);

      this.CalendarsCtrl = controllerService.invoke<CalendarsCtrl>(CalendarsCtrl, locals);
      this.result = this.CalendarsCtrl.get("1");
      return this.result;
    }));

    it("should get the service from InjectorService", () => {
      expect(this.CalendarsCtrl).to.be.an.instanceof(CalendarsCtrl);
    });

    it("should have a fake memoryStorage", () => {
      expect(this.CalendarsCtrl.calendarsService).to.equal(this.calendarsService);
    });

    it("should have been called the CalendarService.find() method", () => {
      this.calendarsService.find.should.be.calledWithExactly("1");
    });

    it("should return the calendar", () => {
      return this.result.should.eventually.deep.equal({id: "1"});
    });
  });
开发者ID:Romakita,项目名称:ts-express-decorators,代码行数:31,代码来源:CalendarsCtrl.spec.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript testing.TestContext类代码示例发布时间:2022-05-28
下一篇:
TypeScript testing.bootstrap函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap