Ember 2, acceptance testing, websocket pending hangs andThen() wating for pending to finish

158 views Asked by At

I'm starting for the first time in Acceptance testing my Ember application.

So I started from login with this:

test/acceptance/login-test.js:

import { test } from "qunit";
import moduleForAcceptance from "myapp/tests/helpers/module-for-acceptance";

moduleForAcceptance("Acceptance | login");

test("Should login", function(assert) {
  visit("/login");
  fillIn("input[type=email]", "[email protected]");
  fillIn("input[type=password]", "userpass");
  click("button[type=submit]");

  andThen(() => {
    assert.equal(currentURL(), "/");
    assert.equal(find("h1").text(), "Hello!");
  });
});

It never goes in andThen(), so it hangs on click("button[type=submit]");.

I understand why.

In my app/templates/index.hbs I have a component notifications which rely on a websocket which is constantly in pending in my single page application (if I open Chrome there is a pending websocket call...).

If I remove this component from my index.hbs everything works as expected.

After the login I should tell to andThen() helper to ignore the pending state of that service('notifications') which is constantly in pending state?

How to do?

1

There are 1 answers

1
Sandeep On

For me I was facing this because of one polling method I used which was calling my server in few seconds to fetch something. What I did was disable that code when running in test mode

if(!Ember.testing){
  //polling
}

AndThen() basically waits for all your promises to resolved before it executes.