Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('* theme switching checks', () => {
const application: RenderAPI = render();
fireEvent(application.getByType(Button), 'press');
const { output } = shallow(application.getByType(ApplicationProvider));
const stringify = (obj: any): string => {
return JSON.stringify(obj);
};
// @ts-ignore just for theme prop changing
expect(stringify(output.props.theme)).toBe(JSON.stringify(themeInverse));
});
test('changes font color', () => {
const { getByType } = render();
const root = getByType(Text);
expect(StyleSheet.flatten(root.props.style)).not.toMatchObject({
color: expect.any(String)
});
fireEvent(root, 'mouseEnter');
expect(StyleSheet.flatten(root.props.style)).toMatchObject({
color: Theme.Color.Primary40
});
});
});
test('adds a bg color', () => {
const { getByProps } = render();
const root = getByProps({ accessibilityRole: 'link' });
expect(StyleSheet.flatten(root.props.style)).not.toMatchObject({
backgroundColor: expect.any(String)
});
fireEvent(root, 'mouseEnter');
expect(StyleSheet.flatten(root.props.style)).toMatchObject({
backgroundColor: Theme.Color.Primary00
});
});
it('* touchable other props', () => {
const onPressIn = jest.fn();
const onPressOut = jest.fn();
const component: RenderAPI = renderComponent({
onPressIn: onPressIn,
onPressOut: onPressOut,
});
fireEvent(component.getByType(TouchableOpacity), 'pressIn');
fireEvent(component.getByType(TouchableOpacity), 'pressOut');
expect(onPressIn).toHaveBeenCalled();
expect(onPressOut).toHaveBeenCalled();
});
it('checking of value reverse', () => {
let checked: boolean = true;
const onChangeValue = (changed: boolean) => {
checked = changed;
};
const component: RenderAPI = renderComponent({
checked: checked,
onChange: onChangeValue,
});
const { [0]: containerView } = component.getByType(ToggleComponent).children;
fireEvent(containerView as ReactTestInstance, 'responderRelease');
expect(checked).toBe(false);
});
it('active checked', async () => {
const component: RenderAPI = renderComponent({ checked: true });
fireEvent(component.getByType(TouchableOpacity), 'pressIn');
const active: ReactTestInstance = await waitForElement(() => {
return component.getByType(Radio);
});
const { output: activeOutput } = shallow(active);
fireEvent(component.getByType(TouchableOpacity), 'pressOut');
const inactive: ReactTestInstance = await waitForElement(() => {
return component.getByType(Radio);
});
const { output: inactiveOutput } = shallow(inactive);
expect(activeOutput).toMatchSnapshot();
expect(inactiveOutput).toMatchSnapshot('checked');
});
it('* emits onBlur', () => {
const onBlur = jest.fn();
const component: RenderAPI = renderComponent({ onBlur });
fireEvent(component.getByType(TextInput), 'blur');
expect(onBlur).toBeCalled();
});
it('* menu item onPress prop checks', () => {
const onPress = jest.fn();
const title: string = 'Option';
const menuItem: RenderAPI = render(
<menuitem title="{title}">
</menuitem>,
);
fireEvent(menuItem.getAllByText(title)[0], 'press');
expect(onPress).toHaveBeenCalled();
});
const onLongPress = jest.fn();
const title: string = 'Option';
const menuItem: RenderAPI = render(
<menuitem title="{title}">
</menuitem>,
);
fireEvent(menuItem.getAllByText(title)[0], 'press');
fireEvent(menuItem.getAllByText(title)[0], 'pressIn');
fireEvent(menuItem.getAllByText(title)[0], 'pressOut');
fireEvent(menuItem.getAllByText(title)[0], 'longPress');
expect(onLongPress).toHaveBeenCalled();
});
icon={(style: StyleType) => <img style="{style}/">}
title='Screen 1'
selected={false}/>
<img style="{style}/">}
title='Screen 2'
selected={true}/>
<img style="{style}/">}
title='Screen 3'
selected={false}/>
,
);
fireEvent(component.getByTestId(tabTestId), 'select');
expect(component).toMatchSnapshot();
expect(onSelect).toHaveBeenCalled();
});