Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing Jasmine spec runner单元测试结果闪烁然后消失_Unit Testing_Jasmine - Fatal编程技术网

Unit testing Jasmine spec runner单元测试结果闪烁然后消失

Unit testing Jasmine spec runner单元测试结果闪烁然后消失,unit-testing,jasmine,Unit Testing,Jasmine,我有这个文件来运行我的单元测试: unit-tests.html: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>Vepo Unit Tests</title> <link rel="stylesh

我有这个文件来运行我的单元测试:

unit-tests.html:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title>Vepo Unit Tests</title>
  <link rel="stylesheet" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
  <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
  <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
  <script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
</head>
<body>
  <!-- #1. add the system.js and angular libraries -->
  <script src="node_modules/zone.js/dist/zone.js"></script>
  <script src="node_modules/reflect-metadata/Reflect.js"></script>
  <script src="node_modules/systemjs/dist/system.src.js"></script>

  <script src="systemjs.config.js"></script>


  <script>
    // #2. Import the spec files explicitly
    Promise.all([
      System.import('js/app/landing-page/landing-page.component.spec.js'),
      System.import('js/app/pipes/my-uppercase.pipe.spec.js')
    ])

      // #3. wait for all imports to load ...
      //     then re-execute `window.onload` which
      //     triggers the Jasmine test-runner start
      //     or explain what went wrong.
      .then(window.onload)
      .catch(console.error.bind(console));
  </script>

</body>

</html>

Vepo单元测试
// #2. 显式导入规范文件
我保证([
System.import('js/app/landing page/landing page.component.spec.js'),
System.import('js/app/pipes/my uppercase.pipe.spec.js')
])
// #3. 等待所有导入加载。。。
//然后重新执行'window.onload',其中
//触发Jasmine test runner启动
//或者解释什么地方出了问题。
.then(window.onload)
.catch(console.error.bind(console));
当我用npm start启动服务器,然后在web浏览器中浏览到localhost:3000/unit-tests.html时,它会闪烁两个单元测试的绿色单词(就像通过的测试一样),然后结果就消失了

它并没有说一旦它消失,就找不到单元测试。它就是这样:

没有控制台错误

编辑:重新加载前等待9秒:

  <script>
    Promise.all([
      System.import('js/app/landing-page/landing-page.component.spec'),
      System.import('js/app/pipes/my-uppercase.pipe.spec')
    ]).then(setTimeout(window.onload, 9000)).catch(console.error.bind(console));
  </script>

我保证([
System.import('js/app/landing page/landing page.component.spec'),
System.import('js/app/pipes/my uppercase.pipe.spec')
]).then(setTimeout(window.onload,9000)).catch(console.error.bind(console));
使测试结果显示9秒,然后消失

但是,答案不是取消承诺,而是直接导入测试脚本,因为如果脚本是比几行代码更大的测试,那么就找不到脚本

问题是,当窗口重新加载时,所有内容都会消失。但是如果没有重新加载,它就找不到大型单元测试。它能找到小的


如何防止测试结果在重新加载窗口时消失?

可能我们遇到了一些竞争条件,可以通过异步
boot.js
文件加载来解决

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <title>Vepo Unit Tests</title>
  <link rel="stylesheet" href="node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
  <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
  <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
  <script src="node_modules/zone.js/dist/zone.js"></script>
  <script src="node_modules/reflect-metadata/Reflect.js"></script>
  <script src="node_modules/systemjs/dist/system.src.js"></script>
  <script src="systemjs.config.js"></script>
</head>
<body>
  <script>
    System.import('node_modules/jasmine-core/lib/jasmine-core/boot.js')
      .then(function() {
        return Promise.all([
          System.import('./spec/first.spec.js'),
          System.import('./spec/second.spec.js')
        ])
      })
      .then(function() {window.onload()})
      .catch(console.error.bind(console));
  </script>

</body>
</html>

Vepo单元测试
System.import('node_modules/jasmine-core/lib/jasmine-core/boot.js')
.然后(函数(){
回报你的承诺([
System.import('./spec/first.spec.js'),
System.import('./spec/second.spec.js')
])
})
.then(函数(){window.onload()})
.catch(console.error.bind(console));
看起来很有希望:

我不知道为什么会这样……这不是一个真正的答案,只是一个解决办法

当我在终端中运行“npmtest”时,它会打开unit-tests.html,它们会正常运行,结果会显示在屏幕上


我打算进行最基本的设置,我认为它的工作方式不太基本,但可能更好。

不幸的是,它似乎无法使它工作。我的控制台什么也没说。不是XHR Get您是否在本地web服务器上运行它?尝试解决XHR请求的问题,因为这是所需的基本功能。我在控制台中没有任何错误,所以它仍然可能是XHR请求问题吗?这再次阻碍了我,因为我下面的解决方案已停止工作。这似乎是一个承诺不起作用的问题。虽然它显示了其中一个测试文件结果3次,但实际上现在似乎起作用了。要回答这个问题有点困难,因为这只是配置设置的大量尝试和错误,我不确定是什么让它工作