NativeScript / NativeScript/nativescript-cli
NativeScript - unit tests throwing errors
未关闭
还没有人认领这个 Issue。
unit testing
- 主要语言
- JavaScript
- 星标
- 1.1k
- 派生
- 204
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 8
描述
I'm writing an app with NativeScript 6+ and Angular 8+. I'm trying to write some unit tests for my services with karma and jasmine. My unit tests are throwing errors.
How can I write my unit tests properly? I read and followed the directions on this web page but it still doesn't work: https://docs.nativescript.org/angular/tooling/testing/testing
karma.config.js
// list of files / patterns to load in the browser
files: [
'src/tests/setup.ts',
'src/tests/**/*.spec.ts'
],
test
import {
nsTestBedAfterEach,
nsTestBedBeforeEach,
nsTestBedRender
} from 'nativescript-angular/testing';
import { HttpInterceptorService } from '../app/core/interceptors/http-interceptor-service';
describe('HttpInterceptorService', () => {
beforeEach(nsTestBedBeforeEach([HttpInterceptorService]));
afterEach(nsTestBedAfterEach(false));
it('should be created', () => {
});
it('should have its functions defined', () => {
});
});
Error:
NativeScript / 13.3 (13.3; iPad): Executed 15 of 17 SUCCESS (0 secs / 0.018 secs)
NativeScript / 13.3 (13.3; iPad) undefined at line undefined FAILED
An error was thrown in afterAll
TypeError: undefined is not an object (evaluating 'window.location.origin') (line 108)
at <Jasmine>
at file:///app/vendor.js:157139:46
at <Jasmine>
at file:///app/vendor.js:157341:57
at <Jasmine>
at file:///app/bundle.js:1389:28
at <Jasmine>
TypeError: undefined is not an object (evaluating 'window.location.origin') (line 108)
at <Jasmine>
at file:///app/vendor.js:157139:46
at <Jasmine>
at file:///app/vendor.js:157341:57
at <Jasmine>
at file:///app/bundle.js:1389:28
at <Jasmine>
NativeScript / 13.3 (13.3; iPad): Executed 16 of 17 (1 FAILED) (0.084 secs / 0.018 secs)
TOTAL: 1 FAILED, 15 SUCCESS
CONSOLE LOG file:///node_modules/nativescript-unit-test-runner/app/main-view-model.js:132:0: NSUTR: this.error: An error was thrown in afterAll
TypeError: undefined is not an object (evaluating 'window.location.origin') (line 108)
at <Jasmine>
at file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.jasmine.js:1445:0
at <Jasmine>
at file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:188:0
at <Jasmine>
at file:///src/main.ts:11:16
at <Jasmine>
TypeError: undefined is not an object (evaluating 'window.location.origin') (line 108)
at <Jasmine>
at file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.jasmine.js:1445:0
at <Jasmine>
at file:///node_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:188:0
at <Jasmine>
at file:///src/main.ts:11:16
at <Jasmine>
CONSOLE LOG file:///node_modules/nativescript-unit-test-runner/app/main-view-model.js:120:0: NSUTR: completed test run.
CONSOLE LOG file:///node_modules/nativescript-unit-test-runner/app/main-view-model.js:120:0: NSUTR: completed test run.
CONSOLE LOG file:///node_modules/nativescript-unit-test-runner/app/main-view-model.js:124:0: NSUTR: completeAck
CONSOLE LOG file:///node_modules/nativescript-unit-test-runner/app/main-view-model.js:124:0: NSUTR: completeAck
NativeScript / 13.3 (13.3; iPad) ERROR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 karma.config.js、src/tests/setup.ts 以及报告中显示的 HttpInterceptorService spec 开始,然后复现 NativeScript 6+/Angular 8+ 的测试运行。跟踪涉及 window.location.origin 的 afterAll 失败,并将 setup 与链接的测试文档进行比较。当测试套件在没有该错误的情况下完成时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- angular, javascript
- 领域
- mobile, testing
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100