Testing Actions
State Change
Testing for a state change is easy, and you can just run your action like a function.
import { effects } from 'ferp';
const IncrementCounter = state => [
{ ...state, counter: state.counter + 1 },
effects.none(),
];
describe('IncremenetCounter', () => {
it('increments the counter state variable', () => {
const initialState = { counter: 0 };
const [state, _effect] = IncrementCounter(initialState);
expect(state).toDeepEqual({
counter: 1,
});
});
});Testing action builders is very similar, too:
Result of Side-Effects
Testing that the correct side effects can be a little more tricky. The problem is that effects touch the outside world that is not controlled by Ferp. Running these end-to-end just like the effect testing is likely your best bet.
Yes, that test code looks clunky, so why not make a helper to make things a little easier?
Which would result in:
There may be other forms of helpers that can make the end-to-end portions of your tests to be more readable and manageable.
Last updated
Was this helpful?