-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add first dedicated useDispatch test
- Loading branch information
1 parent
0c95a17
commit a790f5f
Showing
1 changed file
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {describe, it, expect} from "vitest"; | ||
import { defineComponent, h } from 'vue' | ||
import { | ||
createDispatchComposition, provideStore, | ||
provideStore as provideMock, | ||
useDispatch, | ||
} from '../src' | ||
import { createStore } from 'redux' | ||
import {render} from "@testing-library/vue"; | ||
|
||
const store = createStore((c: number = 1): number => c + 1) | ||
const store2 = createStore((c: number = 1): number => c + 2) | ||
|
||
describe('Vue', () => { | ||
describe('compositions', () => { | ||
describe('useDispatch', () => { | ||
it("returns the store's dispatch function", () => { | ||
const Comp = defineComponent(() => { | ||
const dispatch = useDispatch(); | ||
expect(dispatch).toBe(store.dispatch) | ||
|
||
return () => null; | ||
}) | ||
|
||
const App = defineComponent(() => { | ||
provideStore({store}); | ||
return () => <Comp/> | ||
}) | ||
|
||
render(<App/>) | ||
}) | ||
}) | ||
// describe('createDispatchComposition', () => { | ||
// it("returns the correct store's dispatch function", () => { | ||
// const nestedContext = | ||
// React.createContext<ReactReduxContextValue | null>(null) | ||
// const useCustomDispatch = createDispatchComposition(nestedContext) | ||
// const { result } = renderHook(() => useDispatch(), { | ||
// // eslint-disable-next-line react/prop-types | ||
// wrapper: ({ children, ...props }) => ( | ||
// <ProviderMock {...props} store={store}> | ||
// <ProviderMock context={nestedContext} store={store2}> | ||
// {children} | ||
// </ProviderMock> | ||
// </ProviderMock> | ||
// ), | ||
// }) | ||
// | ||
// expect(result.current).toBe(store.dispatch) | ||
// | ||
// const { result: result2 } = renderHook(() => useCustomDispatch(), { | ||
// // eslint-disable-next-line react/prop-types | ||
// wrapper: ({ children, ...props }) => ( | ||
// <ProviderMock {...props} store={store}> | ||
// <ProviderMock context={nestedContext} store={store2}> | ||
// {children} | ||
// </ProviderMock> | ||
// </ProviderMock> | ||
// ), | ||
// }) | ||
// | ||
// expect(result2.current).toBe(store2.dispatch) | ||
// }) | ||
// }) | ||
}) | ||
}) |