Search code examples
nativescriptangular2-nativescriptnativescript-cli

NativeScript tests fail to run


The tests appear to run in the simulator because an app launches briefly with text that says "Testing in Progress" then "Total: 0, Passed: 0, Failed: 0" (took a video of the simulator window).

This is a NativeScript Angular project using TypeScript. I have tried an example as both src/app/tests/example.js and src/app/tests/example.ts with the following:

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

Last few lines of log after running 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 versions:

"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 Happens on Android as well.


Solution

  • I had the tests in the wrong folder. Tried src/tests and src/app/tests. Noticed app/tests was mentioned but thought it meant src/app.

    N.B. tns test init did not create any files in app/tests.