We're trying to test behavior of a form in our system using konacha and sinon. In the routes, form submission is handled with the following pattern:
save: (object) ->
object.one "didCreate", @, ->
@transitionTo "nextStep"
object.one "becameInvalid", @, ->
object.send("becameValid")
object.one "becameError", @, ->
@transitionTo "currentStep"
object.get("transaction").commit()
This works fine when a real user is interacting with a browser. If our server returns a validation error, the user remains on the same page and the validation errors are displayed correctly. When we try to test this functionality, the form POST never occurs and none of the object.one blocks are called.
We're testing with the following:
describe "When I enter invalid information", ->
beforeEach (done) ->
Em.run ->
$('.button-success').click()
done()
it "should redirect to the current step", ->
Em.run ->
@router.get("url").should.equal "/currentStep"
describe ".help-block", ->
it "should display a validation error", ->
Em.run ->
$('.help-block').text().should.equal "is not a valid, can't be blank"
When I run konacha:serve, I can see the form properly. Clicking on the submit button manually in the iFrame behaves differently than clicking on the submit button in a standalone browser window (in a standalone browser window, I can see the POST occur). My hunch is that this has to do with the POST occurring in the next run loop. If that's true, is there a way for a konacha test to span multiple run loop iterations? How would I advance to the next loop iteration manually?