我有一个从bootstrap.min.js调用方法的指令,当我编写测试文件来测试它时,它会呈现错误,说我使用的函数没有定义。我认为导致此错误的原因是因为我在测试环境中没有包含Bootstrap。我在Google上搜索了很多次但是没有找到让Bootstrap与Karma-Jasmine一起工作的方法。有没有人知道如何做到这一点?
如果你将files
添加到你的karma.conf.js
它应该工作。例子来自here。
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
singleRun: false,
files: [
"../node_modules/bootstrap/bootstrap.min.css",
"../node_modules/jquery/dist/jquery.min.js"
]
});
};
如果您使用Bower或其他一些软件包管理器,只需更改路径,例如
"bower_components/jquery/dist/jquery.js",
注意拥有正确的文件相对路径。也许你需要在开头添加或省略../