【问题标题】:how to properly include source files for jasmine-node test runner如何正确包含 jasmine-node 测试运行器的源文件
【发布时间】:2016-04-20 03:29:55
【问题描述】:

我正在使用 jasmine 规范库和 jasmine-node 运行器用于 node.js。运行包含源文件和规范文件的测试(cli 中的命令)的正确方法是什么?

我有一个lib 目录,其中包含我想要包含的源代码和包含测试的unit.spec.js。当我执行以下操作时,出现错误:

Tomasz.Ducin@WAWLT548 MINGW64 ~/Development/json-schema-faker/json-schema-faker (master)
$ ./node_modules/.bin/jasmine-node lib unit.spec.js --noStackTrace --captureExceptions
F.

Failures:

  1) A suite contains spec with an expectation
    Message:
      ReferenceError: booleanGenerator is not defined

Finished in 0.007 seconds
2 Tests, 1 Failures, 0 Skipped

booleanGenerator 定义在 lib 目录中 - 但不知何故它没有被加载...不知道为什么。

CommonJS require 功能是否正确?在 jasmine 运行时我在 cli 中传递的路径是分开的吗?

【问题讨论】:

    标签: javascript node.js unit-testing jasmine


    【解决方案1】:

    您通过命令提示符传递给 jasmine-node 的目录是保存您的规范的文件夹。

    所以是的,您需要 require 在您的规范文件的 lib 目录中定义的附加函数。

    有一篇很好的文章here 构建了传统的计算器项目,你可以看到计算器功能是如何用require 拉进来的。

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 2015-07-19
      • 2019-02-17
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多