我有一個用Coffeescript編寫的web應用程序,我使用nodeunit進行測試,而且我似乎無法訪問測試中設置的全局變量(應用程序中的「會話」變量) :Coffeescript,nodeunit和全局變量
SRC/test.coffee
root = exports ? this
this.test_exports = ->
console.log root.export
root.export
測試/ test.coffee
exports["test"] = (test) ->
exports.export = "test"
test.equal test_file.test_exports(), "test"
test.done()
結果輸出:
test.coffee
undefined
✖ test
AssertionError: undefined == 'test'
如何跨測試訪問全局變量?
試着用'b'-Flag編譯它。這可以防止添加安全關閉。 – TimWolla 2012-01-15 15:01:44
我的源代碼是用以下標誌編譯的:'nice -n 19 coffee -o web/-b -c -w src /',我將-b添加到Trevor Burnham的連續Cakefile build =(watch,callback) - > \t如果typeof運算手錶是 '功能' \t \t回調=觀看 \t \t手錶=假 \t選項= [ '-b', '-c', '-o', 'LIB', 'SRC'] \t選項。如果手錶 但沒有骰子,則'快速移動'-w'。 – 2012-01-15 15:20:01
嘗試不使用全局變量? – Raynos 2012-01-16 12:52:29