# 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.

```ts
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.

```ts
import { allTasks } from 'nanostores'

it('saves user', async () => {
  saveUser()
  await allTasks()
  expect(analyticsEvents.get()).toEqual(['user:save'])
})
```

***

*Imported from the [Nano Stores README](https://github.com/nanostores/nanostores/blob/1.5.5/README.md#tests) for version 1.5.5. Improve this page there.*
