Simplistic Acceptance Testing in Ember.js with Qunit and Ember.model fails to be reliable


The setup is very simplistic attempt at getting an acceptance test ( end to end)

Rails API server with public data set

Ember.model Item

Index Route model: returns RSVP.hash including ‘items’

Controller that runs filter on items model from Index route.

I have a couple other basic tests. (does an element exist on the page)

I’m working off of the documents i’ve found - and this makes sense to me - reset the app before each test.

module "Browse Item",
  setup: ->

My question is why is only a single ajax request being made?

I visit the index 2 times, in a total of 2 tests, once for each test.

I see only a single ajax request in the network tab.

I’m also noticing the following behavior :smile:

all Ajax requests are going all the way down to the Ember.model layer, but the second visit never calls the succeed or failure callback.

defining afterModel or beforeModel (with a promise returned) stops the model from being called altogether - ( this contradicts the documentation)

Of course removing App.reset allows both tests to pass - because the data was fetched a single time.

My instinct is that something in the Ember-Testing / App.reset is breaking the acceptance testing environment.

I suspect I wouldn’t have noticed this if I was mocking out the server.

Any thoughts?

The test error seems to indicate that something about the request is failing:

TypeError: Cannot call method 'get' of undefined
  at Test.QUnitAdapter.Test.Adapter.extend.exception (http://u2u.local:3000/assets/ember.js?body=1:41419:5)
  at superWrapper [as exception] (http://u2u.local:3000/assets/ember.js?body=1:1243:16)
  at Ember.RSVP.onerrorDefault (http://u2u.local:3000/assets/ember.js?body=1:16896:28)
  at Object.__exports__.default.trigger (http://u2u.local:3000/assets/ember.js?body=1:8721:13)
  at Promise._onerror (http://u2u.local:3000/assets/ember.js?body=1:9445:16)
  at Promise.publishRejection (http://u2u.local:3000/assets/ember.js?body=1:9852:17)
  at Object.DeferredActionQueues.flush (http://u2u.local:3000/assets/ember.js?body=1:5897:24)
  at Object.Backburner.end (http://u2u.local:3000/assets/ember.js?body=1:5988:27)


I found the issue after I installed teaspoon and stepped through installing mocha - I was setting jquery ajax preflight in a controller and then it was getting re-used over again after the app was reset.

Mocha is slower to run but moving back and forth gave me a chance to see the bug in a stack trace - neither mocha or qunit had the actual error location in the stack-trace – but that’s more a javascript issue than anything.

The take away… teaspoon helped me figure out that browser state and interaction with localstore from a development environment was causing issue by giving me a hint that there wasn’t anything wrong with the code, but some other interaction - and installing an alternative testing environment gave me a chance to set up the test environment incorrectly and find the exception.

Clearly the exception handling in the adapters of mocha and qunit are a bit subpar so i hope find a way to avoid spending so much time on such a strange issue in the future.