Catch error caused by exporting an undefined
suite, print helpful message when caught
#261
Labels
undefined
suite, print helpful message when caught
#261
On the website with the documentation for Vows - http://vowsjs.org - there is a sequence of examples that is illuminating, but can lead to problems when you're following its example in your own project (for the first time).
There are a two main ways to run your tests.
First, you can call
run()
on a suite, then execute withnode
. In a line:Then you run it with
node test.js
.Second, you can export your suite(s) and use
vows
to run it. The documentation demonstrates two variations on this:Then you can run it with
vows
.But you encounter a pitfall if you are trying out the different ways and you accidentally mix them like so:
When you try to run the test with
vows
, you get the following error message:Speaking as someone new to Vows (and Node.js in general), this error is rather confusing until you look under the hood. Of course, the issue is actually simple:
run()
doesn't have a return value. That meansexports.suite
is being set toundefined
, and then an exception gets thrown whenimportSuites
(inbin/vows
) tries to set a property on this object.I can't imagine I'm the only one this has happened to, so perhaps this error could be caught by the
bin/vows
script, with an instructive suggestion that might illuminate the solution for a new user.If you think this mistake seems too obvious, imagine it's your first time dealing with a snippet like this:
It's a mistake that's easy to miss when you're first picking up Vows.
The text was updated successfully, but these errors were encountered: