Testing
App tests
// app/utils/math.js
export function add(a, b) {
assert(
'arguments must be numbers',
typeof a === number && typeof b === number
);
return a + b;
}// tests/unit/utils/math-test.js
import { module, test } from 'qunit';
import { add } from 'app/utils/math';
module('the `add` function', function(hooks) {
test('adds numbers correctly', function(assert) {
assert.equal('2 + 2 is 4', add(2, 2), 4);
assert.notEqual('2 + 2 is a number', add(2, 2), NaN);
assert.notEqual('2 + 2 is not infinity', add(2, 2), Infinity);
});
test('throws an error with strings', function(assert) {
assert.throws(
'when the first is a string and the second is a number',
() => add('hello', 1)
);
assert.throws(
'when the first is a number and the second is a string',
() => add(0, 'hello')
);
assert.throws(
'when both are strings',
() => add('hello', 'goodbye')
);
})
});Addon tests
Gotchas
The TestContext
TestContextQUnit Dom for Component tests
Last updated
Was this helpful?