testing-library / vue-testing-library

🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
http://testing-library.com/vue
MIT License
1.08k stars 110 forks source link

fireEvent click on disabled button fired #208

Closed hxgqh closed 3 years ago

hxgqh commented 3 years ago
<button disabled="disabled">button</button>
await fireEvent.click(btn);
const clickEvent = emitted().click;
// The following test fail. It SHOULD success.
expect(!!clickEvent).toBe(false);
afontcu commented 3 years ago

Hi,

Just ran it locally and it passes, as expected. Maybe your test is failing due to something else?

afontcu commented 3 years ago

Closing as this doesn't look like a library issue. Feel free to reopen if it's not the case! :)

igbominadeveloper commented 2 years ago

I am currently dealing with this issue.

igbominadeveloper commented 2 years ago
const Component = {
      template: `<button :disabled="disabled" @click="handleClick">Click Me</button>`,
      props: ['disabled'],
      methods: {
        handleClick() {
          this.$emit('save')
        },
      },
    }

    const { getByText, emitted, debug } = render(Component, {
      props: {
        disabled: true,
      },
    })

    const saveButton = getByText('Click Me')
    await fireEvent.click(saveButton)
    expect(emitted('save').length).toBe(0)
igbominadeveloper commented 2 years ago

The test is failing

afontcu commented 2 years ago

Hi,

this is expected (albeit counterintuitive): https://github.com/testing-library/dom-testing-library/pull/217