我有我認爲是3個非常簡單的測試。組件測試Ember-CLI與{{link-to}}助手
1)檢查一個組件呈現屬性(燼-CLI自動生成此)
2)點擊其導航到 'user.index' 路線的類(這是一個{{鏈接到}})
3)點擊其中導航到「brands.index」路線的一類(這是一個{{鏈接到}})
我可以確認的是航線訪問,當我在瀏覽器中點擊它們,但是,測試失敗。儘管指定了「品牌鏈接」,但「品牌。索引」測試仍在期待「users.index」。
任何幫助將不勝感激!
的測試如下:
import {
moduleForComponent,
test
} from 'ember-qunit';
moduleForComponent('navigation-bar', 'NavigationBarComponent', {
// specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar']
});
test('it renders', function() {
expect(2);
// creates the component instance
var component = this.subject();
equal(component._state, 'preRender');
// appends the component to the page
this.append();
equal(component._state, 'inDOM');
});
test('it can navigate to users', function() {
expect(3);
var component = this.subject();
equal(component._state, 'preRender');
this.append();
equal(component._state, 'inDOM');
click('.users-link');
andThen(function() {
equal(currentRouteName(), 'users.index');
});
});
test('it can navigate to brands', function() {
expect(3);
var component = this.subject();
equal(component._state, 'preRender');
this.append();
equal(component._state, 'inDOM');
click('.brands-link');
andThen(function() {
equal(currentRouteName(), 'brands.index');
});
});
和組件模板是:
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<!--<img alt="Brand" src="...">-->
</a>
</div>
<ul class="nav navbar-nav">
{{#link-to 'users' tagName='li' classNames='users-link'}}<a href="#">Users</a>{{/link-to}}
{{#link-to 'brands' tagName='li' classNames='brands-link'}}<a href="#">Brands</a>{{/link-to}}
</ul>
</div>
</nav>
沒有回答你的問題,但是在使用鏈接時你不需要添加'a'標籤。 – kaungst 2014-11-23 12:56:49