ReferenceError:CoffeeScript + JsTestDriver + Qunit [英] ReferenceError: CoffeeScript + JsTestDriver + Qunit

查看:230
本文介绍了ReferenceError:CoffeeScript + JsTestDriver + Qunit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在研究TDD与CoffeeScript和JsTestDriver,但我被困在由JsTestDriver抛出的ReferenceError。



一些信息:





配置 b

  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

控制器 / b>

  class PortfolioController extends Backbone.Controller 
constructor: - >

test: b) - >
return a + b

测试代码

 模组(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未定义
ReferenceError:没有在Objects定义PortfolioController
。 (http:// mark-pc:9876 / test / js / coffee / test / controllers / PortfolioController.test.js:12:5)
at [object Object] .test indexRoute(http: pc:9876 / test / js / lib / test / QUnitAdapter.js:40:15)




  • 删除依赖项(如jQuery,BackBone等)

  • 删除了Qunit适配器和尝试使用jstestdriver声明

  • 在测试本身内添加了一个类,然后工作



似乎有些出口问题或原型冲突?

解决方案

听起来像你需要 PortfolioController 全局,也许通过添加

  root =全局
root.PortfolioController = PortfolioController

文件的结尾, / p>

  class PortfolioController extends Backbone.Controller 

  class @PortfolioController extends Backbone.Controller 



利用这个是该上下文中的全局根。



CoffeeScript不会自动导出超出文件范围的任何内容;你必须明确做到。请参阅我对此行为的解释此处


Currently I'm looking into TDD with CoffeeScript and JsTestDriver however I'm stuck on a ReferenceError thrown by JsTestDriver.

Some info:

  • Using the IntelliJ JsTestDriver plugin
  • Testing via Chrome
  • Configured JsTestDriver the same way as on: http://code.google.com/p/js-test-driver/wiki/QUnitAdapter
  • Writing the tests in CoffeeScript
  • CoffeeScript is compiled to javascript and put in the configured directories before the test is run

Config

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

Controller

class PortfolioController extends Backbone.Controller
    constructor: ->

    test: (a, b) ->
        return a + b

Test code

module("PortfolioController", {
    setup: -> @routeSpy = sinon.spy()
    teardown: -> window.location.hash = ""
})

test 'indexRoute', ->
    c = new PortfolioController
    equals c.test(1, 1), 2, "1 + 1 = 2"

Problem

JsTestDriver throws a error

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)

Tried:

  • Removing dependancies such as jQuery, BackBone, etc
  • Removed Qunit adapter and tried with jstestdriver asserts
  • Added a class inside the test itself, then it worked

Seems like some kinda exporting issue or prototype conflict?

解决方案

Sounds like you need to make PortfolioController a global, perhaps by adding

root = window ? global
root.PortfolioController = PortfolioController

the end of the file, or by simply replacing

class PortfolioController extends Backbone.Controller

with

class @PortfolioController extends Backbone.Controller

taking advantage of the fact that this is the global root in that context.

CoffeeScript never exports anything beyond a file's scope automatically; you have to do it explicitly. See my explanation for this behavior here.

这篇关于ReferenceError:CoffeeScript + JsTestDriver + Qunit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆