[英]Ember-cli acceptance test times out on await click(); qunit error: Uncaught (in promise) Error: pushFailure()
我正在嘗試為webapp的登錄頁面創建驗收測試。 除了await click(element)
承諾永遠不會解決之外,一切都快要起作用了:
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(), '/login-success');
console.log('finished', getSettledState());
});
});
如果我按原樣運行此測試,“await btn click”不會登錄控制台,直到它超時。 我也得到了qunit錯誤“Uncaught(in promise)錯誤:pushFailure()斷言在測試上下文之外,在___ at internalStart” (由我添加的下划線)
但是,如果我刪除了await
click(btnSubmit)
調用的部分,則測試成功完成但是,getSettledState()的最后一次檢查會返回:
hasPendingRequests: true
hasPendingTimers: true
hasPendingWaiters: false
hasRunLoop: true
pendingRequestCount: 1
由於存在待處理的請求和計時器,因此即使所有assert()
調用都成功,測試仍會超時。
所以看起來如果我用await click(btnSubmit)
正確運行測試,測試會在click()上超時,但如果我只是調用click(btnSubmit)
,測試就會成功完成,盡管testem或qunit不知道所有測試都完成了。 我究竟做錯了什么?
海市蜃樓登陸終點:
this.post('/login', function(db, request) {
let formData = JSON.parse(request.requestBody);
let auth = this.serialize(db.profiles.all());
if (formData.identification !== auth.data[0].attributes.loginid || formData.password !== auth.data[0].attributes.password) {
return new Response(401, {some: 'header', 'Content-Type': 'application/json'}, {
error_code: "err_loginAuthenticationFail"
});
}
let profile = this.serialize(db.profiles.all());
profile.data[0].attributes.id = profile.data[0].attributes.localid
delete profile.data[0].attributes.localid;
return { ...longAccessTokenObject }
});
海市蜃樓端點運行正常,它驗證我設置的一個用戶/ pw組合,無論是在測試中還是在Chrome中手動使用/ login頁面。
NullVoxPopuli 100%正確。 我跟進了你的懷疑,並且在代碼庫中有一個我不知道沒有解決的ember-concurrency任務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.