Jsdom: Posting a form.

Created on 6 Jan 2011  路  6Comments  路  Source: jsdom/jsdom

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?

feature

Most helpful comment

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

All 6 comments

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

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.

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

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

Any changes with this?

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jhegedus42 picture jhegedus42  路  4Comments

potapovDim picture potapovDim  路  4Comments

philipwalton picture philipwalton  路  4Comments

amfio picture amfio  路  3Comments

cg433n picture cg433n  路  3Comments