Skip to content

Commit

Permalink
test: add test for useDispatch's context passing
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn committed Sep 5, 2024
1 parent f9c07f6 commit 968fe51
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 66 deletions.
61 changes: 61 additions & 0 deletions packages/vue-redux/tests/use-dispatch.spec.tsx
Original file line number Diff line number Diff line change
@@ -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 () => <Comp/>
})

render(<App/>)
})
})
describe('createDispatchComposition', () => {
it("returns the correct store's dispatch function", () => {
const nestedContext = Symbol.for("mock-redux-store") as InjectionKey<VueReduxContextValue | null>
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 () => <CheckDispatch/>
})

const App = defineComponent(() => {
provideMock({store});
return () => <InnerApp/>
})

render(<App/>)
})
})
})
})
66 changes: 0 additions & 66 deletions packages/vue-redux/tests/useDispatch.spec.tsx

This file was deleted.

0 comments on commit 968fe51

Please sign in to comment.