NativeScript / NativeScript/nativescript-cli

NativeScript - unit tests throwing errors

オープン
#5,277 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

unit testing
主要言語
JavaScript
スター
1.1k
フォーク
204
平均マージ
1日 9時間
マージ済み PR(30日)
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

karma.config.js、src/tests/setup.ts、およびレポートに示されている HttpInterceptorService spec から始め、その後 NativeScript 6+/Angular 8+ のテスト実行を再現します。window.location.origin に関係する afterAll の失敗を追跡し、セットアップをリンク先のテストドキュメントと比較します。そのエラーなしでテストスイートが完了すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, javascript
領域
mobile, testing
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。