Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regexp is not defined in Jest test

I have a module ./main.js that I am trying to test using ./__tests__/main-test.js. ./main.js uses new Regexp(REGEX, 'g') in one of its exported functions.

Running jest produces this error:

ReferenceError: Regexp is not defined

I thought it may be a mocking problem and added jest.unmock('Regexp') to main-test.js (even though it's not a required module), but got the same result.

What isn't Regexp defined?

like image 681
Matt Norris Avatar asked Mar 17 '16 21:03

Matt Norris


1 Answers

Cause it should be RegExp , case sensitive, remember? otherwise the interpreter is searching for an object called Regexp which is not the desired RegExp constructor.

like image 77
Roko C. Buljan Avatar answered Nov 05 '22 08:11

Roko C. Buljan