Skip to content

Testing

Synchronous checks with flushAll().

flushAll()

Templates and control flow render synchronously, so the DOM is complete right after mount(). Updates after a signal write apply in a microtask. In a test, call flushAll() after a write to run them at once.

import { application, flushAll } from 'signy';

test('counts clicks', () => {
  const root = document.createElement('div');
  const app = application(Counter).mount(root);

  root.querySelector('button').click();
  flushAll();

  expect(root.textContent).toContain('Clicked 1 times');
  app.unmount();
});

Async work

For loaders, lazy imports and resources, wait for pending promises first, then call flushAll().

await new Promise((resolve) => setTimeout(resolve));
flushAll();

Router

memoryRouter() keeps history in memory and takes the starting entries.

const testRouter = memoryRouter({ routes, initialEntries: ['/users/42'] });
application(Layout).use(testRouter).mount(root);