mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
05db7bcaac
<!-- Please provide enough information so that others can review your pull request. --> <!-- Keep pull requests small and focused on a single change. --> ### Summary Adds API proposed by https://github.com/callstack/react-native-testing-library/pull/33#issuecomment-430302079. Also component output is now highlighted: <img width="259" alt="screenshot 2018-10-16 at 19 33 25" src="https://user-images.githubusercontent.com/5106466/47035614-c10efb80-d17a-11e8-99ac-00f648880008.png"> ### Test plan Added tests for `debug`.
61 lines
1.4 KiB
JavaScript
61 lines
1.4 KiB
JavaScript
// @flow
|
|
/* eslint-disable no-console */
|
|
import React from 'react';
|
|
import { TouchableOpacity, Text } from 'react-native';
|
|
import stripAnsi from 'strip-ansi';
|
|
import { debug } from '..';
|
|
|
|
function TextComponent({ text }) {
|
|
return <Text>{text}</Text>;
|
|
}
|
|
|
|
class Button extends React.Component<*> {
|
|
render() {
|
|
return (
|
|
<TouchableOpacity onPress={this.props.onPress}>
|
|
<TextComponent text={this.props.text} />
|
|
</TouchableOpacity>
|
|
);
|
|
}
|
|
}
|
|
|
|
test('debug', () => {
|
|
// $FlowFixMe
|
|
console.log = jest.fn();
|
|
const component = <Button onPress={jest.fn} text="Press me" />;
|
|
debug(component);
|
|
|
|
const output = console.log.mock.calls[0][0];
|
|
|
|
expect(stripAnsi(output)).not.toEqual(output);
|
|
expect(stripAnsi(output)).toMatchSnapshot();
|
|
|
|
console.log.mockReset();
|
|
|
|
debug(component, 'test message');
|
|
|
|
expect(console.log).toBeCalledWith(output, 'test message');
|
|
});
|
|
|
|
test('debug.shallow', () => {
|
|
expect(debug.shallow).toBe(debug);
|
|
});
|
|
|
|
test('debug.deep', () => {
|
|
// $FlowFixMe
|
|
console.log = jest.fn();
|
|
const component = <Button onPress={jest.fn} text="Press me" />;
|
|
debug.deep(component);
|
|
|
|
const output = console.log.mock.calls[0][0];
|
|
|
|
expect(stripAnsi(output)).not.toEqual(output);
|
|
expect(stripAnsi(output)).toMatchSnapshot();
|
|
|
|
console.log.mockReset();
|
|
|
|
debug.deep(component, 'test message');
|
|
|
|
expect(console.log).toBeCalledWith(output, 'test message');
|
|
});
|