Testing toolkit

  • What is testin-nutin?

    testin-nutin is Nutin's built-in testing toolkit, a small hand-built test runner + jsdom environment + assertion library.

  • How do I configure testin-nutin?

    testinNutin block in nutin.config.js:

  • How do I run tests?

    The test environment loads the built development output (not bundled nor minified) dist/src/index.html into jsdom.

  • How do I write a test?

    Note: Every generated app's package.json gets an "imports": { "#root/.js": "./.js" } entry, so test files can write import { foo } from '#root/path/to/foo.js'.

  • What assertions are available?

    expect(actual) returns a Jest/Chai-style matcher chain; every matcher throws a descriptive Error on failure.

  • How do I spy on methods?

    Replaces obj.methodName and returns a handle:

  • How do I fake timers?

    Fake timers for time-dependent code (setTimeout/setInterval/Date), installed as globals the same way as spies — no imports needed:

  • How do I silence console output?

    silenceConsole(methodOrMethods, fn) wraps a single call, spying on and no-op'ing one or more console methods (a single name or an array) for the duration of that call, then restoring them automatically — before returning the call's result. Works for both sync and async fn: a thenable return value is awaited before restoring, so the spies stay installed for the whole async operation.

  • How do I mock core services?

    For services that shouldn't hit real state (event bus, HTTP, i18n, router), testin-nutin/mocks/ provides plain classes built from a shared factory, createMockMethod():

  • How do I use test coverage?

    via command line: