Tape: Which is the preferred usage? plan(n) or end()?

Created on 24 May 2016  路  5Comments  路  Source: substack/tape

Assuming all else equal, is it preferred to use end() at the end of the test, or plan(n) at the beginning? Is one more performant?

It would seem that t.end() is much easier to use, as you don't have to maintain the number of assertions to check as with t.plan(n). Are there situations where plan is better?

Using t.end():

tape('test using end()', t => {
  t.equal(1, 1)
  t.equal(2, 2)
  t.end()
})

Using t.plan(n):

tape('test using plan(n)', t => {
  t.plan(2)
  t.equal(1, 1)
  t.equal(2, 2)
})
question

Most helpful comment

I only ever use end() personally.

All 5 comments

I'd recommend using t.plan() on every test. It provides stronger guarantees in async scenarios and makes sure comments are put on the right line in the output.

I prefer often doing both. "plan" at the beginning to protect myself against hard-to-catch async test omissions, and "end" at the end to notify tape that i'm for sure done, to fail faster.

I only ever use end() personally.

@TimBuckley @Raynos .end() where I can (which is quite often). plan(n) earlier on in the test example due to uncertanty.

In other news...Make some noise for .end() being 2 chars lazier to type than .plan(n) IJS 馃帀 馃巻

image

This appears answered thoroughly.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndyOGo picture AndyOGo  路  8Comments

Istador picture Istador  路  3Comments

mustafamamun picture mustafamamun  路  3Comments

jimkang picture jimkang  路  3Comments

kl0tl picture kl0tl  路  7Comments