【发布时间】:2017-10-11 06:11:35
【问题描述】:
我试图断言代码中的几个步骤(访问页面、提供错误的卡号、密码组合和单击提交)应该从后端服务产生错误 - 我已经提到了 this..
并尝试使用错误对象作为 assert.throws 的第二个参数的建议,但这对我不起作用。
在发布我的问题之前,我确实也看到了this 链接, 我的问题是 - 在这种情况下,我无法控制引发异常/错误的代码。 (我不能把它改成 Ember.assert 等)我只想能够抓住一个错误的案例。
其次,在这种情况下,我没有组件。它是在单击提交完成时进行的直接 API 调用,基本上是在控制器中调用 submitAuthForm 动作,该控制器调用 ember cli mirage 场景,该场景返回以下对象问题对象。
return new Response(401,{'X-Auth-Token': 'wrong-username-password-combination'},failResponse401);
返回的对象看起来像
var failResponse401 = {
problems: [ {
field: null,
index: null,
value: null,
code: '0006',
subCode: '',
details: {},
_type: 'error'
} ]
};
我们有一个 node_module 依赖于一个内部异常工具包,该工具包基于此抛出一个错误对象。
这是我的 Qunit 测试
test('ERROR_CASE_visiting /signon, provide cardNumber(2342314) and ' +
'password, submit and expect to see invalid cardnumber/password error',
function (assert) {
assert.expect(2);
assert.throws(
function () {
visit('/signon');
fillIn('#a8n-signon-card-number input', '2342314');
fillIn('#a8n-signon-password input', 'password');
click('#a8n-signon-submit-button button');
},
Error,
"Error Thrown"
);
});
我不断收到来自 Qunit 的此错误
Error Thrown@ 110 ms
Expected:
function Error( a ){
[code]
}
Result:
undefined
Diff:
function Error( a ){
[code]
}defined
Source:
at Object.<anonymous> (http://localhost:7357/assets/tests.js:175:12)
at runTest (http://localhost:7357/assets/test-support.js:3884:30)
at Test.run (http://localhost:7357/assets/test-support.js:3870:6)
at http://localhost:7357/assets/test-support.js:4076:12
at Object.advance (http://localhost:7357/assets/test-support.js:3529:26)
at begin (http://localhost:7357/assets/test-support.js:5341:20)
API rejected the request because of : []@ 1634 ms
Expected:
true
Result:
false
Source:
Error: API rejected the request because of : []
at Class.init (http://localhost:7357/assets/vendor.js:172237:14)
at Class.superWrapper [as init] (http://localhost:7357/assets/vendor.js:55946:22)
at new Class (http://localhost:7357/assets/vendor.js:51657:19)
at Function._ClassMixinProps.create (http://localhost:7357/assets/vendor.js:51849:12)
at Function.createException (http://localhost:7357/assets/vendor.js:172664:16)
at Class.<anonymous> (http://localhost:7357/assets/vendor.js:133592:72)
at ComputedPropertyPrototype.get (http://localhost:7357/assets/vendor.js:32450:27)
at Object.get (http://localhost:7357/assets/vendor.js:37456:19)
at Class.get (http://localhost:7357/assets/vendor.js:50194:26)
at http://localhost:7357/assets/vendor.js:133645:30
还有什么我可以尝试让它工作的。 有没有办法通过某种方式通过这个测试,通过以某种方式包装返回的响应,它不会完全破坏我的测试。
【问题讨论】:
-
这个问题的讨论很有用stackoverflow.com/questions/42781085/…
-
我在发布之前也确实看到了该链接,我已经更新了我上面的问题,考虑了该链接提供的信息。基本上我的问题不在于测试组件,并且更改异常抛出代码的源代码不在我的控制范围内
标签: ember.js qunit ember-qunit ember-testing