我想使用Vows來測試無DOM的JavaScript代碼,理想情況下直接針對編譯後的JS運行。 我的誓言是用CoffeeScript編寫的,但我不確定如何載入我的JS;我已經使用eval
嘗試了它內聯:在Node.js下測試Closure編譯器輸出
vows = require "vows"
assert = require "assert"
eval('var e=this;function f(a,g){var c=a.split("."),b=e;!(c[0]in b)&&b.execScript&&b.execScript("var "+c[0]);for(var d;c.length&&(d=c.shift());)!c.length&&g!==void 0?b[d]=g:b=b[d]?b[d]:b[d]={}}function h(a){a.call(e)};(function(){var a;a={};h(function(){a=function(a){this.a=a};a.prototype.b=function(a){return this.a+a.a};f("Cl.LinearExpression",a);f("Cl.LinearExpression.prototype.plus",a.prototype.b)})}).call(this);');
vows
.describe("Linear Expression")
.addBatch
"initialized with a number":
topic: -> new Cl.LinearExpression 5
"adds up with scalar": (cle) -> assert.equal 7, cle.plus 2
.export(module)
,但我得到「的ReferenceError:氯沒有定義」。 在瀏覽器控制檯中運行縮小的JS和new Cl.LinearExpression(5);
可以正常工作,因此編譯後的代碼沒問題。 將JS加載到節點進行Vows測試的最佳方式是什麼?
您可以使用反引號將JS內聯,不要使用eval。 – thejh