[英]angular - ReferenceError: Can't find variable: URLSearchParams in http://localhost:9877src/test.ts
This is my function in ts file. 这是我在ts文件中的功能。
getFeatures () {
const queryString = new URLSearchParams();
...
}
This is my jasmine file. 这是我的茉莉花文件。
it('should get features', inject([FeatureSupportService], (service : FeatureSupportService) => {
expect(service.getFeatures()).toBeTruthy();
}));
Error: I am not getting this error in karma but I am getting this error when I try to code coverage with yarn test
错误:我没有在业力中收到此错误,但是当我尝试使用
yarn test
编码覆盖时,我收到此错误
Can't find variable: URLSearchParams in http://localhost:9877src/test.ts
Had the same problem with Ionic 2 framework recently. 最近与Ionic 2框架有同样的问题。 For me it was that PhantomJS needed a polyfill for
URLSearchParams
. 对我而言,PhantomJS需要为URLSearchParams提供
URLSearchParams
。
So try including it as a npm package (or manually from https://github.com/WebReflection/url-search-params ): 因此,请尝试将其包含为npm包(或手动从https://github.com/WebReflection/url-search-params ):
npm install url-search-params
And include it to whatever test runner or environment you are using eg karma config file: 并将其包含在您正在使用的任何测试运行器或环境中,例如karma配置文件:
files: [
'../node_modules/url-search-params/build/url-search-params.js',
{ pattern: './karma-test-shim.js', watched: true }
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.