How to unit test form output with Jasmine

I’m learning unit testing with Jasmin. Have been able t test everything but I am stuck on form. This is the test I am trying to run

  it('should trigger form', function(){
    document.body.innerHTML += '<form><input value="get milk" /><button type="submit" /></form>'
    const form = document.getElementsByTagName('form')[0]
    const value = ''
    form.addEventListener('submit', function(e){
      e.preventDefault();
      console.log('it happened')
      const input = document.querySelector('input').value
    })
    setTimeout(function(){form.submit()}, 3000)
    expect(value).toEqual(result)
    // Then I'll remove the form from the dom
  })

I simplified it to get to the point that I don’t know how to trigger the form without reloading the page. I am trying to test if when the form is submitted something happens.

I assume the form has to be submitted automatically, why I did by form.submit (I added the timer as I thought it make a different).

Is there something missing or is it totally wrong?

Currently you are testing that the web browser is capable of submitting a form. That is a test that seems to belong to browser development tests and doesn’t seem to have anything to do with the testing code that you have written.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.