summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Roberts <sam@strongloop.com>2014-09-25 22:19:40 -0700
committerTrevor Norris <trev.norris@gmail.com>2014-11-18 16:19:52 -0800
commit2ff29cc7e35f486daf86710fd2db48275442c788 (patch)
tree3725e3020337df916d61a40713ce5f584367da72
parent13a992b1c2e1d0e69567fb94bc35f978c4c37ce5 (diff)
downloadnode-2ff29cc7e35f486daf86710fd2db48275442c788.tar.gz
test: use assert.throw to test exceptions
The test wasn't checking directly that an assertion was thrown. Instead, it was checking that spawn did not sucessfully spawn a non-existent command. However, the command chosen, dir, exists in GNU coreutils, so it exists on Linux (though not on BSD derived OS X). The test as written passed on Linux, even with the TypeError it is supposed to be checking for deleted from spawn(). It would also pass on Windows if a ls.exe existed. The approach is unnecessarily obscure, assert.throw() is for asserting code throws, using it is more clear and works regardless of what commands do or do not exist. PR-URL: https://github.com/joyent/node/pull/8454 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
-rw-r--r--test/simple/test-child-process-spawn-typeerror.js28
1 files changed, 8 insertions, 20 deletions
diff --git a/test/simple/test-child-process-spawn-typeerror.js b/test/simple/test-child-process-spawn-typeerror.js
index d18ce943e..d13d5e62e 100644
--- a/test/simple/test-child-process-spawn-typeerror.js
+++ b/test/simple/test-child-process-spawn-typeerror.js
@@ -19,30 +19,18 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-var spawn = require('child_process').spawn,
- assert = require('assert'),
- windows = (process.platform === 'win32'),
- cmd = (windows) ? 'dir' : 'ls',
- invalidcmd = (windows) ? 'ls' : 'dir',
- errors = 0;
+var assert = require('assert');
+var child_process = require('child_process');
+var spawn = child_process.spawn;
+var cmd = (process.platform === 'win32') ? 'dir' : 'ls';
-try {
- // Ensure this throws a TypeError
- var child = spawn(invalidcmd, 'this is not an array');
- child.on('error', function (err) {
- errors++;
- });
-
-} catch (e) {
- assert.equal(e instanceof TypeError, true);
-}
+// verify that args argument must be an array
+assert.throws(function() {
+ spawn(cmd, 'this is not an array');
+}, TypeError);
// verify that args argument is optional
assert.doesNotThrow(function() {
spawn(cmd, {});
});
-
-process.on('exit', function() {
- assert.equal(errors, 0);
-});