1

emberjs で JQuery セレクターを click() メソッドに渡すと、テスト中に要素がクリックされません。ID と href を持つ要素がクリックされて URL が変更され、ページが変更されたことをアサートする簡単な受け入れテストを作成しようとしています。

<a>要素 id="sidebar-user-profile" にid を追加しましたが、試行click($('#sidebar-user-profile'))すると「エラー: 要素 [オブジェクト オブジェクト] が見つかりません」というエラーが表示されます。ページ上で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>

4

1 に答える 1

1

Click は 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');
  });
});
于 2015-06-05T09:34:37.913 に答える