mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Allow reducerTester to work with every data type & payload-less actions (#29241)
This commit is contained in:
parent
6838af5ce1
commit
f5916260bd
@ -1,9 +1,10 @@
|
|||||||
import { Reducer } from 'redux';
|
import { Reducer } from 'redux';
|
||||||
import { PayloadAction } from '@reduxjs/toolkit';
|
import { PayloadAction, Action } from '@reduxjs/toolkit';
|
||||||
|
import { cloneDeep } from 'lodash';
|
||||||
|
|
||||||
export interface Given<State> {
|
export interface Given<State> {
|
||||||
givenReducer: (
|
givenReducer: (
|
||||||
reducer: Reducer<State, PayloadAction<any>>,
|
reducer: Reducer<State, PayloadAction<any> | Action<any>>,
|
||||||
state: State,
|
state: State,
|
||||||
showDebugOutput?: boolean,
|
showDebugOutput?: boolean,
|
||||||
disableDeepFreeze?: boolean
|
disableDeepFreeze?: boolean
|
||||||
@ -11,7 +12,7 @@ export interface Given<State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface When<State> {
|
export interface When<State> {
|
||||||
whenActionIsDispatched: (action: PayloadAction<any>) => Then<State>;
|
whenActionIsDispatched: (action: PayloadAction<any> | Action<any>) => Then<State>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Then<State> {
|
export interface Then<State> {
|
||||||
@ -66,9 +67,9 @@ export const reducerTester = <State>(): Given<State> => {
|
|||||||
disableDeepFreeze = false
|
disableDeepFreeze = false
|
||||||
): When<State> => {
|
): When<State> => {
|
||||||
reducerUnderTest = reducer;
|
reducerUnderTest = reducer;
|
||||||
initialState = { ...state };
|
initialState = cloneDeep(state);
|
||||||
if (!disableDeepFreeze) {
|
if (!disableDeepFreeze && (typeof state === 'object' || typeof state === 'function')) {
|
||||||
initialState = deepFreeze(initialState);
|
deepFreeze(initialState);
|
||||||
}
|
}
|
||||||
showDebugOutput = debug;
|
showDebugOutput = debug;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user