Reputation: 45400
I am using Qunit
testing engine in JavaScript and I need to check if a property exists in an object.
Here is my setup:
var tests = [
{
foo: 'foo',
bar: 'bar',
expected: {}
},
{
foo: '',
bar: '',
expected: //I need to expect foo and bar properties to exist
}
]
for(var i = 0; i < tests.length; i++) {
assert.deepEqual(validate_foo(tests[i]), tests[i].expected);
}
The function validate_foo()
either will return an empty object {}
on success, or an object with the properties of each error. For example, validate_foo()
expectes foo
to equal foo
and bar
to equal bar
. So in the second test, the result is:
{
foo: 'foo does not equal foo',
bar: 'bar does not equal bar'
}
How do I write a test to accomblish this?
Upvotes: 0
Views: 1335
Reputation: 7505
Maybe I have totally missed the point, but assuming you are testing the validate_foo function, isn't this all you need to do?
var tests = [
{
foo: 'foo',
bar: 'bar',
expected: {}
},
{
foo: '',
bar: '',
expected: {foo: 'foo does not equal foo',
bar: 'bar does not equal bar'}
}
]
for(var i = 0; i < tests.length; i++) {
assert.deepEqual(validate_foo(tests[i]), tests[i].expected);
}
...and if that's not the test you want then can you clarify what specifically you are trying to test in this case?
Upvotes: 1