Commit adce87c6 authored by Andrew Fontaine's avatar Andrew Fontaine Committed by David O'Regan

Add findAllByTestId Helper to Extended Wrappers

This allows you to find all instances by a `data-testid`, which is about
as handy as `findByTestId`. It is a shortcut to call `findAll` with a
given `data-testid` attribute.
parent 61a32e5e
......@@ -45,9 +45,16 @@ export const extendedWrapper = (wrapper) => {
return wrapper;
}
return Object.defineProperty(wrapper, 'findByTestId', {
return Object.defineProperties(wrapper, {
findByTestId: {
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', () => {
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