When working with callbacks you’re usually doing async operations, so to unit test a callback you will need to use QUnit’s async() method.
async(): Instruct QUnit to wait for an asynchronous operation.
So try this:
QUnit.test('should invoke callback', (assert) => {
let done = assert.async();
let callback = () => {
assert.ok( true, 'test ok callback invoked' );
done();
};
myFunction(callback);
});
And that’s it! If myFunction
does its job of invoking the callback then your test will pass.