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

Posting a form. #123

Open
thimbl opened this issue Jan 6, 2011 · 8 comments
Open

Posting a form. #123

thimbl opened this issue Jan 6, 2011 · 8 comments
Labels

Comments

@thimbl
Copy link

thimbl commented Jan 6, 2011

Having trouble figuring out how to post a form using jsdom and jquery. is this possible?

var form = '

';
$(form).appendTo('body');
$('form').submit();

The above doesn't work for me, should it, or am I doing something wrong?

@tmpvar
Copy link
Member

tmpvar commented Jan 6, 2011

not yet, there are no default actions at this time.

@domenic
Copy link
Member

domenic commented Jul 3, 2016

This is probably much easier to implement now that I've implemented the form data algorithm (in FormData-impl.js). However the navigation after the form submission would of course still not work.

@josenobile
Copy link

After form is submitted, how to read the response body? For example resourceLoader did not trigger anything after a submitted form in a iframe.

@domenic
Copy link
Member

domenic commented Apr 18, 2017

Form submission is not currently implemented, so it is not possible.

@BebeSparkelSparkel
Copy link

Any changes with this?

@marvinrabe
Copy link

marvinrabe commented Nov 21, 2018

It looks like form submission is partially implemented. It dispatches a HTMLEvent but does not support the submit method.

Minimal reproduction

As a Mocha + Chai test:

import {JSDOM} from 'jsdom'
import {assert} from 'chai'
import sinon from 'sinon'

describe('JSDOM Form', () => {

    it('submit form with button', () => {
        const dom = new JSDOM(`
  <form id="my-form">
    <button type="submit" id="submit-button">Submit Button</button>
  </form>
`, {})
        const listener = sinon.stub()
        dom.window.document.getElementById('my-form').addEventListener('submit', listener)

        dom.window.document.getElementById('submit-button').click()

        assert.isTrue(listener.called)
    })

})

What is expected?

Submit works without any errors.

What happens?

Test succeeds but returns this error:

Error: Not implemented: HTMLFormElement.prototype.submit

@ScubaDaniel
Copy link

Is this ever going to be addressed? I can't find a single work-around for "react-testing-library" + Jest that actually makes sense and works.

@salazarm

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants