angular - ReferenceError:找不到变量:http:// localhost:9877src / test.ts中的URLSearchParams

时间:2017-10-11 11:44:41

标签: angular jasmine

这是我在ts档案中的功能。

getFeatures () {
    const queryString = new URLSearchParams();
    ...
}

这是我的茉莉花档。

 it('should get features', inject([FeatureSupportService], (service : FeatureSupportService) => {
    expect(service.getFeatures()).toBeTruthy();
  }));

错误:我没有在业力中收到此错误但是当我尝试使用yarn test编码覆盖率时出现此错误

Can't find variable: URLSearchParams in http://localhost:9877src/test.ts

1 个答案:

答案 0 :(得分:2)

最近与Ionic 2框架有同样的问题。对我而言,PhantomJS需要URLSearchParams的填充物。

因此尝试将其作为npm包(或从https://github.com/WebReflection/url-search-params手动)包含在内:

npm install url-search-params

并将其包含在您使用的任何测试运行器或环境中,例如karma配置文件:

files: [
            '../node_modules/url-search-params/build/url-search-params.js',
            { pattern: './karma-test-shim.js', watched: true }
        ],