NativeScript / NativeScript/nativescript-cli
NativeScript - how to get unit tests to work properly?
Abierto
@NathanWalker ya está trabajando en esto.
Desde el 5/6/2020.
in-progress
unit testing
- Lenguaje dominante
- JavaScript
- Estrellas
- 1.1k
- Forks
- 204
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 8
Descripción
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;
});
});
});
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.