ngrx-workshop
Search…
Testing Factory
1
// State Factory
2
const createUser = ({
3
id = 0,
4
firstName = '',
5
lastName = '',
6
userName = ''
7
} = {}): User => ({
8
id: id,
9
firstName: firstName || 'firstName',
10
lastName: lastName || `lastName`,
11
userName: userName || `${firstName}.${lastName}`
12
});
13
14
const createUsersState = ({
15
entities = {
16
'1': createUser({ id: 1, firstName: 'Bob' }),
17
'2': createUser({ id: 2, firstName: 'Sue' }),
18
'3': createUser({ id: 3, firstName: 'Mary' })
19
},
20
ids = ['1', '2', '3'],
21
selectedId = 0,
22
loading = false,
23
error = ''
24
} = {}) => ({
25
users: {
26
ids,
27
entities,
28
selectedId,
29
loading,
30
error
31
}
32
});
Copied!
Copy link