使用集成的QUnit测试framweork我需要测试是否访问路由会导致抛出错误。在Ember.js中引发错误的测试
路线中有一个把手助手,在某些情况下应该抛出一个错误(失败断言)。我该如何测试这个错误是否被抛出?
这是我走到这一步:
test('throws, if the SVG is missing', function() {
throws(visit('/missing'), Error, "has thrown an Error");
});
但它不工作,因为错误没有被抓到throws(...)
和泡沫到测试框架,这标志着本次测试为失败。
这是测试输出:
Died on test #1 at http://localhost:7357/assets/dummy.js:304:5
at requireModule (http://localhost:7357/assets/vendor.js:77:29)
at http://localhost:7357/assets/test-loader.js:14:29: Assertion Failed: No SVG found for this/svg/is/missing
Source:
Error: Assertion Failed: No SVG found for this/svg/is/missing
at new Error (native)
at Error.EmberError (http://localhost:7357/assets/vendor.js:27463:23)
at Object.Ember.assert (http://localhost:7357/assets/vendor.js:17077:15)
at inlineSvg (http://localhost:7357/assets/dummy.js:94:13)
at Object.bindView.normalizedValue (http://localhost:7357/assets/vendor.js:20498:21)
at Object.SimpleHandlebarsView.render (http://localhost:7357/assets/vendor.js:23450:26)
at EmberRenderer_createElement [as createElement] (http://localhost:7357/assets/vendor.js:52738:16)
at EmberRenderer.Renderer_renderTree [as renderTree] (http://localhost:7357/assets/vendor.js:23840:24)
at EmberRenderer.<anonymous> (http://localhost:7357/assets/vendor.js:23917:16)
at DeferredActionQueues.invoke (http://localhost:7357/assets/vendor.js:13891:18)
由于visit('/missing')
回报的承诺,人们会认为使用.then(success, error)
会的工作,但事实并非如此。
截至Ember 2.11,断言抛出似乎不再是一件事情。 https://github.com/emberjs/ember.js/pull/14898 – snewcomer 2017-04-09 01:44:05