1
我在我的应用程序上运行'ember test --server',出现两次失败,我不知道它们为什么失败。Ember测试失败
从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
从Web浏览器:
> 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
这是在对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 '';
});
我使用的是ember-cli,它产生了测试,所以我不知道为什么数字'42'被传递。我应该删除测试并使用cli重新创建它吗? – Mithrilhall 2014-12-03 21:13:13
嗯,我猜Ember cli只是为你生成一个基本的测试,而不知道你的函数的实现。你的测试应该是“验证”预期的行为。在你的toUrl函数中,你不希望收到数字,而是字符串。然后,你的测试必须验证意外,但“可能发生”行为,因此你应该测试传递null,未定义,数字等......到你的函数中,并修改它的实现以避免它的破坏。 (这实际上就是发生在这里的事情,烬哲提供了一个边缘案例并破坏了你的代码)。 – Sephy 2014-12-07 11:04:32
如果这回答你的问题,请检查它作为正确的答案。这将验证它。 – Sephy 2014-12-07 18:09:32