Checks whether current app instance is launched by Detox or not
yarn add react-native-is-detox
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 />;
}
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 />;
}
Import react-native-is-detox/jestSetup
in your Jest setup file.
import 'react-native-is-detox/jestSetup';
Original solution by Simon Buchan from this comment.
MIT