NativeScript / NativeScript/nativescript-cli

NativeScript - how to get unit tests to work properly?

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

@NathanWalker がすでに取り組んでいます。

2020年6月5日 から。

in-progress 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 and get them up and running.

I have read the documentation on unit testing: https://docs.nativescript.org/tooling/testing/testing

I followed the directions there for setting up the tests and using TestBed. My tests are not working and throwing errors.

Here is my repository: https://github.com/aubrey-fowler/NativeScriptUnitTests

Questions:

  1. The documentation only shows an example of how to write a test for a component. How do I write a test for a service? I also need to use TestBed for this because my service has dependency injection.
  2. My tests are throwing errors. Why and how can I fix them?

Errors:

no reachable hosts
on my Android phone

code snippet:

import { ItemsComponent } from '../app/item/items.component';

import {
    nsTestBedAfterEach,
    nsTestBedBeforeEach,
    nsTestBedRender
} from 'nativescript-angular/testing';

describe('ItemsComponent Test', () => {

    beforeEach(nsTestBedBeforeEach([ItemsComponent]));
    afterEach(nsTestBedAfterEach(false));

    it('should be defined', () => {

        nsTestBedRender(ItemsComponent).then((fixture) => {
            fixture.detectChanges();
            const component = fixture.componentInstance;
            expect(component).toBeTruthy;
        });

    });

});

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

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

はじめの一歩

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

評価

この issue はまだ評価されていません。

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

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