Last active
December 11, 2021 19:40
-
-
Save jasonleehodges/7b1ff8d27a33dc73ade98d3580f6732c to your computer and use it in GitHub Desktop.
Selector Example with Currying and Selector Unit Tests
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 React from "react"; | |
import { useSelector } from "react-redux"; | |
import {selectCountFormatted} from './selectors' | |
export const Counter = () => { | |
const countFormattedAsDollars = useSelector(selectCountFormatted('$')); | |
... |
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
describe("counter selectors", () => { | |
const state: RootState = { | |
counter: { | |
value: 3, | |
status: "idle", | |
}, | |
}; | |
it("should format count in dollars", () => { | |
const actual = selectCountFormatted("$")(state); | |
expect(actual).toEqual("$3"); | |
}); | |
it("should format count as a percentage", () => { | |
const actual = selectCountFormatted("%")(state); | |
expect(actual).toEqual("3%"); | |
}); | |
it("should select multiple items from state", () => { | |
const actual = selectCountAndStatus(state); | |
expect(actual).toEqual("The current count is 3 and the status is idle"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment