import diff from 'deep-diff' ; import { ReduxActionWithPayload } from '../../../harmowatch/ngx-redux-core' ; import { ReduxReducerFunction } from '@harmowatch/redux-decorators/lib/reducer/function/redux-reducer-function.type' ; export function compare ( actual , state , action ) { const stateJson = JSON . stringify ( state ) ; const givenState = JSON . parse ( stateJson ) ; const expectedState = JSON . parse ( stateJson ) ; actual ( givenState , action || null ) ; const differences = diff ( expectedState , givenState ) || [ ] ; const diffStr = differences . map ( difference => `- "${ difference . path . join ( '.' ) }"` ) . join ( '\n' ) ; return { pass : differences . length === 0 , message : `Expected the reducer not to mutate the state, but it mutates the following properties:\n${ diffStr }` , } ; } export function notToMutateTheGivenState ( ) { return { compare } ; }