NativeScript / NativeScript/nativescript-cli

NativeScript - unit tests throwing errors

Đang mở
#5,277 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

unit testing
Ngôn ngữ chính
JavaScript
Star
1.1k
Fork
204
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
8

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với karma.config.js, src/tests/setup.ts và spec của HttpInterceptorService được nêu trong báo cáo, sau đó tái hiện lần chạy test của NativeScript 6+/Angular 8+. Truy tìm lỗi afterAll liên quan đến window.location.origin và so sánh phần setup với tài liệu kiểm thử được liên kết. Được coi là hoàn tất khi test suite hoàn thành mà không gặp lỗi đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
angular, javascript
Lĩnh vực
mobile, testing
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.