Skip to content

Instantly share code, notes, and snippets.

@jasonleehodges
Last active December 11, 2021 18:31
Show Gist options
  • Save jasonleehodges/ee0206d991d9a93ebae5496c24fb7fd1 to your computer and use it in GitHub Desktop.
Save jasonleehodges/ee0206d991d9a93ebae5496c24fb7fd1 to your computer and use it in GitHub Desktop.
Unit Tests for Reducer
import {
CounterState,
decrement,
increment,
incrementByAmount,
testableCounterReducer,
} from "./testableCounterReducer";
describe("testable counter reducer", () => {
const initialState: CounterState = {
value: 3,
status: "idle",
};
it("should handle initial state", () => {
expect(testableCounterReducer(undefined, { type: "unknown" })).toEqual({
value: 0,
status: "idle",
});
});
it("should handle increment", () => {
const actual = testableCounterReducer(initialState, increment());
expect(actual.value).toEqual(4);
});
it("should handle decrement", () => {
const actual = testableCounterReducer(initialState, decrement());
expect(actual.value).toEqual(2);
});
it("should handle incrementByAmount", () => {
const actual = testableCounterReducer(initialState, incrementByAmount(2));
expect(actual.value).toEqual(5);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment