-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
720 additions
and
605 deletions.
There are no files selected for viewing
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
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
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,66 @@ | ||
import Vuex from 'vuex'; | ||
import { createLocalVue, shallowMount } from '@vue/test-utils'; | ||
|
||
import { createHelpers, getField, updateField } from './package/src'; | ||
|
||
const localVue = createLocalVue(); | ||
|
||
localVue.use(Vuex); | ||
|
||
const { mapFields } = createHelpers({ | ||
getterType: `getField`, | ||
mutationType: `updateField`, | ||
}); | ||
|
||
describe(`Component initialized with namespaced Vuex module.`, () => { | ||
let Component; | ||
let store; | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
Component = { | ||
template: `<input id="foo" v-model="foo">`, | ||
computed: { | ||
...mapFields(`fooModule`, [ | ||
`foo`, | ||
]), | ||
}, | ||
}; | ||
|
||
store = new Vuex.Store({ | ||
modules: { | ||
fooModule: { | ||
namespaced: true, | ||
state: { | ||
foo: ``, | ||
}, | ||
getters: { | ||
getField, | ||
}, | ||
mutations: { | ||
updateField, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
wrapper = shallowMount(Component, { localVue, store }); | ||
}); | ||
|
||
test(`It should render the component.`, () => { | ||
expect(wrapper.exists()).toBe(true); | ||
}); | ||
|
||
test(`It should update field values when the store is updated.`, () => { | ||
store.state.fooModule.foo = `foo`; | ||
|
||
expect(wrapper.element.value).toBe(`foo`); | ||
}); | ||
|
||
test(`It should update the store when the field values are updated.`, () => { | ||
wrapper.element.value = `foo`; | ||
wrapper.trigger(`input`); | ||
|
||
expect(store.state.fooModule.foo).toBe(`foo`); | ||
}); | ||
}); |
Oops, something went wrong.