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?