【发布时间】:2020-03-14 03:18:16
【问题描述】:
我正在使用 NativeScript 6+ 和 Angular 8+ 编写应用程序。
我正在尝试编写一些单元测试并让它们运行起来。
我已阅读有关单元测试的文档: https://docs.nativescript.org/tooling/testing/testing
我按照那里的说明设置测试和使用 TestBed。 我的测试不工作并抛出错误。
这是我的存储库:https://github.com/aubrey-fowler/NativeScriptUnitTests
问题:
- 文档仅显示了如何编写测试的示例 零件。如何为服务编写测试?我也需要使用 TestBed 因为我的服务有依赖注入。
- 我的测试抛出错误。为什么以及如何解决它们?
错误:
no reachable hosts
在我的安卓手机上
代码sn-p:
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;
});
});
});
【问题讨论】:
标签: angular unit-testing nativescript