2015-06-05 27 views
0

當在測試時將JQuery選擇器傳遞給emberjs中的click()方法時,該元素不會被單擊。 我想寫一個簡單的驗收測試,其中一個ID和一個href的元素被點擊並且URL更改,然後我斷言該頁面已更改。EmberJS - Click()助手無法按預期方式工作

我將ID添加到<a>元素id =「sidebar-user-profile」,當我嘗試click($('#sidebar-user-profile'))時,出現錯誤「Error:Element [object Object] not found。」。我在頁面上嘗試了同樣的操作,在Chrome的控制檯中輸入$('#sidebar-user-profile')並選擇了確切的元素。

我一直試圖讓這個工作在過去的2周,我沒有選擇。

編輯:下面是有錯誤的測試:

test('exists and works /home/user-profile', function(assert) { 
 
    assert.expect(1); 
 
    click('#sidebar-user-profile'); 
 
    andThen(function() { 
 
    assert.equal(currentURL(), '/home/user-profile'); 
 
    }); 
 
});

<li>{{#link-to 'home.user-profile' id="sidebar-user-profile"}}User Profile{{/link-to}}</li>

+0

'點擊( '#側邊欄的用戶配置文件');' –

+0

記得有包裹在一個'andThen' –

+0

好斷言,現在的錯誤是不是「錯誤:Element [object Object] not found。「,現在是」Error:Element#sidebar-user-profile not found「。 –

回答

0

點擊需要選擇不是一個jQuery對象,你的測試看起來會如:

click('#sidebar-user-profile'); 
andThen(() => { 
    assert.equal(currentURL(), `/myurl/new`, 'Should go to new route'); 
}); 

編輯:

test('exists and works /home/user-profile', function(assert) { 
    visit('/home'); // route where your link-to is located 
    click('#sidebar-user-profile'); 
    andThen(function() { 
    assert.equal(currentURL(), '/home/user-profile'); 
    }); 
}); 
相關問題