[jest] SyntaxError: The string did not match the expected pattern

Jun 7, 2020 06:46 · 124 words · 1 minute read

axios を使った jest のテストで以下のようなエラーが出た

SyntaxError: The string did not match the expected pattern.

これは jest ランタイムだと axios が XMLHttpRequest を使おうとしてしまうため発生するエラーだったようだ

jest.config.js に testEnvironment: 'node' を追加すればよい

module.exports = {
  verbose: true,
  testEnvironment: 'node',
  ...

参考

tweet Share