ns-unit-testing
Unit testing with Vitest on real NativeScript runtimes
@nativescript/unit-test-runner v5 (2026) is not Karma anymore — it's a Vitest 4 custom-pool plugin. Vitest runs on the host (CLI, reporters, coverage, editor integrations); a plugin bridges Vitest's worker protocol over a WebSocket to your app running in the real iOS/Android runtime, where specs execute on the app's main thread (default) or in NativeScript Worker runtimes (opt-in). Karma/karma.conf.js/jasmine-mocha-qunit selection is the deprecated v4-and-below world.
Setup
ns test init --framework vitest
ns test ios # or: ns test android
ns test init scaffolds: vitest.config.mts, app/test.ts (the on-device entry: coordinator + spec registry + host page), app/tests/example.spec.ts, and tsconfig.spec.json (TS projects). It installs vitest, @vitest/runner, @nativescript/unit-test-runner@^5 as devDependencies plus @valor/nativescript-websockets as a regular dependency — that one ships native code, and the CLI only wires native code for regular deps; don't "clean it up" into devDependencies.
// vitest.config.mts — ns test sets NS_PLATFORM for you
import { defineConfig } from 'vitest/config';
import { nativeScript } from '@nativescript/unit-test-runner';