|
| 1 | +// @flow |
| 2 | +/* eslint-disable no-console */ |
| 3 | +import React from 'react'; |
| 4 | +import { TouchableOpacity, Text } from 'react-native'; |
| 5 | +import stripAnsi from 'strip-ansi'; |
| 6 | +import { debug } from '..'; |
| 7 | + |
| 8 | +function TextComponent({ text }) { |
| 9 | + return <Text>{text}</Text>; |
| 10 | +} |
| 11 | + |
| 12 | +class Button extends React.Component<*> { |
| 13 | + render() { |
| 14 | + return ( |
| 15 | + <TouchableOpacity onPress={this.props.onPress}> |
| 16 | + <TextComponent text={this.props.text} /> |
| 17 | + </TouchableOpacity> |
| 18 | + ); |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +test('debug', () => { |
| 23 | + // $FlowFixMe |
| 24 | + console.log = jest.fn(); |
| 25 | + const component = <Button onPress={jest.fn} text="Press me" />; |
| 26 | + debug(component); |
| 27 | + |
| 28 | + const output = console.log.mock.calls[0][0]; |
| 29 | + |
| 30 | + expect(stripAnsi(output)).not.toEqual(output); |
| 31 | + expect(stripAnsi(output)).toMatchSnapshot(); |
| 32 | + |
| 33 | + console.log.mockReset(); |
| 34 | + |
| 35 | + debug(component, 'test message'); |
| 36 | + |
| 37 | + expect(console.log).toBeCalledWith(output, 'test message'); |
| 38 | +}); |
| 39 | + |
| 40 | +test('debug.shallow', () => { |
| 41 | + expect(debug.shallow).toBe(debug); |
| 42 | +}); |
| 43 | + |
| 44 | +test('debug.deep', () => { |
| 45 | + // $FlowFixMe |
| 46 | + console.log = jest.fn(); |
| 47 | + const component = <Button onPress={jest.fn} text="Press me" />; |
| 48 | + debug.deep(component); |
| 49 | + |
| 50 | + const output = console.log.mock.calls[0][0]; |
| 51 | + |
| 52 | + expect(stripAnsi(output)).not.toEqual(output); |
| 53 | + expect(stripAnsi(output)).toMatchSnapshot(); |
| 54 | + |
| 55 | + console.log.mockReset(); |
| 56 | + |
| 57 | + debug.deep(component, 'test message'); |
| 58 | + |
| 59 | + expect(console.log).toBeCalledWith(output, 'test message'); |
| 60 | +}); |
0 commit comments