Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,26 @@ Assertions can be added to the test by calling the step method of the test
object with a function containing the test assertions:

```js
t.step(function() {assert_true(true)});
t.step(function() {assert_equals(1+1, 2)});
```

When all the steps are complete, the done() method must be called:
When all the steps are complete, the `done()` method must be called:

```js
t.done();
```

As a convenience, async_test can also takes a function as first argument.
As a convenience, `async_test` can also takes a function as first argument.
This function is called with the test object as both its `this` object and
first argument. The above example can be rewritten as:
first argument. Thus we can write:

```js
async_test(function(t) {
object.some_event = function() {
t.step(function (){assert_true(true); t.done();});
object.some_event = function(e) {
t.step(function() {
assert_true(e.a);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is weird here

t.done();
});
};
}, "Simple async test");
```
Expand Down Expand Up @@ -120,6 +123,14 @@ object.some_event = t.unreached_func("some_event should not fire");
Keep in mind that other tests could start executing before an Asynchronous
Test is finished.

Finally, for cases where you want to simply pass the test when a callback is
called, there is `step_func_done`, which will generate a step function that
calls `done()`. For example:

```js
object.some_event = t.step_func_done();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that step_func_done can also take a callback argument; in that case

t.step_func_done(f)

is roughly equivalent to

t.step_func(() => {
  f();
  t.done();
})

```

## Promise Tests ##

`promise_test` can be used to test APIs that are based on Promises:
Expand Down