2019-03-18 12:03:34 +01:00
# Redux framework
2020-01-13 08:03:22 +01:00
Grafana uses [Redux Toolkit ](https://redux-toolkit.js.org/ ) to handle Redux boilerplate code.
> Some of our Reducers are used by Angular and therefore state is to be considered as mutable for those reducers.
2019-03-18 12:03:34 +01:00
2019-11-15 07:30:50 +01:00
## Test functionality
2019-03-18 12:03:34 +01:00
### reducerTester
Fluent API that simplifies the testing of reducers
2019-11-15 07:30:50 +01:00
#### Usage
2019-03-18 12:03:34 +01:00
```typescript
reducerTester ()
. givenReducer ( someReducer , initialState )
. whenActionIsDispatched ( someAction ( 'reducer tests' ))
. thenStateShouldEqual ({ ... initialState , data : 'reducer tests' });
```
2019-11-15 07:30:50 +01:00
#### 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' )]);
```