Skip to content

Commit

Permalink
test: add first dedicated useDispatch test
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn committed Sep 5, 2024
1 parent 0c95a17 commit a790f5f
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/vue-redux/tests/useDispatch.spec.tsx
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)
// })
// })
})
})

0 comments on commit a790f5f

Please sign in to comment.