I'm trying to create an acceptance test for the login page of a webapp. Everything is almost working, except the await click(element)
promise never resolves:
import { module, test } from 'qunit';
import { visit, currentURL, fillIn, click, waitFor, getSettledState } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { invalidateSession } from 'ember-simple-auth/test-support';
import { setupMirage } from 'ember-cli-mirage/test-support';
module('Acceptance | login', function(hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
test('login page | login success', async function(assert) {
assert.timeout(5000);
console.log('start', getSettledState());
await visit('/login');
assert.equal(currentURL(), '/login');
await waitFor('.btn-primary:disabled');
await fillIn('input[type="text"]', 'mirage');
await fillIn('input[type="password"]', 'password1234');
await waitFor('.btn-primary:not([disabled])', 2000);
console.log('btn enabled');
let btnSubmit = document.querySelector('.btn-primary');
assert.equal(btnSubmit.disabled, false);
await click(btnSubmit);
console.log('await btn click');
await waitFor('.nav-tabs', 4000);
console.log('nav complete');
assert.equal(currentURL(), '/bid-search/planetbids-bids');
console.log('finished', getSettledState());
});
});
If I run this test as-is, "await btn click" doesn't log in the console, until it times-out. I also get the qunit error "Uncaught (in promise) Error: pushFailure() assertion outside test context, in ___ at internalStart" (underscores added by me)
HOWEVER, if I remove the await
part of the click(btnSubmit)
call, the test completes successfully BUT, the last check of getSettledState() returns this:
hasPendingRequests: true
hasPendingTimers: true
hasPendingWaiters: false
hasRunLoop: true
pendingRequestCount: 1
So it looks like if I run the test correctly with await click(btnSubmit)
, the test times out on the click(), but if I just call click(btnSubmit)
, the tests complete successfully, although testem or qunit doesn't know all the tests completed. What am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire