Jasmine 规范未找到在 CoffeeScript 中定义的类 [英] Classes defined in CoffeeScript not found by Jasmine specs

查看:18
本文介绍了Jasmine 规范未找到在 CoffeeScript 中定义的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Rails 3.1 后端构建一个主干.js 应用程序.我正在使用 CoffeeScript 编写主干类,并使用 Jasmine(通过 jasmine-headless-webkit)进行测试.

I am building a backbone.js app on a Rails 3.1 back-end. I'm using CoffeeScript to write the backbone classes, and Jasmine (via jasmine-headless-webkit) for testing.

给定以下(部分)树:

.
├── app
│   ├── assets
│   │   ├── javascripts
│   │   │   └── views
│   │   │       ├── avia_view.js.coffee
├── spec
│   ├── javascripts
│   │   └── views
│   │       └── avia_view_spec.js.coffee

...我希望 avia_view_spec.js.coffee 了解 Avia.AviaView,它在 avia_view.js.coffee.

... I would expect avia_view_spec.js.coffee to know about Avia.AviaView, which is defined in avia_view.js.coffee.

但是,我从运行 bundle exec jasmine-headless-webkit 得到以下输出:

However, I get the following output from running bundle exec jasmine-headless-webkit:

Running Jasmine specs...
F

Avia.AviaView render creates a new MatricesView . (/home/duncan/avia/spec/javascripts/views/avia_view_spec.js.coffee:10)
  ReferenceError: Can't find variable: Avia in /home/duncan/avia/spec/javascripts/views/avia_view_spec.js.coffee (line ~5)
  ReferenceError: Can't find variable: Avia in /home/duncan/avia/spec/javascripts/views/avia_view_spec.js.coffee (line ~10)

我的 jasmine.yml 包含以下内容:

My jasmine.yml contains the following:

src_files:
  - public/javascripts/prototype.js
  - public/javascripts/effects.js
  - public/javascripts/controls.js
  - public/javascripts/dragdrop.js
  - public/javascripts/application.js
  - public/javascripts/**/*.js

认为我需要告诉 Jasmine 加载 avia_view.js.coffee 的内容,但我不完全确定如何.在 jasmine.ymlsrc_files 部分中添加显式引用似乎没有什么不同...

I think I need to tell Jasmine to load the contents of avia_view.js.coffee but I'm not entirely sure how. Adding an explicit reference in the src_files section in jasmine.yml doesn't seem to make a difference ...

有人可以告诉我我在这里做错了什么吗?我怀疑这很简单......

Could someone please tell me what I'm doing wrong here? I suspect it's something simple ...

推荐答案

没有看过你的大部分代码,我怀疑这是因为 CoffeeScript 的函数包装 (docs).您需要确保将要使用的所有符号导出到您可以获取的位置(此处 对此进行了彻底的讨论).

Without having seen to much of your code, I'd suspect it beacuse of CoffeeScript's function wrapping (docs). You need to ensure that all the symbols you want to use are exported to somewhere you can get at them (here is a thorough discussion about that).

这里是 关于这个主题的另一个冗长的理论但很好的文档.

here's another longish and theoretical but good documentation on this topic.

这篇关于Jasmine 规范未找到在 CoffeeScript 中定义的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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