mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Docs: Updates docs for redux framework (#20377)
* Docs: Updates docs for redux framework * Update contribute/style-guides/redux.md Co-Authored-By: Marcus Olsson <olsson.e.marcus@gmail.com> * Update contribute/style-guides/redux.md Co-Authored-By: Marcus Olsson <olsson.e.marcus@gmail.com> * Update contribute/style-guides/redux.md Co-Authored-By: Marcus Olsson <olsson.e.marcus@gmail.com> * Update contribute/style-guides/redux.md Co-Authored-By: Marcus Olsson <olsson.e.marcus@gmail.com> * Docs: Updates after PR comments * Update redux.md
This commit is contained in:
parent
5b84a3cd53
commit
e60f7d008e
@ -5,7 +5,7 @@ To reduce the amount of boilerplate code used to create a strongly typed redux s
|
||||
`+` Much less boilerplate code
|
||||
`-` Non Redux standard api
|
||||
|
||||
## New core functionality
|
||||
## Core functionality
|
||||
|
||||
### actionCreatorFactory
|
||||
|
||||
@ -117,13 +117,13 @@ Type '{ nonExistingProperty: string; data: string[]; }' is not assignable to typ
|
||||
Object literal may only specify known properties, and 'nonExistingProperty' does not exist in type 'ExampleReducerState'. [2322]
|
||||
```
|
||||
|
||||
## New test functionality
|
||||
## Test functionality
|
||||
|
||||
### reducerTester
|
||||
|
||||
Fluent API that simplifies the testing of reducers
|
||||
|
||||
#### Example
|
||||
#### Usage
|
||||
|
||||
```typescript
|
||||
reducerTester()
|
||||
@ -131,3 +131,32 @@ reducerTester()
|
||||
.whenActionIsDispatched(someAction('reducer tests'))
|
||||
.thenStateShouldEqual({ ...initialState, data: 'reducer tests' });
|
||||
```
|
||||
|
||||
#### Complex usage
|
||||
Sometimes you encounter a `resulting state` that contains properties that are hard to compare, such as `Dates`, but you still want to compare that other props in state are correct.
|
||||
|
||||
Then you can use `thenStatePredicateShouldEqual` function on `reducerTester` that will return the `resulting state` so that you can expect upon individual properties..
|
||||
|
||||
```typescript
|
||||
reducerTester()
|
||||
.givenReducer(someReducer, initialState)
|
||||
.whenActionIsDispatched(someAction('reducer tests'))
|
||||
.thenStatePredicateShouldEqual(resultingState => {
|
||||
expect(resultingState.data).toEqual('reducer tests');
|
||||
return true;
|
||||
});
|
||||
```
|
||||
|
||||
### thunkTester
|
||||
|
||||
Fluent API that simplifies the testing of thunks.
|
||||
|
||||
#### Usage
|
||||
|
||||
```typescript
|
||||
const dispatchedActions = await thunkTester(initialState)
|
||||
.givenThunk(someThunk)
|
||||
.whenThunkIsDispatched(arg1, arg2, arg3);
|
||||
|
||||
expect(dispatchedActions).toEqual([someAction('reducer tests')]);
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user