Testing interim states with the latest test-helpers

I’m sure it used to be possible to do something like this:

let promise = fillIn('.some-field', 'Some value');

assert.ok(someInterimState);

await promise;

// ...

But all the helpers in @ember/test-helpers appear to be wrapped in a nextTickPromise so nothing happens synchronously. Is there any way to achieve the above these days?

You would use waitFor or waitUntil for this. Those helpers intentionally do not wait for “settledness” before continuing.

Here is an example test in @ember/test-helpers that shows what I mean:

  test('can check element while waiting for settled state', async function(assert) {
    let deferred = defer();
    this.set('promise', deferred.promise);

    // Does not use `await` intentionally
    let renderPromise = render(hbs`{{promise-wrapper promise=promise }}`);

    await waitFor('.loading');

    assert.equal(this.element.textContent, 'Please wait', 'has pending content');

    deferred.resolve('Yippie!');

    await renderPromise;

    assert.equal(this.element.textContent, 'Yippie!', 'has fulfillment value');
  });
1 Like

Simply beautiful :heart:

Thanks @rwjblue!

I just pushed a proposal to ember-cli-mirage to better support that use cases: Proposal: defer requests to improve testing pending states · Issue #35 · miragejs/discuss · GitHub Basically it let you defer a response after all tests of pending states are done. Would appreciate any feedback.

By the way waitFor and waitUntil test helpers are awesome!