2016-08-09 29 views
2

我在ember-cli上創建了一個驗收測試,爲了檢查用戶何時在URL上,然後點擊該頁面上的「取消」按鈕,頁面應該被重定向到其他URL。驗收測試重定向到特定的URL

運行測試時,我得到這個錯誤:

"Promise rejected during Redirects to previous URL if cancel button is clicked: Element .close-button not found".

但我有我的模板元素。有人可能會建議我在這裏失蹤或建議我一個文件,我可以閱讀以解決這個錯誤?

這是我的驗收測試:

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

moduleForAcceptance('Acceptance | test/company'); 
test('Redirects to previous URL if cancel button is clicked', function() { 
    return visit('test/company/add').then(function(){ 
     return click('.close-button'); 
    }).then(function(assert){ 
     assert.equal(currentURL(), 'test/company'); 
    }); 
}); 

我想這個測試過,但我不斷收到類似的錯誤:

test('Redirects to previous URL if cancel button is clicked', function(assert) { 
    visit('/test/company/add'); 
    click ('.close-button'); 
    andThen(function() { 
    assert.equal(currentURL(), '/test/company'); 
    }); 
}); 

這是錯誤:

Error: Element .close-button not found.

這是模板的一部分,我有取消按鈕(add.hbs)

<div class="form-add"> 
    <a href="#" class="close-button" {{action 'cancel'}}>Close</a> 
</div> 

這是控制器,其中動作「取消」的定義:

actions: { 
    cancel() { 
     if (this.get('isSaved')) { 
      return; 
     } 
     this.transitionToRoute('test/company'); 
    } 
} 
+0

你嘗試在你的第二個方法把你的點擊andThen()裏面? – iveedee

回答

1

訪問並單擊是測試助手將返回一個promise.Usually你將執行進一步測試,一旦你的承諾已解決。

試着這樣做:

test('Redirects to previous URL if cancel button is clicked', function(assert) { 
    visit('/test/company/add'); 
    andThen(()=>{ 
    click ('.close-button'); 
    andThen(()=>{ 
     assert.equal(currentURL(), '/test/company'); 
    }) 
    }); 
}); 
+0

感謝您的幫助,我嘗試了您的代碼,但仍然收到相同的錯誤。我不知道還有什麼要做。它無法在頁面上找到該元素。 – karinfdez