1

I made my first acceptance test with Ember CLI. I use Ember Mirage to mock the server.

  test('create file', function(assert){
    visit('/login');
    fillIn('input[name=username]', 'Joe');
    fillIn('input[name=password]', 'foo');
    click('button');

    andThen(function() { 
      visit('/projects/files');
    });

    andThen(function(){
      assert.ok(true);
    })  
  });

The test runs successfully, but it hangs, and I am getting the following error

Uncaught (in promise) Error: Called stop() outside of a test context

at Object.stop (http://localhost:4200/assets/test-support.js:2469:10) at Class.asyncStart (http://localhost:4200/assets/vendor.js:49507:13) at asyncStart (http://localhost:4200/assets/vendor.js:41446:44) at Object.async (http://localhost:4200/assets/vendor.js:41460:7) at fulfill (http://localhost:4200/assets/vendor.js:61624:26) at handleMaybeThenable (http://localhost:4200/assets/vendor.js:61584:9) at resolve (http://localhost:4200/assets/vendor.js:61597:7) at sealed (http://localhost:4200/assets/vendor.js:61536:11)

Ajax service

I use an ajax service, which makes calls to custom api endpoints. As you can see it uses the standard JSONAPISerializer. Could be still a problem ? This is an existing app, and there is no easy way to turn off this service, to test without it.

export default Ember.Service.extend({
  // http://stackoverflow.com/questions/9705773/non-crud-actions-with-ember-data
  call: function(method, type, id, action, hash = null){
    var owner = Ember.getOwner(this);
    var adapter = owner.lookup('adapter:application');
    var url = adapter.buildURL(type, id) + '/' + action;
    if (hash) {
      hash.data = $.extend({}, hash);
    }
    return adapter.ajax(url, method, hash);

  }
});

EDIT 1

I have changed the test slightly + turned on ENV.APP.LOG_TRANSITIONS_INTERNAL and ENV.APP.LOG_TRANSITIONS to see better whats going on:

$.Velocity.mock = true
var done = assert.async();
visit('/login');
fillIn('input[name=username]', 'Joe');
fillIn('input[name=password]', 'foo');
click('button');

andThen(function() { 
  visit('/projects/files/new/overview');
  setTimeout(function() {
    assert.equal( find('.btn-primary').length, 2,"button was found" );
    done();
  }, 20000);
});

It looks like the login works fine, then

Transition #2: projects.files.new.overview.index: calling deserialize hook ember.debug.js:51061 Transition #2: projects.files.new.overview.index: calling afterModel hook ember.debug.js:51061 Transition #2: Resolved all models on destination route; finalizing transition. ember.debug.js:6520 generated -> controller:projects Object {fullName: "controller:projects"}

tells me, that the transition was ok, and I can see the new page in qunit's container.

sometimes I also receive

Uncaught Error: Assertion Failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in a run

user3568719
  • 1,036
  • 15
  • 33
  • I think you'll need to use QUnit's async feature... https://api.qunitjs.com/async/ – Jordan Kasper Sep 07 '16 at 17:44
  • @jakerella thanks. could you please give some more info? Should I set x ms in setTimeout till /projects/files 's html appears? Do you have a hunch, why this could happen? – user3568719 Sep 07 '16 at 19:01
  • This error: "Uncaught Error: Assertion Failed: You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in a run" is probably because you're using `setTimeout`, use `Ember.run.later` instead – Piotr Sep 08 '16 at 14:19
  • @awpeter I have searched through my app folder, but there is no setTimeout in the code. – user3568719 Sep 08 '16 at 14:33
  • You have it in the EDIT1 code, it's what I was referring to – Piotr Sep 08 '16 at 15:21
  • @awpeter ah ok, get it. actually I had occasionally that error before the setTimeout too. – user3568719 Sep 08 '16 at 16:01

0 Answers0