Testing interim states with the latest test-helpers


#1

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?


#2

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');
  });

#3

Simply beautiful :heart:

Thanks @rwjblue!


#4

I just pushed a proposal to ember-cli-mirage to better support that use cases: https://github.com/samselikoff/ember-cli-mirage/issues/1344 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!