Skip to content

Commit

Permalink
[readme] Document unexpected t.end() behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kl0tl authored and ljharb committed Mar 28, 2016
1 parent 7aff9e4 commit b505c4c
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions readme.markdown
Expand Up @@ -408,6 +408,74 @@ With [npm](https://npmjs.org) do:
npm install tape --save-dev
```

# troubleshooting

Sometimes `t.end()` doesn’t preserve the expected output ordering.

For instance the following:

```js
var test = require('tape');

test('first', function (t) {

setTimeout(function () {
t.ok(1, 'first test');
t.end();
}, 200);

t.test('second', function (t) {
t.ok(1, 'second test');
t.end();
});
});

test('third', function (t) {
setTimeout(function () {
t.ok(1, 'third test');
t.end();
}, 100);
});
```

will output:

```
ok 1 second test
ok 2 third test
ok 3 first test
```

because `second` and `third` assume `first` has ended before it actually does.

Use `t.plan()` instead to let other tests know they should wait:

```diff
var test = require('tape');

test('first', function (t) {

+ t.plan(2);

setTimeout(function () {
t.ok(1, 'first test');
- t.end();
}, 200);

t.test('second', function (t) {
t.ok(1, 'second test');
t.end();
});
});

test('third', function (t) {
setTimeout(function () {
t.ok(1, 'third test');
t.end();
}, 100);
});
```

# license

MIT

0 comments on commit b505c4c

Please sign in to comment.