blue-tape icon indicating copy to clipboard operation
blue-tape copied to clipboard

Can't assert within a 'then' block

Open sunny-g opened this issue 8 years ago • 2 comments

Maybe I'm using this library wrong, but I can't seem to assert anything from within a then block, as so:

require('babel-core/register')({
  presets: ['es2015']
});
const test = require('blue-tape');

...

test('setup', (assert) => {
  return ddpClient.connect().then(() => {
    assert.pass(); // this can be assert.end() and it will still fail
  });
});
test('basic test', (assert) => {
  assert.equal(1, 1);
  assert.end();
});

With this example, both tests fail and give me the following output:

TAP version 13
# setup
not ok 1 test exited without ending
  ---
    operator: fail
  ...
not ok 2 test exited without ending
  ---
    operator: fail
  ...

1..2

If I simplify this example by making the test's callback return a Promise, I can assert anything up until I try returning ddpClient.connect() which returns a Promise. Side note: if I do assert.end() before that line, by 'basic test' doesn't run, and it says I only passed 1 test.

One thing that may be affecting the output is my use of babel to transpile the ddpClient module and all node_modules I'm using, but I need it (b/c I'm testing React Native, pseudo-ES7 code and trying to mock out a WebSocket server) and it's also hard for me to see why that may be the source of these issues. Can someone point me in the right direction?

sunny-g avatar Nov 10 '15 01:11 sunny-g

Try this instead:

test('setup', (assert) => {
  return ddpClient.connect()
});

Sparragus avatar Nov 23 '15 21:11 Sparragus

If your issue is indeed related to ES6 I'd advise not having the register hook in your test and just running your test files with babel-node.

trodrigues avatar Feb 12 '16 10:02 trodrigues