Skip to content

Commit

Permalink
Add namespacing tests for 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
maoberlehner committed May 23, 2018
1 parent 50345d6 commit abf74e4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,41 @@ describe(`index`, () => {

expect(commitMock).toBeCalledWith(`updateField`, { path: `bar.baz`, value: `newFieldValue` });
});

describe(`Namespacing`, () => {
test(`It should call the namespaced getter function.`, () => {
const mockGetter = jest.fn();
const objectOfFields = { foo: `foo` };
const mappedFields = mapFields(`fooModule/`, objectOfFields);

mappedFields.foo.get.apply({ $store: { getters: { 'fooModule/getField': mockGetter } } });

expect(mockGetter).toBeCalledWith(`foo`);
});

test(`It should call the namespaced getter function even if no trailing slash is provided.`, () => {
const mockGetter = jest.fn();
const objectOfFields = { foo: `foo` };
const mappedFields = mapFields(`fooModule`, objectOfFields);

mappedFields.foo.get.apply({ $store: { getters: { 'fooModule/getField': mockGetter } } });

expect(mockGetter).toBeCalledWith(`foo`);
});

test(`It should commit the namespaced mutation function.`, () => {
const commitMock = jest.fn();
const objectOfFields = {
foo: `foo`,
bar: `bar.baz`,
};
const mappedFields = mapFields(`fooModule`, objectOfFields);

mappedFields.bar.set.apply({ $store: { commit: commitMock } }, [`newFieldValue`]);

expect(commitMock).toBeCalledWith(`fooModule/updateField`, { path: `bar.baz`, value: `newFieldValue` });
});
});
});

describe(`mapMultiRowFields()`, () => {
Expand Down

0 comments on commit abf74e4

Please sign in to comment.