mercredi 18 janvier 2017

Ember acceptance testing - async side effects error

Attempting to run acceptance tests in Ember:

test('successful login', (assert) => {

  Ember.run(() => {
    visit('/signin');
    fillIn('#email', 'validemail@server.com');
    fillIn('#password', 'password');
    click(':submit');

    andThen(function() {
      assert.equal(currentURL(), '/');
    });
  });
});

Occasionally (and seemingly randomly) yields the error:

"Global error: 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..."

I was able to get a working version:

test('successful login', (assert) => {
  const done = assert.async();

  Ember.run(() => {
    visit('/signin').then(() => {
      fillIn('#email', 'isaac@silverorange.com').then(() => {
        fillIn('#password', 'keen').then(() => {
          click(':submit').then(() => {
            assert.equal(currentURL(), '/');
            done();
          });
        });
      });
    });
  });
});

However, if I include a second test making use of the same route (for an unsuccessful login), one of them almost always ends up with the error listed above.

I am wondering what I am not understanding about the run-loop, Ember.run, and how to test with async behavior. Any help or pointers towards a good resource would be greatly appreciated!




Aucun commentaire:

Enregistrer un commentaire