Skip to content

Checks whether current app instance is launched by Detox or not

License

Notifications You must be signed in to change notification settings

jesperjohansson/react-native-is-detox

Repository files navigation

react-native-is-detox

Checks whether current app instance is launched by Detox or not

Installation

yarn add react-native-is-detox

Usage (async)

import { isDetox } from 'react-native-is-detox';

// ...

const result = await isDetox();

console.log('Was app launched by Detox?', result);
import { isDetox } from 'react-native-is-detox';

function App() {
  useEffect(() => {
    isDetox().then((result) => {
      console.log('Was app launched by Detox?', result);
    });
  }, []);

  return <MyApp />;
}

Usage (sync)

import { isDetoxSync } from 'react-native-is-detox';

const result = isDetoxSync();

console.log('Was app launched by Detox?', result);
import { isDetoxSync } from 'react-native-is-detox';

function App() {
  useEffect(() => {
    const result = isDetoxSync();
    console.log('Was app launched by Detox?', result);
  }, []);

  return <MyApp />;
}

Mock module in Jest

Import react-native-is-detox/jestSetup in your Jest setup file.

import 'react-native-is-detox/jestSetup';

Credits

Original solution by Simon Buchan from this comment.

License

MIT