Commit 3f71e91a authored by peterhegman's avatar peterhegman

Switch to using vm.$options.provide() to check provide/inject

Instead of using `_provided`
parent 9b62b6af
......@@ -56,15 +56,5 @@ export const extendedWrapper = (wrapper) => {
return this.findAll(`[data-testid="${id}"]`);
},
},
// Returns attributes provided to the component via provide/inject
// https://vuejs.org/v2/api/#provide-inject
provided: {
value(key) {
// eslint-disable-next-line no-underscore-dangle
const provided = this.vm?._provided || {};
return key ? provided[key] : provided;
},
},
});
};
......@@ -105,52 +105,5 @@ describe('Vue test utils helpers', () => {
expect(mockComponent.findAllByTestId(testId)).toHaveLength(2);
});
});
describe('provided', () => {
let wrapper;
beforeEach(() => {
wrapper = extendedWrapper(
shallowMount({
template: '<div>mock component</div>',
provide: { fooBar: 'baz', company: 'GitLab' },
}),
);
});
describe('when called without `key` argument', () => {
it('returns an object of provided attributes', () => {
expect(wrapper.provided()).toEqual({ fooBar: 'baz', company: 'GitLab' });
});
});
describe('when called with `key` argument', () => {
describe('when `key` exists in provided attributes', () => {
it('returns value of provided attribute', () => {
expect(wrapper.provided('fooBar')).toBe('baz');
});
});
describe('when `key` does not exist in provided attributes', () => {
it('returns `undefined`', () => {
expect(wrapper.provided('invalidKey')).toBeUndefined();
});
});
});
describe('when no attributes are provided', () => {
beforeEach(() => {
wrapper = extendedWrapper(
shallowMount({
template: '<div>mock component</div>',
}),
);
});
it('returns an empty object', () => {
expect(wrapper.provided()).toEqual({});
});
});
});
});
});
......@@ -46,7 +46,7 @@ describe('initMembersApp', () => {
it('sets `currentUserId` in provide/inject', () => {
setup();
expect(wrapper.provided('currentUserId')).toBe(123);
expect(vm.$options.provide().currentUserId).toBe(123);
});
describe('when `gon.current_user_id` is not set (user is not logged in)', () => {
......@@ -54,20 +54,20 @@ describe('initMembersApp', () => {
window.gon = {};
setup();
expect(wrapper.provided('currentUserId')).toBeNull();
expect(vm.$options.provide().currentUserId).toBeNull();
});
});
it('parses and sets `data-source-id` as `sourceId` in provide/inject', () => {
setup();
expect(wrapper.provided('sourceId')).toBe(234);
expect(vm.$options.provide().sourceId).toBe(234);
});
it('parses and sets `data-can-manage-members` as `canManageMembers` in Vuex store', () => {
setup();
expect(wrapper.provided('canManageMembers')).toBe(true);
expect(vm.$options.provide().canManageMembers).toBe(true);
});
it('parses and sets `members` in Vuex store', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment