#react-native #sqlite #jestjs #expo
Вопрос:
У меня есть следующий код для тестирования expo-sqlite
,
import { openDatabase } from "expo-sqlite"
const db = openDatabase("test.db")
jest.useFakeTimers()
function sleep(duration = 1000) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(duration)
}, duration)
})
}
describe("orm", () => {
test("throws error if two different types is used on same column", async () => {
db.transaction(tsx => {
tsx.executeSql(`SELECT * FROM USERS`)
})
await sleep(1000)
})
})
Однако я получаю следующую ошибку,
TypeError: Cannot read property 'map' of undefined
at node_modules/expo-sqlite/src/SQLite.ts:27:41
Моя конфигурация Jest выглядит так,
{
"jest": {
"preset": "jest-expo",
"setupFiles": [
"./jest-setup.js"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?@react-native|react-native|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|@sentry/.*)"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}
И jest-setup.js
, например, следующее,
import "regenerator-runtime"
import "react-native-gesture-handler/jestSetup"
require("react-native-reanimated/lib/reanimated2/jestUtils").setUpTests()
jest.mock("react-native/Libraries/Utilities/Platform", () => {
const Platform = require.requireActual(
"react-native/Libraries/Utilities/Platform"
)
Platform.OS = "android"
return Platform
})