Skip to content

Commit ed23274

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [v27] 2 pages modified
1 parent 4820fa9 commit ed23274

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

api-1/createovermindmock.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,26 @@ describe('Actions', () => {
4848
It is important that you separate your **config** from the instantiation of Overmind, meaning that **createOvermind** should not be used in the same file as the config you see imported here, it should rather be used where you render your application. This allows the config to be used for multiple purposes.
4949
{% endhint %}
5050

51+
## Setting initial state
52+
53+
Pass a function as the second or third argument to set initial state.
54+
55+
{% tabs %}
56+
{% tab title="overmind/actions.test.js" %}
57+
```typescript
58+
import { createOvermindMock } from 'overmind'
59+
import { config } from './'
60+
61+
describe('State', () => {
62+
test('should derive authors of posts', async () => {
63+
const overmind = createOvermindMock(config, (state) => {
64+
state.posts = { 1: { id: 1, author: 'Janet' } }
65+
})
66+
67+
expect(overmind.state.authors).toEqual(['Janet'])
68+
})
69+
})
70+
```
71+
{% endtab %}
72+
{% endtabs %}
73+

guides-1/testing.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ When you write tests you will create many instances of a mocked version of Overm
1313
{% tabs %}
1414
{% tab title="overmind/index.js" %}
1515
```typescript
16-
import { IConfig } from 'overmind'
1716
import { state } from './state'
1817

1918
export const config = {
@@ -34,6 +33,29 @@ const overmind = createOvermind(config)
3433

3534
Now we are free to import our configuration without touching the application instance. Lets go!
3635

36+
## Setting initial state
37+
38+
By passing a function either as second or third argument you can change the initial state of Overmind.
39+
40+
{% tabs %}
41+
{% tab title="overmind/actions.test.js" %}
42+
```typescript
43+
import { createOvermindMock } from 'overmind'
44+
import { config } from './'
45+
46+
describe('State', () => {
47+
test('should derive authors of posts', async () => {
48+
const overmind = createOvermindMock(config, (state) => {
49+
state.posts = { 1: { id: 1, author: 'Janet' } }
50+
})
51+
52+
expect(overmind.state.authors).toEqual(['Janet'])
53+
})
54+
})
55+
```
56+
{% endtab %}
57+
{% endtabs %}
58+
3759
## Testing actions
3860

3961
When testing an action you’ll want to verify that changes to state are performed as expected. To give you the best possible testing experience Overmind comes with a mocking tool called **createOvermindMock**. It takes your application configuration and allows you to run actions as if they were run from components.

0 commit comments

Comments
 (0)