5

統合された QUnit テスト フレームワークを使用して、ルートにアクセスしないとエラーが発生するかどうかをテストする必要があります。

ルートには、特定の条件下でエラーをスローするハンドルバー ヘルパーがあります (アサーションの失敗)。このエラーがスローされるかどうかをテストするにはどうすればよいですか?

これは私がこれまでに得たものです:

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)

Asvisit('/missing')は promise を返します.then(success, error)

4

2 に答える 2

1

http://api.qunitjs.com/throws/で説明されているthrowsように、関数を呼び出す代わりにコールバックを渡すことになっています。

そう:

test('throws, if the SVG is missing', function() {
  throws(function() {visit('/missing')}, Error, "has thrown an Error");
});
于 2015-01-21T12:49:35.117 に答える