How do I write a test?
- Note: Every generated app's
package.jsongets an"imports": { "#root/*.js": "./*.js" }entry, so test files can writeimport { foo } from '#root/path/to/foo.js'.
File discovery
Files matching *.test.js, anywhere under a configured origin directory, are
discovered automatically (see How do I configure testin-nutin?).
Global API
Installed before any test file loads:
describe('globals beforeEach/All and afterEach/All', () => {
// `beforeEach/All` and `afterEach/All` must be INSIDE a `describe` block
beforeAll(() => { beforeAllCount++; });
beforeEach(() => { beforeEachCount++; });
afterEach(() => { afterEachCount++; });
afterAll(() => { console.debug('afterAll called.'); });
it('should be called once for all and once for each', () => {
expect(beforeAllCount).toEqual(1);
expect(beforeEachCount).toEqual(1);
expect(afterEachCount).toEqual(0);
});
it.todo('Keep counting.');
});
describe(name, fn)/it(name, fn)— notest()alias, onlyit.beforeAll/beforeEach/afterEach/afterAll— one hook of each kind per suite; declaring a second one in the samedescribesilently overwrites the first (no stacking/composition).- DOM helpers:
$(selector)/$(selector)(querySelector/querySelectorAllshorthands),click(el),type(el, text). setupJsdom/teardownJsdom/resetDom/flushPromises/silenceConsoleare also exposed as globals if a test needs to manage the DOM environment directly.