Roy
Roy

Reputation: 2808

Jest "testRegex" throws "Unexpected token . in JSON"

I'm using jest to unit test my server and when I set the "testRegex" on my package.json to be

"testRegex": "(/test/.*|(\.|/)test)\.js$"

I get this error: Unexpected token . in JSON

Any ideas?

Upvotes: 0

Views: 489

Answers (1)

Michał Pierzchała
Michał Pierzchała

Reputation: 1850

"\." is invalid escape character in JSON. You need to escape the backslash:

"testRegex": "(/test/.*|(\\.|/)test)\\.js$"

Upvotes: 2

Related Questions