0

コールバック内にあるテストを実行することは可能ですか? たとえば、私は

System.import("mymodule").then(function(Mymodule) {
  describe("Mymodule", function() {
    it("does something", function() {
      expect(Mymodule.dosomething()).toBeTruthy();
    });
  });
});

このテストは実行されません。単純なものでも同じですsetTimeout

var Mymodule = { dosomething: function(){ return true; } };

setTimeout(function() {
  describe("Mymodule", function() {
    it("does something", function() {
      expect(Mymodule.dosomething()).toBeTruthy();
    });
  });
});

これを行う方法はありますか?それ以外の場合、モジュールを非同期で含む多くの問題があります

4

2 に答える 2

0

私は最終的に問題を解決しました。このファイルを最後のファイルとして含めます。

basePath = "/base/spec/"

modules = []

for own fileName, fileHash of window.__karma__.files
  if fileName.indexOf(basePath) is 0
    isRunner   = fileName.indexOf("spec_runner") >= 0
    isRunner ||= fileName.indexOf("spec_helper") >= 0
    unless isRunner
      moduleName = fileName.replace(basePath, "")
      moduleName = moduleName.replace(".js", "")
      modules.push(path: fileName, name: moduleName)

mappedModules = {}
baseSpecsPath = "http://localhost:9876"
specModules   = []

for module in modules
  mappedModules[module.name] = baseSpecsPath + module.path
  specModules.push(module.name)

System.config
  baseURL: "http://localhost:4567/javascripts/"
  map:     mappedModules

moduleImports = specModules.map (moduleName) ->
  System.import(moduleName)

Promise.all(moduleImports).then ->
  window.__karma__.start     = window.__lastKarmaStart__
  window.__lastKarmaStart__  = null
  delete window.__lastKarmaStart__
  window.__karma__.start()

次のことを行います。

  • カルマ開始機能を一時的に無効にして、null に置き換えます
  • に保存されている各テストを取得し、すべてのテストSystem.registerを実行しますSystem.import
  • すべてのインポートが完了すると、アタッチし__karma__startて実行し、Jasmine を実行します
于 2015-08-20T20:26:45.020 に答える