You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have used jail-monkey for my app. But when i wrote the unit test, i found the problem like this: TypeError: Cannot read properties of undefined (reading 'rootedDetectionMethods')
This is my code and test
Code:
const onLoginPress = () => {
if (Platform.OS === 'ios') {
if (JailMonkey.isJailBroken()) {
// do something
return;
}
}
};
Test:
// Import the `jail-monkey` package
import JailMonkey from 'jail-monkey';
// Import any necessary components for your UI
import MyButton from './MyButton';
import MyJailbreakWarning from './MyJailbreakWarning';
describe('MyButton', () => {
it('should show jailbreak warning when clicked on jailbroken device', () => {
// Set the mock implementation to return true for jailbreak detection
JailMonkey.isJailBroken.mockReturnValueOnce(true);
// Render the component that contains the button and the jailbreak warning
const { getByText, getByTestId } = render(<MyButton />);
// Simulate a user click on the button
const button = getByTestId('my-button');
fireEvent.press(button);
// Expect the jailbreak warning component to be present in the rendered output
const jailbreakWarning = getByText('Warning: Your device is jailbroken.');
expect(jailbreakWarning).toBeDefined();
});
it('should not show jailbreak warning when clicked on non-jailbroken device', () => {
// Set the mock implementation to return false for jailbreak detection
JailMonkey.isJailBroken.mockReturnValueOnce(false);
// Render the component that contains the button and the jailbreak warning
const { getByText, getByTestId } = render(<MyButton />);
// Simulate a user click on the button
const button = getByTestId('my-button');
fireEvent.press(button);
// Expect the jailbreak warning component to not be present in the rendered output
const jailbreakWarning = queryByText('Warning: Your device is jailbroken.');
expect(jailbreakWarning).toBeNull();
});
});
Can anyone help me to explain why this issue occurs? Thanks 🤔
The text was updated successfully, but these errors were encountered:
ducminhleeh
changed the title
Failed unit test
Failed unit test: TypeError: Cannot read properties of undefined (reading 'rootedDetectionMethods')
Apr 17, 2023
jest.mock('react-native', () => {
const RN = jest.requireActual('react-native'); // use original implementation, which comes with mocks out of the box
RN.NativeModules.JailMonkey = jest.requireActual('jail-monkey');
return RN;
});
I have used
jail-monkey
for my app. But when i wrote the unit test, i found the problem like this:TypeError: Cannot read properties of undefined (reading 'rootedDetectionMethods')
This is my code and test
Code:
Test:
Can anyone help me to explain why this issue occurs? Thanks 🤔
The text was updated successfully, but these errors were encountered: