Использование Quinit's throw() Утверждение Я хочу проверить, что выдается ошибка, и сообщение об ошибке. У меня есть следующие функции:Правильное использование утверждения QUnit throw()?
/**
* Error function for Node.
* @param {String} msg Error message.
*/
function NodeError (msg) {
var that = this
/**
* Attribute for message.
* @type {String}
*/
this.msg = msg
/**
* Function rendering NodeError as a string.
* @return {String} String representation of NodeError.
*/
this.toString = function() {
return that.msg
}
}
/**
* Node object. TODO Fill out.
* @param {String} title Node title.
* @throws {NodeError} If no title given
*/
function Node (title) {
var that = this
if (!title) {
throw new Error('Error: no title given')
}
/**
* Node title
* @type {[type]}
*/
this.title = title
}
И следующий QUnit
тест:
QUnit.test('new Node w/o title throws error', function (assert) {
assert.expect(1) // Expected number of assertions
assert.throws(
function() { new Node() },
function (err) { err.toString() === 'Error: no title given' },
'Error thrown'
)
})
Однако тесты блок не дает этого:
Error [email protected] 0 ms
Expected:
function(a){
[code]
}
Result:
Error("Error: no title given")
Diff:
function(a){
[code]
}Error("Error: no title given")
Source:
at Object.<anonymous> (file:///Users/maasha/install/src/protwiz/test/test_pw_node.js:10:10)
Что делать?
Спасибо, ты дорогая! – maasha