Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled property not worked as expected #121

Closed
jmsunseri opened this issue Feb 14, 2021 · 2 comments
Closed

Disabled property not worked as expected #121

jmsunseri opened this issue Feb 14, 2021 · 2 comments

Comments

@jmsunseri
Copy link

I have a button component like this

<script lang="ts">
  export let disabled: boolean = false;
</script>

<button  {disabled} on:click>
 <slot />
</button>

I'm trying to test it like this

it('does disabled work', async () => {
  const { getByRole, component } = render(Button, {
    disabled: true,
  });
  const button = getByRole('button');
  expect(button.hasAttribute('disabled')).toBeTruthy();    <-- passes

  const mock = jest.fn();
  component.$on('click', mock);

  fireEvent.click(button);
  expect(mock).not.toHaveBeenCalled();   <-- fails
});

Shouldn't fireEvent.click(button) try to replicate what would happen if a user tried to click the button?

@benbender
Copy link

bump? I've stumbled about the same issue today...

@yanick
Copy link
Collaborator

yanick commented Mar 31, 2022

@testing-library/svelte pretty much only import 'fireEvent' from @testing-library/dom without any change.

The 'click on disabled' issue is reported on their repo here: testing-library/dom-testing-library#92, which itself tracks the root source to jsdom (jsdom/jsdom#2665)

As this is an upstream problem and there is not much we can do about it, I'll close the issue here.

@yanick yanick closed this as completed Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants