Skip to content

Colota - Android GPS Location tracker

1.5 KB
Raw Blame
/* eslint-env node, jest */
/**
 * Jest setup file
 * Provides mocks for React Native native modules and browser APIs
 */

// SVG and Lucide icon mocks
jest.mock("react-native-svg", () => {
  const React = require("react")
  const c = (tag) => {
    const Component = (props) => React.createElement(tag, props)
    Component.displayName = tag
    return Component
  }
  return {
    __esModule: true,
    default: c("svg"),
    Svg: c("svg"),
    Path: c("path"),
    Circle: c("circle"),
    Rect: c("rect"),
    Line: c("line"),
    G: c("g")
  }
})

jest.mock("lucide-react-native", () => {
  const React = require("react")
  return new Proxy(
    {},
    {
      get: (_, name) => {
        const Icon = (props) => React.createElement("View", { ...props, testID: `icon-${String(name)}` })
        Icon.displayName = String(name)
        return Icon
      }
    }
  )
})

// RN registers these globals in setUpTimers, which the jest preset never runs.
// Runs synchronously so deferred work lands inside act() - deferring it made
// waitFor race under parallel suite load.
global.requestIdleCallback = (cb) => {
  cb()
  return 0
}
global.cancelIdleCallback = () => {}

// AppState mock - RN exports AppState as .default from this path
jest.mock("react-native/Libraries/AppState/AppState", () => ({
  __esModule: true,
  default: {
    addEventListener: jest.fn(() => ({ remove: jest.fn() }))
  }
}))

const i18next = require("i18next")
const { I18N_OPTIONS } = require("./src/i18n/options")
i18next.init({ ...I18N_OPTIONS, lng: "en" })