May 2017
Intermediate to advanced
448 pages
10h 10m
English
Testing asynchronous code such as Ajax requests presents an additional challenge. The rest of the tests must pause while the asynchronous test occurs, and then they must begin again when it is complete. This type of scenario is by now very familiar; we have seen such asynchronous operations in effects queues, Ajax callback functions, and promise objects. Asynchronous tests in QUnit are just like the regular QUnit.test() function except that it will pause the running of tests until we resume them with a call to a function created by assert.async() function:
QUnit.test('JSON', (assert) => { assert.expect(0); const done = assert.async(); $.getJSON('A.json', (json, textStatus) => { // add tests here }).always(done);}); ...Read now
Unlock full access