Skip to content

[Testing]: npm test invokes error : too many open files, watch #11212

Description

@alamenai

I want to test my component using Enzyme and Jest but I got this error:

node:events:371
      throw er; // Unhandled 'error' event
      ^

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:204:21)
Emitted 'error' event on FSWatcher instance at:
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}

Package.json

{
   "name": "react-toast",
   "version": "0.1.0",
   "private": true,
   "dependencies": {
      "@testing-library/jest-dom": "^5.14.1",
      "@testing-library/react": "^11.2.7",
      "@testing-library/user-event": "^12.8.3",
      "react": "^17.0.2",
      "react-dom": "^17.0.2",
      "react-icons": "^4.2.0",
      "styled-components": "^5.3.0",
      "web-vitals": "^1.1.2"
   },
   "devDependencies": {
      "enzyme": "^3.11.0",
      "enzyme-adapter-react-16": "^1.15.6",
      "react-scripts": "^1.1.5"
   },
   "scripts": {
      "start": "react-scripts start",
      "build": "react-scripts build",
      "test": "react-scripts test",
      "eject": "react-scripts eject"
   },
   "eslintConfig": {
      "extends": [
         "react-app",
         "react-app/jest"
      ]
   },
   "browserslist": {
      "production": [
         ">0.2%",
         "not dead",
         "not op_mini all"
      ],
      "development": [
         "last 1 chrome version",
         "last 1 firefox version",
         "last 1 safari version"
      ]
   }
}

jest.config.json

{
   "jest": {
      "setupFilesAfterEnv": ["<rootDir>src/setupTests.js"]
   }
}

setupTests.js

// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '../jest.config.json';

Command test

npm test 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions