-
-
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 test for useDispatch's context passing
- Loading branch information
1 parent
f9c07f6
commit 968fe51
Showing
3 changed files
with
61 additions
and
66 deletions.
There are no files selected for viewing
File renamed without changes.
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,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/>) | ||
}) | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.