generated from iamogbz/node-js-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
90 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import { useDispatch } from "src"; | ||
import { createContextWithValue } from "src/createContext"; | ||
|
||
describe("useDispatch", () => { | ||
it("uses dispatch from Context", () => { | ||
const dispatch = jest.fn(); | ||
const context = createContextWithValue<unknown, string, string>({ | ||
dispatch, | ||
}); | ||
const ACTION_TYPE = "ACTION_TYPE" as const; | ||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
const actionCreator = (payload?: string) => ({ | ||
type: ACTION_TYPE, | ||
payload, | ||
}); | ||
const { result } = renderHook(() => | ||
useDispatch(actionCreator, context), | ||
); | ||
const arg0 = "Some argument"; | ||
result.current(arg0); | ||
expect(dispatch).toHaveBeenCalledTimes(1); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: ACTION_TYPE, | ||
payload: arg0, | ||
}); | ||
}); | ||
|
||
it.each` | ||
actionCreator | ||
${"non function"} | ||
${null} | ||
${undefined} | ||
`("fails to use dispatch with actionCreator", ({ actionCreator }) => { | ||
const dispatch = jest.fn(); | ||
const context = createContextWithValue<unknown, string, string>({ | ||
dispatch, | ||
}); | ||
const { result } = renderHook(() => | ||
useDispatch(actionCreator, context), | ||
); | ||
expect(() => result.current).toThrow("Unable to bind action creator"); | ||
}); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type Nullable<T> = T | null | undefined; |