【问题标题】:How to get karma to run a init function first?如何让业力首先运行初始化函数?
【发布时间】:2016-08-13 08:23:32
【问题描述】:

我遇到了一个奇怪的问题,我有一个从 CDN 下拉的 JS 库,在我可以使用它之前,我需要在它上面运行一个 init 函数,然后运行我的测试。有人知道我该怎么做吗?

在我的实际项目中,我首先调用 init 函数,然后从 inits 回调中调用我的其余代码,但我只是不知道如何为测试执行此操作

【问题讨论】:

    标签: karma-runner karma-mocha


    【解决方案1】:

    您可以在 karma 配置中列出 CDN:

    files : [
      'http://theurl.totheserver/thelibrary.js',
    

    那么假设库有一个以回调函数为参数的初始化函数:

    describe("My tests", function() {  
    
     before(function(done) {
      myLibrary.initialization(done);
     });
    
     describe("My test cases", function() {
    

    但是我会考虑使用 Bower 来管理您的前端依赖项,而不是依赖 CDN。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-02
      • 2015-10-06
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多