5

Recently migrated from mocha to jest and I'm running into an issue. I have lots of warnings in my tests:

[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()

Now, adding the following line to each file fixes the issue, but only for that specific test file:

jest.mock('node-uuid', () => ({ v4: jest.fn(() => 1) }));

I'm hoping there's a way to mock node-uuid globally for all tests instead of individual files? I've done a bunch of searches and tried different techniques in my setup file, but to no avail.

4

1 回答 1

17

您可以在目录 所在的目录中定义手动模拟[root]/__mocks__/node-uuid.js[root]node_modules

module.exports = { v4: jest.fn(() => 1) }
于 2017-11-25T16:33:07.083 回答