On this page
On this page
Tests
Adding an empty listener by keepMount(store) keeps the store
in active mode during the test. cleanStores(store1, store2, …) cleans
stores used in the test.
import { cleanStores, keepMount } from 'nanostores'
import { $profile } from './profile.js'
afterEach(() => { cleanStores($profile)})
it('is anonymous from the beginning', () => { keepMount($profile) expect($profile.get()).toEqual({ name: 'anonymous' })})You can use allTasks() to wait all async operations in stores.
import { allTasks } from 'nanostores'
it('saves user', async () => { saveUser() await allTasks() expect(analyticsEvents.get()).toEqual(['user:save'])})Imported from the Nano Stores README for version 1.5.5. Improve this page there.