From 1afc0c9e86025693a157df935edbe72d7296055d Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Wed, 1 Jul 2015 08:14:52 -0700 Subject: fs: fix error on bad listener type When the listener was truthy but NOT a function, fs.watchFile would throw an error through the EventEmitter. This caused a problem because it would only be thrown after the listener was started, which left the listener on. There should be no backwards compatability issues because the error was always thrown, just in a different manner. Also adds tests for this and other basic functionality. PR-URL: https://github.com/nodejs/io.js/pull/2093 Reviewed-By: Ben Noordhuis --- test/parallel/test-fs-watchfile.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/parallel/test-fs-watchfile.js (limited to 'test/parallel/test-fs-watchfile.js') diff --git a/test/parallel/test-fs-watchfile.js b/test/parallel/test-fs-watchfile.js new file mode 100644 index 0000000000..a64858ce0f --- /dev/null +++ b/test/parallel/test-fs-watchfile.js @@ -0,0 +1,17 @@ +'use strict'; + +const fs = require('fs'); +const assert = require('assert'); + +// Basic usage tests. +assert.throws(function() { + fs.watchFile('./some-file'); +}, /watchFile requires a listener function/); + +assert.throws(function() { + fs.watchFile('./another-file', {}, 'bad listener'); +}, /watchFile requires a listener function/); + +assert.throws(function() { + fs.watchFile(new Object(), function() {}); +}, /Path must be a string/); -- cgit v1.2.3