Skip to content

Commit 62e0d80

Browse files
committed
Enable inline namespaces for created helpers
1 parent 2a18415 commit 62e0d80

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export const mapMultiRowFields = normalizeNamespace((
9393
export const createHelpers = ({ getterType, mutationType }) => ({
9494
[getterType]: getField,
9595
[mutationType]: updateField,
96-
mapFields: fields => mapFields(fields, getterType, mutationType),
97-
mapMultiRowFields: paths => mapMultiRowFields(paths, getterType, mutationType),
96+
mapFields: normalizeNamespace((namespace, fields) =>
97+
mapFields(namespace, fields, getterType, mutationType)),
98+
mapMultiRowFields: normalizeNamespace((namespace, paths) =>
99+
mapMultiRowFields(namespace, paths, getterType, mutationType)),
98100
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import Vuex from 'vuex';
2+
import { createLocalVue, shallowMount } from '@vue/test-utils';
3+
4+
import { createHelpers, getField, updateField } from './package/src';
5+
6+
const localVue = createLocalVue();
7+
8+
localVue.use(Vuex);
9+
10+
const { mapFields } = createHelpers({
11+
getterType: `getField`,
12+
mutationType: `updateField`,
13+
});
14+
15+
describe(`Component initialized with namespaced Vuex module.`, () => {
16+
let Component;
17+
let store;
18+
let wrapper;
19+
20+
beforeEach(() => {
21+
Component = {
22+
template: `<input id="foo" v-model="foo">`,
23+
computed: {
24+
...mapFields(`fooModule`, [
25+
`foo`,
26+
]),
27+
},
28+
};
29+
30+
store = new Vuex.Store({
31+
modules: {
32+
fooModule: {
33+
namespaced: true,
34+
state: {
35+
foo: ``,
36+
},
37+
getters: {
38+
getField,
39+
},
40+
mutations: {
41+
updateField,
42+
},
43+
},
44+
},
45+
});
46+
47+
wrapper = shallowMount(Component, { localVue, store });
48+
});
49+
50+
test(`It should render the component.`, () => {
51+
expect(wrapper.exists()).toBe(true);
52+
});
53+
54+
test(`It should update field values when the store is updated.`, () => {
55+
store.state.fooModule.foo = `foo`;
56+
57+
expect(wrapper.element.value).toBe(`foo`);
58+
});
59+
60+
test(`It should update the store when the field values are updated.`, () => {
61+
wrapper.element.value = `foo`;
62+
wrapper.trigger(`input`);
63+
64+
expect(store.state.fooModule.foo).toBe(`foo`);
65+
});
66+
});

0 commit comments

Comments
 (0)