【问题标题】:Angularjs - How to import Bootstrap into Karma-Jasmine for testingAngularjs - 如何将 Bootstrap 导入 Karma-Jasmine 进行测试
【发布时间】:2018-08-30 03:53:22
【问题描述】:

我有一个指令,它从 bootstrap.min.js 调用一个方法,当我编写一个测试文件来测试它时,它会呈现错误,说我使用的函数没有定义。我认为导致此错误的原因是因为我没有在测试环境中包含 Bootstrap。我在 Google 上搜索了很多次,但没有找到让 Bootstrap 与 Karma-Jasmine 一起工作的方法。有没有人知道如何做到这一点?

【问题讨论】:

    标签: angularjs unit-testing bootstrap-4 angular-ui-bootstrap karma-jasmine


    【解决方案1】:

    如果您将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",
    

    注意文件的相对路径正确。也许你需要在开头添加或省略../

    【讨论】:

    • 谢谢,我总是用 Karma 把头撞到墙上,这很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 2014-05-04
    • 2013-09-29
    • 1970-01-01
    • 2014-09-20
    • 2013-05-15
    • 2019-02-17
    相关资源
    最近更新 更多