Qunit因TypeError而失败:$不是函数

时间:2015-12-11 11:10:52

标签: javascript jquery jquery-ui ember.js

我有一个余烬应用程序。一切正常,需要一次验收测试:

test('delete user 271', function(assert) {
  server.logging = true;
  server.create('user', {id: 271});
  visit('/users/271');

  andThen(function() {
    assert.equal(currentURL(), '/users/271');
    const deleteUSerButton = find(':button.delete-user');
    click(deleteUSerButton);
    andThen(() => assert.equal(find('.modal-body').text().trim(), 'Are you sure you want to remove this user ?'));
  });
});

但我得到TypeError: $ is not a function : at didInsertElement (actionnable-modal.js:10)

export default Ember.Component.extend({
  didInsertElement() {
    jQuery.noConflict();
    let modalContainer = $('#modal-container .modal');
    modalContainer.modal();
    modalContainer.on('hidden.bs.modal', () => {
      this.dismiss();
    }); // line 10
  }
});

测试随机失败的问题。我不知道为什么。我删除了/temp文件夹但没有成功。似乎jquery.noConflict()对我的代码来说是一团糟,但如果我删除这一行:TypeError: modalContainer.modal is not a function并且它会破坏我网站上的模式。

你能解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

答案是因为我用ember-cli-rails加载了一些资产,资产不能用于ember测试。

我必须在我的emberApp/tests/index.html中添加jquery + bootstrap.js脚本。

现在它的工作,但它不是一个好方法。我不应该使用bootstrap但是在没有bootstrap的情况下制作我自己的模态。我应该只使用带有正确插件或自己代码的ember。