Skip to content

Commit

Permalink
Docs: Document assert.timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Trent Willis authored and trentmwillis committed Jul 7, 2017
1 parent 668d3e3 commit 42e8d73
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/assert/timeout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
layout: default
title: timeout
description: Sets the length of time to wait for async operations before failing the test.
categories:
- assert
- async
---

## `timeout( duration )`

Sets the length of time to wait for async operations before failing the test.

| name | description |
|------|-------------|
| `duration` (Number) | The length of time, in milliseconds, to wait for async operations. |

### Description

`assert.timeout()` sets the length of time, in milliseconds, to wait for async operations in the current test. This is equivalent to setting `config.testTimeout` on a per-test basis. The timeout length only applies when performing async operations.

If `0` is passed, then the test will be assumed to be completely synchronous. If a non-numeric value is passed as an argument, the function will throw an error.

### Examples

```js
QUnit.test( "Waiting for focus event", function( assert ) {
assert.timeout( 1000 ); // Timeout of 1 second
var done = assert.async();
var input = $( "#test-input" ).focus();
setTimeout(function() {
assert.equal( document.activeElement, input[0], "Input was focused" );
done();
});
});
```

```js
QUnit.test( "Waiting for async function", function( assert ) {
assert.timeout( 500 ); // Timeout of .5 seconds
var promise = asyncFunction();
return promise.then( function( result ) {
assert.ok( result );
} );
});
```

0 comments on commit 42e8d73

Please sign in to comment.