Greed94
Greed94

Reputation: 178

React tests with IndexedDB

I want to mock indexedDB for test purposes, I have declared in App.test.js:

const Dexie = require("dexie");
require("fake-indexeddb/auto");
const db = new Dexie("PersonsDB");

And in package.json:

 {
...
  "devDependencies": {
    "@wojtekmaj/enzyme-adapter-react-17": "^0.6.2",
    "fake-indexeddb": "^3.1.3",
    "jest": "^26.6.0"
  },
  "jest": {
    "setupFiles": [
      "fake-indexeddb/auto"
    ]
  }
}

After that - I'm getting an error:"These options (setupFiles) in your package.json Jest configuration are not currently supported by Create React App:" I don't want to force override it.

How can I configure Jest to work with indexedDB?

Upvotes: 0

Views: 1260

Answers (1)

Greed94
Greed94

Reputation: 178

I had to add in setupTests.js:

require("fake-indexeddb/auto");

Upvotes: 3

Related Questions