Last active
December 11, 2021 18:31
-
-
Save jasonleehodges/ee0206d991d9a93ebae5496c24fb7fd1 to your computer and use it in GitHub Desktop.
Unit Tests for Reducer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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