Created
February 20, 2013 11:49
-
-
Save SimonRichardson/4994980 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FUCK HEADS https://github.com/caolan/nodeunit#tests-run-in-series | |
// No -> | |
var _readFile = fs.readFile; | |
fs.readFile = function(path, callback){ | |
// its a stub! | |
}; | |
// test function that uses fs.readFile | |
// we're done | |
fs.readFile = _readFile; | |
// Yes | |
// Better -> but could be improved, if you create a wrapper for IO. | |
var FileProvider = { | |
get: function(path, callback) { | |
return fs.readFile(path, callback); | |
} | |
}; | |
var MockFileProvider = { | |
get: function() { | |
return // My stubby! | |
} | |
} | |
var file = FileProvider.get(path, callback); | |
// or | |
var file = MockFileProvider.get(path, callback); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Essentially they're testing the wrong code. There should be a mocking lib setup to spy or at least mock the fs.readFile. Don't method swizzle it.
Although it's fun to see who is using it :-)