daybrush / selecto

Selecto.js is a component that allows you to select elements in the drag area using the mouse or touch.
https://daybrush.com/selecto
MIT License
2.04k stars 82 forks source link

Testing Selecto in react with jest #83

Open PhilippJunginger opened 2 years ago

PhilippJunginger commented 2 years ago

Environments

Description

Hello!

I am currently trying to Test the behaviour of the Selecto-Component. I implemented a feature, where the User enters a select-mode after a button click. In the select-mode the user can click or drag-to-select items to add them to a selectedItems-state.

While Testing: When I click an Item with userEvent after I have clicked the button for select-mode, I get the Error that

'TypeError: document.elementFromPoint is not a function' and the test fails on the userEvent. If I replace it with fireEvent.click instead of userEvent.click it runs through.

However, when trying to test the dragging with fireEvent.mouseDown/mouseMove/mouseUp, I get the TypeError again that elementFromPoint is not defined.

Does anyone have experience with testing Selecto and can help me out?

Thanks!

daybrush commented 2 years ago

selecto's new version is released. Check it again.

PhilippJunginger commented 2 years ago

Thank you for the update @daybrush . I am still experiencing the TypeError for elementFromPoint. There has been a small change, it doesn't say 'document.elementFromPoint is not a function'' but now instead says '_a.elementFromPoint is not a function'.

Can you maybe provide an example of how to test Selecto in jest?

daybrush commented 2 years ago

@PhilippJunginger

I'll check it.

I am doing manual testing. I didn't use tests like jest. I'm looking for a way to disable elementFromPoint.

daybrush commented 2 years ago

@PhilippJunginger

It seems that it was transpiled incorrectly while building. The new version doesn't seem to have any problems.