Skip to content

Commit a136620

Browse files
committed
test: add tests for useReduxContext
1 parent 968fe51 commit a136620

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

packages/vue-redux/src/compositions/use-redux-context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function createReduxContextComposition(context = ContextKey) {
1515

1616
if (process.env.NODE_ENV !== 'production' && !contextValue) {
1717
throw new Error(
18-
'could not find react-redux context value; please ensure the component is wrapped in a <Provider>',
18+
'could not find vue-redux context value; please ensure the component is wrapped in a <Provider>',
1919
)
2020
}
2121

packages/vue-redux/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './provider/context'
33
export * from './compositions/use-store'
44
export * from './compositions/use-dispatch'
55
export * from './compositions/use-selector'
6+
export * from './compositions/use-redux-context'

packages/vue-redux/src/provider/context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ export interface VueReduxContextValue<
1111
subscription: Subscription
1212
}
1313

14-
export const ContextKey = Symbol.for(`react-redux-context`) as InjectionKey<VueReduxContextValue>
14+
export const ContextKey = Symbol.for(`vue-redux-context`) as InjectionKey<VueReduxContextValue>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {describe, it, expect, vi} from "vitest";
2+
import {
3+
createReduxContextComposition,
4+
useReduxContext,
5+
} from '../src'
6+
import {defineComponent, h} from "vue";
7+
import type {InjectionKey} from "vue";
8+
import {render} from "@testing-library/vue";
9+
10+
describe('Vue', () => {
11+
describe('compositions', () => {
12+
describe('useReduxContext', () => {
13+
it('throws if component is not wrapped in provider', () => {
14+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
15+
16+
const App = defineComponent(() => {
17+
useReduxContext();
18+
return () => null;
19+
})
20+
21+
expect(() => render(<App/>)).toThrow(
22+
/could not find vue-redux context value/,
23+
)
24+
spy.mockRestore()
25+
})
26+
})
27+
describe('createReduxContextHook', () => {
28+
it('throws if component is not wrapped in provider', () => {
29+
const customContext = Symbol.for("testing") as InjectionKey<VueReduxContextValue | null>;
30+
const useCustomReduxContext = createReduxContextComposition(customContext)
31+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
32+
33+
34+
const App = defineComponent(() => {
35+
useCustomReduxContext();
36+
return () => null;
37+
})
38+
39+
40+
expect(() => render(<App/>)).toThrow(
41+
/could not find vue-redux context value/,
42+
)
43+
44+
spy.mockRestore()
45+
})
46+
})
47+
})
48+
})

0 commit comments

Comments
 (0)