NativeScript 测试无法运行

Posted

技术标签:

【中文标题】NativeScript 测试无法运行【英文标题】:NativeScript tests fail to run 【发布时间】:2019-03-13 14:10:09 【问题描述】:

测试似乎在模拟器中运行,因为应用程序会短暂启动并显示“正在测试”然后是“总计:0,通过:0,失败:0”的文字(拍摄了模拟器窗口的视频)。

这是一个使用 TypeScript 的 NativeScript Angular 项目。我已经尝试了src/app/tests/example.jssrc/app/tests/example.ts 的示例,其中包含以下内容:

// A sample Jasmine test
describe('A suite', () => 
  it('contains spec with an expectation', () => 
    expect(true).toBe(true);
  );
);

运行tns test ios 后的最后几行日志。

Skipping prepare.
Successfully transferred all files.
Refreshing application...
Successfully synced application [redacted] on device CFB71B33-F348-452D-8069-E846D46A246D.
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:54:28: NSUTR: fetching http://127.0.0.1:9876/context.json
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:54:28: NSUTR: fetching http://10.0.1.15:9876/context.json
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:60:32: NSUTR: found karma at 127.0.0.1
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:97:20: NSUTR: connecting to karma at http://127.0.0.1:9876
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:60:32: NSUTR: found karma at 10.0.1.15
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:116:24: NSUTR: successfully connected to karma
08 10 2018 15:56:45.224:INFO [NativeScript / 11.4 (11.4; iPhone)]: Connected on socket 1gPBBxKC1KDaVXesAAAA with id NativeScriptUnit-3023
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:159:20: NSUTR: downloading http://127.0.0.1:9876/context.json
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:200:32: NSUTR: eval script /base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?a1eb923d36d1ca53b93387cb5312668373ad9ef2
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:200:32: NSUTR: eval script /base/node_modules/karma-jasmine/lib/boot.js?945a38bf4e45ad2770eb94868231905a04a0bd3e
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:200:32: NSUTR: eval script /base/node_modules/karma-jasmine/lib/adapter.js?6cf71867f538f40db053c1775b2c56a83696375c
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:212:24: NSUTR: beginning test run
NativeScript / 11.4 (11.4; iPhone): Executed 0 of 0 SUCCESS (0 secs / 0 secs)
NativeScript / 11.4 (11.4; iPhone): Executed 0 of 0 ERROR (0.006 secs / 0 secs)
CONSOLE LOG file:///app/tns_modules/nativescript-unit-test-runner/main-view-model.js:258:24: NSUTR: completeAck
NativeScript / 11.4 (11.4; iPhone) ERROR
  Disconnectedclient disconnected from CONNECTED state
NativeScript / 11.4 (11.4; iPhone): Executed 0 of 0 ERROR (0.006 secs / 0 secs)

Package.json 版本:

"nativescript-unit-test-runner": "^0.3.4",
"@types/jasmine": "~2.8.9",
"jasmine-core": "3.2.1",
"karma": "3.0.0",
"karma-jasmine": "1.1.2",
"karma-nativescript-launcher": "0.4.0",

EDIT 也发生在 android 上。

【问题讨论】:

【参考方案1】:

我将测试放在错误的文件夹中。试过src/testssrc/app/tests。注意到app/tests 被提及但认为它意味着src/app

注意tns test init 没有在app/tests 中创建任何文件。

【讨论】:

以上是关于NativeScript 测试无法运行的主要内容,如果未能解决你的问题,请参考以下文章

TypeError:无法在 Nativescript 中读取未定义的属性“sdkVersion”

我的用例中的 Nativescript 或 Native

在 NativeScript 中显示 PopOver

插件 nativescript-fancyalert 无法在 Android 上运行

Nativescript - 在按钮单击时打开 SideDrawer

使用 Typescript 时如何在 NativeScript 中访问 Native api