0

in my node.js app I have a function that should rename directory path when the user do a http put request. Anyway this function uses shelljs and when I test it manually it works but when I try to test in mocha on my mocked filesystem then shelljs run all the shell commands on my real file system.

How can I fix it?

btw I use mock-fs for this and I am very new to unit tests.

thanks

Amit

Amit
  • 126
  • 2
  • 10
  • 1
    This means that shelljs starts another process (as it's expected) which isn't affected by mocks in this process. In unit tests, you usually need to mock everything that produces side effects, including third-party units, which shelljs is. – Estus Flask Sep 04 '18 at 15:49

1 Answers1

0

I think ShellJS is generally compatible with mock-fs (I tried it locally, it seems to work). This assumes you're running ShellJS commands from the same process you ran mock-fs in (otherwise, please defer to estus's response).

nfischer
  • 181
  • 3