[英]Qunit fail with TypeError: $ is not a function
我有一个余烬应用程序。 一切正常,需要一个验收测试:
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
并且会破坏我的网站上的模态。
你如何解决这个问题?
答案是因为我正在用ember-cli-rails加载某些资产,这些资产不能用于ember测试。
我必须将jquery + bootstrap.js脚本添加到我的emberApp/tests/index.html
。
现在可以工作了,但这不是一个好方法。 我不应该使用引导程序,而是在没有引导程序的情况下创建自己的模态。 我应该只使用具有正确插件或自己代码的ember。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.