Currently, I am facing an issue while using qUnit and mockjax to handle a basic async form submission. It seems like the async POST request is passing through mockjax for some reason.
test 'RuleModal closes the modal on a successful form submission event', ->
$.mockjax
dataType: 'json'
url: '/url'
type: 'post'
responseText:
status: 'success'
$dom = $('<div class="show-modal"><form action="/url" method="post"></form></div>')
$form = $dom.find('form')
modal = new RuleModal($dom)
$form.submit()
equal $($dom).hasClass('show-modal'), false, 'closes the modal after form submission'
In addition to this, here is the implementation:
_bindSubmit: ->
modal = this
@$modal.find('form').on 'submit', (event) ->
event.preventDefault()
$.ajax
dataType: 'json'
url: @action
type: @method
data: $(this).serialize()
success: (data, status, xhr) ->
modal.close()
error: (xhr, status, error) ->
alert 'Something went wrong: ' + error
Despite trying to hardcode the implementation to match the test exactly, it still doesn't seem to work. Can you help me figure out what I might be doing incorrectly?