Commit 49016d2b authored by David O'Regan's avatar David O'Regan

Merge branch 'add-find-all-by-test-id-helper' into 'master'

Add findAllByTestId Helper to Extended Wrappers

See merge request gitlab-org/gitlab!54497
parents 2ccbc432 adce87c6
...@@ -45,9 +45,16 @@ export const extendedWrapper = (wrapper) => { ...@@ -45,9 +45,16 @@ export const extendedWrapper = (wrapper) => {
return wrapper; return wrapper;
} }
return Object.defineProperty(wrapper, 'findByTestId', { return Object.defineProperties(wrapper, {
value(id) { findByTestId: {
return this.find(`[data-testid="${id}"]`); value(id) {
return this.find(`[data-testid="${id}"]`);
},
},
findAllByTestId: {
value(id) {
return this.findAll(`[data-testid="${id}"]`);
},
}, },
}); });
}; };
...@@ -88,5 +88,22 @@ describe('Vue test utils helpers', () => { ...@@ -88,5 +88,22 @@ describe('Vue test utils helpers', () => {
expect(mockComponent.findByTestId(testId).exists()).toBe(true); expect(mockComponent.findByTestId(testId).exists()).toBe(true);
}); });
}); });
describe('findAllByTestId', () => {
const testId = 'a-component';
let mockComponent;
beforeEach(() => {
mockComponent = extendedWrapper(
shallowMount({
template: `<div><div data-testid="${testId}"></div><div data-testid="${testId}"></div></div>`,
}),
);
});
it('should find all components by test id', () => {
expect(mockComponent.findAllByTestId(testId)).toHaveLength(2);
});
});
}); });
}); });
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