Z
Z
Zakhar Orlov2016-02-23 14:03:34
JavaScript
Zakhar Orlov, 2016-02-23 14:03:34

How to replace the result of calling a standard node.js module in tests?

The application uses child_process.exec(). Is it possible somehow to slip the prepared result exec()into the tests? something like mock. After all, CI does not have the program that I want to execute.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HoHsi, 2016-02-23
@divalign

const child_process = {};
child_process.exec = function () {
  // Все что угодно
}

If CP is used not in the test, but in the lib itself, then you can somehow pervert with the transfer of child_process as a parameter, then you can slip any functions instead of it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question