assaf / zombie

Insanely fast, full-stack, headless browser testing using node.js
http://zombie.js.org/
MIT License
5.65k stars 518 forks source link

pressButton on <button type="button"> incorrectly submits the form #1190

Open arturog opened 5 years ago

arturog commented 5 years ago

When pressing a <button type="button"> contained within a <form>, the form is incorrectly submitted. <button type="button"> should not by default submit the form as per specs.

(I believe this is a jsdom problem...)

arturog commented 5 years ago

OK, I think the problem is in Zombie:

  1. when pressButton is called, the event is correctly dispatched https://github.com/assaf/zombie/blob/bbcd5a6b4c31ecc2bd697d48c0e56086ab7d0b8a/src/index.js#L360-L366

  2. But after dispatching the event, we call _click, which submits the form always. https://github.com/assaf/zombie/blob/bbcd5a6b4c31ecc2bd697d48c0e56086ab7d0b8a/src/dom/forms.js#L241-L250

I think the correct place to disable the submission would be the _click function. @assaf if you're happy to put the check in _click I can send a small patch.

assaf commented 5 years ago

Yes, please send a path