NativeScript 测试钩子
NativeScript 插件,让您能够像 Angular 风格指南一样处理 Nativescript 测试
npm i --save nativescript-tests-hook

NativeScript 测试钩子

NativeScript 插件,让您能够像 Angular 风格指南一样处理 Nativescript 测试

NativeScript 默认配置为将所有测试放入 tests 文件夹,但随着应用大小和组件的增加,有时这可能会有些烦恼,因为将单元测试与实现放在一起更容易维护这些测试。当我们为 Angular 应用程序的 Web 版本进行开发时,我们根据 Angular 风格指南将测试文件放入相应的功能文件夹,并使用 .spec.ts.spec.js 后缀。

示例

app
|-- myFeature
|- myFeature.component.html
|- myFeature.component.ts
|- myFeature.component.spec.ts

只需将 .spec.ts.spec.js 文件放在实现旁边即可。在 tns 的 before-prepare 钩子时间,它会将所有测试从任何位置移动到 apptests 文件夹。

安装

Npm

npm install nativescript-tests-hook --save-dev

配置

您需要注意的唯一一件事是在测试中导入文件依赖项时,您必须根据 Nativescript 的位置规则文档 将它们引用为从应用程序包加载文件,以保持它们在移动时的引用。

示例

import { MyFeatureComponent } from '~/myFeature/myFeature.component';
import { AppComponent } from '~/app.component';