2016-04-19 62 views
2

我正在使用jasmine規範庫以及jasmine-node runner for node.js.運行測試(cli中的命令)的正確方法是什麼?它們都包含源文件和spec文件?如何正確包含jasmine-node測試運行器的源文件

我有一個lib目錄與我想要包括的來源和unit.spec.js包括測試。當我這樣做,我得到一個錯誤:

[email protected] 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 

booleanGeneratorlib目錄中定義的 - 但不知何故,它不會加載......說不上來爲什麼。

CommonJS require功能是否正確?我在jasmine運行時將cli傳遞的路徑分開了嗎?

回答

2

您通過命令提示傳遞給jasmine-node的目錄是保存規格的文件夾。

所以是的,你需要require你在spec目錄下的lib目錄中定義的附加函數。

有一篇很好的文章here傳統計算器項目的構建過程中,您可以看到計算器功能是如何與require一起拉入的。

相關問題