Jasmine node testing child process.send

I have a node.js application that has the main process main-process.js and the child process child-process.js . main-process.js looks like this:

 var childProcess = require('child_process'); var job = childProcess.spawn('node', ["child-process.js"], { detached = true, stdio: ['ipc'] }); 

My child-process.js performs some task and notifies the parent process of its status, uses

 exports.init = function() { //some processing here process.send({status: 'success or pending'}); } 

Now I want unit test child-process.js to use jasmine-node. But when I call the init() method from the specification, the jasmine-node throws an error saying

 TypeError: Object #<process> has no method 'send' 

Is there a way to mock the process variable? In other words, how to make unit test this script?

+7
javascript unit-testing jasmine-node
source share

No one has answered this question yet.

See related questions:

2633
How to check for empty javascript object?
2560
How to check a private function or class with private methods, fields or inner classes?
2237
How to pass command line arguments to Node.js?
2201
How to decide when to use Node.js?
1648
How to quit Node.js
1517
How to debug Node.js applications?
1500
Writing Files to Node.js
1388
What is the purpose of Node.js module.exports and how do you use it?
1264
How to get started with Node.js
1116
Reading environment variables in Node.js

All Articles