Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t.throws(undefined) passes, and should not #267

Closed
dmitrizagidulin opened this issue Mar 2, 2016 · 6 comments
Closed

t.throws(undefined) passes, and should not #267

dmitrizagidulin opened this issue Mar 2, 2016 · 6 comments
Labels

Comments

@dmitrizagidulin
Copy link

What am I doing wrong here? t.throws() doesn't seem to be working (not failing the test when a function is not throwing any exceptions).

Here's a sample test, that passes successfully (instead of failing as expected):

'use strict'

var test = require('tape')

function emptyFunction () {
  // nothing happens here
}

test('This test should fail', function (t) {
  t.plan(1)
  t.throws(emptyFunction())
})

I'm on Node 5.0, tape version 4.4.0.

@ljharb
Copy link
Collaborator

ljharb commented Mar 2, 2016

@dmitrizagidulin throws takes a single function - you're passing it undefined (the return value of a function)

@dmitrizagidulin
Copy link
Author

Ohh I see. Is there a way to pass parameters to that function? (and why does it count undefined as a successful throws() test?)

@yoshuawuyts
Copy link

t.throws(myFunction.bind(null, 'arg1', 'arg2'))
t.throws(function () {
  myFunction('arg1', 'arg2')
})

@ljharb
Copy link
Collaborator

ljharb commented Mar 2, 2016

@dmitrizagidulin indeed that seems like a bug - assert.throws(undefined) throws with "block must be a function".

@ljharb ljharb changed the title t.throws() doesn't seem to be working t.throws(undefined) passes, and should not Mar 2, 2016
@ljharb ljharb added the bug label Mar 2, 2016
@dmitrizagidulin
Copy link
Author

Thanks! :) Appreciate the guidance and the fix.

@ljharb
Copy link
Collaborator

ljharb commented Mar 6, 2016

np - I'll be releasing a patch version for v1, v2, v3, and v4 shortly that will include this fix.

gr2m added a commit to hoodiehq/hoodie-store-client that referenced this issue Mar 7, 2016
see tape-testing/tape#267

* * *

This commit was sponsored by Neighbourhoodie

You can hire Neighbourhoodie for all your
Hoodie / CouchDB / Offline First needs
http://go.hood.ie/thehoodiefirm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants