Trying to work out something that I thought would be pretty simple!
I have a PrimeVue checkbox component on my page (and I'm using Vue 3, PrimeVue, vitest, @testing-library/vue and @testing-library/user-event)
<div class="field-checkbox">
<Checkbox role = "checkbox" :aria-label="`Select all students in class ${props.className}`" @change="selectAllChecked()" v-model="selectAll" :binary="true" />
<label>Select All</label>
</div>
I just want to write a test to check the checkbox and then test that it is correctly checked - not a particularly meaningful test but I'm new to these libraries (and unit testing) so want to work out how to do this stuff.
In my test I have:
it("checkbox test", async() => {
const ariaLabel = `Select all students in class ${mockProps.className}`;
const checkbox = screen.getByRole("checkbox", { name: ariaLabel });
await userEvent.click(checkbox);
expect(checkbox.getAttribute('checked')).toBe(true)
});
if I remove the 3rd and 4th lines, the test passes so it seems to be checking that the checkbox is there ok.
Lines 3 and 4 (I hoped) would allow me to confirm that the checkbox is now checked but my test fails with
AssertionError: expected null to be true // Object.is equality
- Expected "true"
+ Received "null"
on the 4th line
@testing-library/vue, but is there anyway you could try clicking theparentof that? Short explanation on the problem in Cypress + Vuetify can be found here, not sure if it helps