NativeScript / NativeScript/nativescript-cli
NativeScript - how to get unit tests to work properly?
@NathanWalker y travaille déjà.
Depuis le 5/6/2020.
- Langage dominant
- JavaScript
- Étoiles
- 1.1k
- Forks
- 204
- Merge moyen
- 1 j 9 h
- PR mergées (30 j)
- 8
Description
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:
- 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.
- 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;
});
});
});
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Évaluation
Cette issue n'a pas encore été évaluée.