我正在跑步' ember test --server'在我的申请中,我遇到两次失败,我不确定他们为什么会失败。
从CLI:
> ToUrlHelper: it works
> ✘ Died on test #1 at eval (new-cms/tests/unit/helpers/to-url-test.js:10:5)
> at requireModule (http://localhost:7357/assets/vendor.js:70:29)
> at http://localhost:7357/assets/test-loader.js:14:29: undefined is not a function
从网络浏览器:
> Died on test #1 at eval
> (new-cms/tests/unit/helpers/to-url-test.js:10:5)
> at requireModule (http://localhost:7357/assets/vendor.js:70:29)
> at http://localhost:7357/assets/test-loader.js:14:29: undefined is not a function Source: TypeError: undefined is not a function
> at Object.eval (new-cms/tests/unit/helpers/to-url-test.js:11:20)
> at Object.Test.run (http://localhost:7357/assets/test-support.js:1078:18)
> at http://localhost:7357/assets/test-support.js:1165:10
> at process (http://localhost:7357/assets/test-support.js:881:24)
> at http://localhost:7357/assets/test-support.js:470:5
这是to-url-test.js:
import {
toUrl
} from 'new-cms/helpers/to-url';
module('ToUrlHelper');
// Replace this with your real tests.
test('it works', function() {
var result = toUrl(42);
ok(result);
});
来自实际帮助者的代码:
import Ember from 'ember';
export default Ember.Handlebars.makeBoundHelper(function(value) {
if(typeof(value) !== 'undefined') {
return value.replace(/\s+/g, '-').toLowerCase();
}
return '';
});
答案 0 :(得分:1)
也许这只不过是你将42传递给你的函数,然后尝试在其上应用.replace
函数。但是这个函数只在字符串...
首先传入像#34; hello me"而不是42,然后在另一个测试中传递42,看看你的测试中断,因为你的实现没有考虑到这一点并修复你的实现。 (这是一种测试驱动开发)