I am writing tests in a vue app (using Jest). While testing a certain component, I need to trigger a change event on a checkbox (which I am using BFormCheckbox for).
When I select the checkbox using the selector the actual checkbox evaluates to ('.custom-control-input'), I can get the test below to pass. However, I would like to use the name of the actual component (BFormCheckbox), which I feel would be easier to follow. Is there any way to make this work?
it('is triggered by clicking a phase checkbox', () => {
// I would like to write:
// const phaseCheckbox = wrapper.find(BFormCheckbox);
// However, I can only get the following to work:
const phaseCheckbox = wrapper.find('.custom-control-input');
// this is true for both selectors
expect(phaseCheckbox.exists()).toBe(true);
phaseCheckbox.trigger('change');
// this fails for wrapper.find(BFormCheckbox)
expect(togglePhaseSpy).toHaveBeenCalled();
});
BFormCheckboxgenerates HTML with the hidden checkbox nested inside. Try this:const phaseCheckbox = wrapper.find(BFormCheckbox).find('input'). This will work also when rendered in plain mode, button mode, and switch mode, as you are not tying it to a specific class name.b-form-checkboxhere.BFormCheckboxcomponent?