Javascript 引用错误:CoffeeScript+;JsTestDriver+;昆特
目前,我正在使用CoffeeScript和JsTestDriver研究TDD,但是我被JsTestDriver抛出的引用错误所困扰 一些信息:Javascript 引用错误:CoffeeScript+;JsTestDriver+;昆特,javascript,tdd,coffeescript,qunit,js-test-driver,Javascript,Tdd,Coffeescript,Qunit,Js Test Driver,目前,我正在使用CoffeeScript和JsTestDriver研究TDD,但是我被JsTestDriver抛出的引用错误所困扰 一些信息: 使用IntellijJSTestDriver插件 通过铬进行测试 以与上相同的方式配置JsTestDriver: 用CoffeeScript编写测试 CoffeeScript被编译成javascript,并在测试运行之前放入配置的目录中 配置 server: http://Mark-PC:9876/capture load: - js/lib/
- 使用IntellijJSTestDriver插件
- 通过铬进行测试
- 以与上相同的方式配置JsTestDriver:
- 用CoffeeScript编写测试
- CoffeeScript被编译成javascript,并在测试运行之前放入配置的目录中
server: http://Mark-PC:9876/capture
load:
- js/lib/main/*.js
- js/lib/test/sinon.js
- js/lib/test/qunit.js
- js/lib/test/equiv.js
- js/lib/test/QUnitAdapter.js
- js/coffee/main/controllers/*.js
- js/coffee/main/models/*.js
- js/coffee/test/controllers/*.js
控制器
class PortfolioController extends Backbone.Controller
constructor: ->
test: (a, b) ->
return a + b
测试代码
module("PortfolioController", {
setup: -> @routeSpy = sinon.spy()
teardown: -> window.location.hash = ""
})
test 'indexRoute', ->
c = new PortfolioController
equals c.test(1, 1), 2, "1 + 1 = 2"
问题
JsTestDriver抛出一个错误
ReferenceError: PortfolioController is not defined
ReferenceError: PortfolioController is not defined
at Object. (http://mark-pc:9876/test/js/coffee/test/controllers/PortfolioController.test.js:12:5)
at [object Object].test indexRoute (http://mark-pc:9876/test/js/lib/test/QUnitAdapter.js:40:15)
已尝试:
- 删除依赖项,如jQuery、主干网等
- 已删除Qunit适配器并尝试使用jstestdriver断言
- 在测试本身中添加了一个类,然后它就工作了
似乎存在某种导出问题或原型冲突?听起来您需要通过添加
root = window ? global
root.PortfolioController = PortfolioController
文件的结尾,或者只需替换
class PortfolioController extends Backbone.Controller
与
利用此
是该上下文中的全局根这一事实
CoffeeScript从不自动导出超出文件范围的任何内容;你必须明确地这样做。请参阅我对这种行为的解释
class @PortfolioController extends Backbone.Controller