Examples of tests that mock Node system APIs: fs, http, child_process, timers
Examples of tests that mock Node system APIs: fs, http, child_process, timers
Practical working test examples for blog post Mock system APIs. Because mocking the stable, well documented Node system APIs is easier than stubbing your own internal code. And simpler to update in the future!
fs
methods with sinon
fs
methodschild_process.exec
call using stub-spawn-once
child_process.spawn
call using stub-spawn-once
setInterval
(same for setTimeout
) with fake timers using sinon
All examples use Mocha test framework, but do not rely on anything Mocha-specific.
File an issue!
Author: Gleb Bahmutov [email protected] © 2017
License: MIT - do anything with the code, but don't blame me if it does not work.