- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
除了 jRuby/Rails
之外,我的应用程序还使用 AngularJS
、CoffeScript
。我想用 Jasmine
测试我的 javascript 并用 Karma
(又名 Testacular
)运行它,但我收到一条错误消息,指出我的 < strong>Angular 模块未在任何地方定义。我得到了什么:安装了 Node.js
和 Karma
,生成了一个配置文件:
// base path, that will be used to resolve files and exclude
basePath = '../';
// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
'vendor/assets/javascripts/angular.js',
'vendor/assets/javascripts/angular-mocks.js',
'vendor/assets/javascripts/angular-resource.js',
'app/assets/javascripts/*.js.coffee',
'spec/javascripts/*_spec.js'
];
preprocessors = {
'**/*.coffee': 'coffee'
};
我添加了 AngularJS
源文件(因此模块和注入(inject)将起作用)、我的 javascript Assets (在 CoffeScript
中)和我的规范。我还添加了 CoffeScript
作为预处理器。
我的规范文件:
describe("PasswordResetsController", function() {
//Mocks
var http = {};
var routeParams = {};
//Controller
var ctrl = null;
//Scope
var $scope = null;
beforeEach( function() {
angular.module('KarmaTracker');
});
/* IMPORTANT!
* this is where we're setting up the $scope and
* calling the controller function on it, injecting
* all the important bits, like our mockService */
beforeEach(angular.inject(function($rootScope, $httpBackend, $controller) {
//create a scope object for us to use.
$scope = $rootScope.$new();
//http mock from Angular
http = $httpBackend;
//now run that scope through the controller function,
//injecting any services or other injectables we need.
ctrl = $controller(PasswordResetsController, {
$scope: $scope,
$http: http,
$routeParams: routeParams
});
}));
it("foo spec", function() {
expect($scope.foo).toEqual('test');
});
});
我正在使用 angular.module 加载模块,注入(inject)依赖项并模拟 $http 和 routeParams。
我的模块定义如下:
window.KarmaTracker = angular.module('KarmaTracker', ['ngCookies', 'ngMobile'])
# Flashe message passed from other controllers to FlashesController
KarmaTracker.factory "FlashMessage", ->
{ string: "", type: null }
KarmaTracker.controller "RootController", ($scope, $http, $location, $cookies, $routeParams, FlashMessage, broadcastService) ->
.....
该模块加载在 KarmaTracker 命名空间中,我怀疑这是罪魁祸首。启动 Karma 时:
karma start --log-level debug config/karma.conf.js
我可以看到 Assets 已编译并已服务器化,但我收到一条消息:
PhantomJS 1.8 (Linux) ERROR
ReferenceError: Can't find variable: KarmaTracker
at /home/.../KarmaTracker/app/assets/javascripts/account.js.coffee-compiled.js:1
任何想法现在做什么将不胜感激!
最佳答案
您是否尝试过以正确的顺序逐个指定来加载它们,而不是使用 wildcats 来加载它们?我知道顺序确实与 karma 有关。
关于angularjs - 将 Karma-runner 与 AngularJS、Jasmine、CoffeeScript 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17601744/
我有以下 Coffeescript: $ -> $('#new_event').submit -> $.post( $(this).attr('acti
Coffeescript docs包含以下简介 String Interpolation, Block Strings, and Block Comments Ruby-style string in
如何获得类似于 HTML 的 target='_blank' 的行为在 CoffeeScript 里面? 到目前为止,我已经尝试过: window.location = "/site/#{pk}/go
array = [1,2,3,4] for num in array //do something num的值是多少在函数的其余部分?是否num得到范围到循环? 最佳答案 不,num不会被限制
Coffeescript 使用存在运算符来确定变量何时存在,并且在 coffeescript documentation 中它表明 something?将编译为 something !== undef
我一直在阅读一些关于 coffeescript 的继承模型的内容,我感觉自己正处于一场我真的不理解的意识形态辩论的边缘。所以,我会非常高兴地发现我只是以错误的方式做事。 基本上我正在做的是编写一组小部
这个问题在这里已经有了答案: How to iterate over the keys and values in an object in CoffeeScript? (4 个回答) 8年前关闭。
让我们定义这个简单的代码: class Foo @foo = 'blah' console.log(@foo) class Bar extends Foo constructor: ()
除了这些示例之外,我正在努力寻找任何好的 CoffeeScript 和模式匹配示例: {x, y} = sprite css = {opacity, fontFamily} 我在 Erlang 中使用
我想做一个 if 语句来检查一个对象是否是一个空对象。 空对象是指如果我执行 console.log(object) 它会打印出 {}。 我该怎么做呢? 最佳答案 myObject = {} if O
在 JS 中创建文字数组时: [{ name: 'david', value: 'blue' }, { name: 'harold', value: 'orange' }] 我能看到在 Coffees
我的问题类似于发布的 here .本质上我想读一个配置file.json看起来像这样: { "message": "Error in #{baseName} at #{directory}" }
如果我有一个类,则将多个参数传递给: class Foo constructor: (parameters) -> @bar = parameters.bar @moo = paramet
coffeescript中是否有 namespace 的内在支持? 适当的命名空间似乎确实可以帮助Coffeescript有所帮助,尽管我似乎无法找到任何迹象表明存在对此的支持。 最佳答案 既可以在自
我有一个具有一些jquery事件侦听器的coffeescript类。我想使用粗箭头=>以避免引用该类,但是我仍然需要引用通常与this一起使用的元素。如何同时使用两者? class PostForm
我要转换 console.log({ a: 'a' }, { b: 'b' }); 进入 CoffeeScript。我发现的唯一方法是 console.log a: 'a', b:
我真的很喜欢这个: var value = maxValue > minValue ? minValue : maxValue; Coffeescript 中是否有同样简洁的东西? 最佳答案 valu
我想在coffeescript中编写一个静态帮助器类。这可能吗? 类别: class Box2DUtility constructor: () -> drawWorld: (world, co
super 简单的coffeescript问题 circles = [] for coordinate, i in coordinates circles[i] = new MakeCircl
我在看this great video由 Jeremy 在 CoffeeScript 上发表。他解释说,CoffeeScript 的理想之一是让“一切都是表达式”。 CoffeeScript 离这个理
我是一名优秀的程序员,十分优秀!