diff --git a/packages/vue-redux/tests/compositions.withTypes.test.tsx b/packages/vue-redux/tests/compositions.with-types.test.tsx similarity index 100% rename from packages/vue-redux/tests/compositions.withTypes.test.tsx rename to packages/vue-redux/tests/compositions.with-types.test.tsx diff --git a/packages/vue-redux/tests/use-dispatch.spec.tsx b/packages/vue-redux/tests/use-dispatch.spec.tsx new file mode 100644 index 0000000..682735c --- /dev/null +++ b/packages/vue-redux/tests/use-dispatch.spec.tsx @@ -0,0 +1,61 @@ +import {describe, it, expect} from "vitest"; +import {defineComponent, h, InjectionKey} from 'vue' +import { + createDispatchComposition, + provideStore as provideMock, + useDispatch, VueReduxContextValue, +} 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(() => { + provideMock({store}); + return () => + }) + + render() + }) + }) + describe('createDispatchComposition', () => { + it("returns the correct store's dispatch function", () => { + const nestedContext = Symbol.for("mock-redux-store") as InjectionKey + const useCustomDispatch = createDispatchComposition(nestedContext) + + const CheckDispatch = defineComponent(() => { + const dispatch = useDispatch(); + const customDispatch = useCustomDispatch(); + expect(dispatch).toBe(store.dispatch) + expect(customDispatch).toBe(store2.dispatch) + + return () => null; + }) + + const InnerApp = defineComponent(() => { + provideMock({store: store2, context: nestedContext}); + return () => + }) + + const App = defineComponent(() => { + provideMock({store}); + return () => + }) + + render() + }) + }) + }) +}) diff --git a/packages/vue-redux/tests/useDispatch.spec.tsx b/packages/vue-redux/tests/useDispatch.spec.tsx deleted file mode 100644 index c2ccee5..0000000 --- a/packages/vue-redux/tests/useDispatch.spec.tsx +++ /dev/null @@ -1,66 +0,0 @@ -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 () => - }) - - render() - }) - }) - // describe('createDispatchComposition', () => { - // it("returns the correct store's dispatch function", () => { - // const nestedContext = - // React.createContext(null) - // const useCustomDispatch = createDispatchComposition(nestedContext) - // const { result } = renderHook(() => useDispatch(), { - // // eslint-disable-next-line react/prop-types - // wrapper: ({ children, ...props }) => ( - // - // - // {children} - // - // - // ), - // }) - // - // expect(result.current).toBe(store.dispatch) - // - // const { result: result2 } = renderHook(() => useCustomDispatch(), { - // // eslint-disable-next-line react/prop-types - // wrapper: ({ children, ...props }) => ( - // - // - // {children} - // - // - // ), - // }) - // - // expect(result2.current).toBe(store2.dispatch) - // }) - // }) - }) -})