eslint-plugin-detox

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript

ESLint environment plugin for Detox, an end-to-end testing framework for React Native applications. Version 1.0.0 is the latest stable release with no known release cadence. It provides a custom ESLint environment to enable global Detox variables (like `device`, `expect`, `element`, `by`, `waitFor`) in test files, preventing no-undef errors. Unlike generic ESLint settings, this plugin is tailored specifically for Detox's asynchronous UI testing helpers and should be combined with environments like mocha/jest. Statically releases with no frequent updates; works with ESLint 1.x+ and supports both npm and yarn.

error 'device' is not defined no-undef
cause The 'detox/detox' environment is not enabled in ESLint config.
fix
Add 'detox/detox' to the env section of .eslintrc or include comment: /* eslint-env detox/detox */
error Definition for rule 'detox/no-assertions' was not found
cause User attempted to use a rule from the plugin, but the plugin does not define any rules.
fix
Remove rule references prefixed with 'detox/'. The plugin only provides an environment.
gotcha The plugin only provides an environment; it does not include any custom rules. Developers might expect rules like 'detox/no-assertions' but they do not exist.
fix Use standard ESLint rules (e.g., 'no-undef') with the 'detox/detox' environment.
gotcha The environment must be used alongside a test runner environment (mocha, jest, etc.) to avoid missing globals like 'describe', 'it', etc.
fix Combine 'detox/detox' with 'mocha':true or 'jest':true in the env block.
npm install eslint-plugin-detox
yarn add eslint-plugin-detox
pnpm add eslint-plugin-detox

Shows how to install, configure ESLint with detox environment, and a sample Detox test using globals enabled by the plugin.

// Install dependencies
// npm install eslint eslint-plugin-detox --save-dev

// .eslintrc.json
{
  "plugins": ["detox"],
  "env": {
    "detox/detox": true,
    "mocha": true
  },
  "rules": {
    "no-undef": "error"
  }
}

// Then in your test file:
/* eslint-env detox/detox, mocha */
describe('Example', () => {
  beforeEach(async () => {
    await device.reloadReactNative();
  });

  it('should show hello screen', async () => {
    await expect(element(by.text('Hello'))).toBeVisible();
  });
});