|
3 | 3 | import React from 'react';
|
4 | 4 | import { TouchableOpacity, Text } from 'react-native';
|
5 | 5 | import stripAnsi from 'strip-ansi';
|
6 |
| -import { debug } from '..'; |
| 6 | +import { debug, render, fireEvent, flushMicrotasksQueue } from '..'; |
7 | 7 |
|
8 | 8 | function TextComponent({ text }) {
|
9 | 9 | return <Text>{text}</Text>;
|
10 | 10 | }
|
11 | 11 |
|
12 |
| -class Button extends React.Component<*> { |
| 12 | +class Button extends React.Component<*, *> { |
| 13 | + state = { counter: 0 }; |
| 14 | + |
| 15 | + onPress = async () => { |
| 16 | + await Promise.resolve(); |
| 17 | + |
| 18 | + this.setState({ counter: 1 }); |
| 19 | + this.props.onPress(); |
| 20 | + }; |
| 21 | + |
13 | 22 | render() {
|
14 | 23 | return (
|
15 |
| - <TouchableOpacity onPress={this.props.onPress}> |
16 |
| - <TextComponent text={this.props.text} /> |
| 24 | + <TouchableOpacity onPress={this.onPress}> |
| 25 | + <TextComponent text={`${this.props.text} ${this.state.counter}`} /> |
17 | 26 | </TouchableOpacity>
|
18 | 27 | );
|
19 | 28 | }
|
@@ -58,3 +67,20 @@ test('debug.deep', () => {
|
58 | 67 |
|
59 | 68 | expect(console.log).toBeCalledWith(output, 'test message');
|
60 | 69 | });
|
| 70 | + |
| 71 | +test('debug.deep async test', async () => { |
| 72 | + // $FlowFixMe |
| 73 | + console.log = jest.fn(); |
| 74 | + const { toJSON, getByName } = render( |
| 75 | + <Button onPress={jest.fn} text="Press me" /> |
| 76 | + ); |
| 77 | + |
| 78 | + fireEvent.press(getByName('TouchableOpacity')); |
| 79 | + await flushMicrotasksQueue(); |
| 80 | + |
| 81 | + debug.deep(toJSON()); |
| 82 | + |
| 83 | + const output = console.log.mock.calls[0][0]; |
| 84 | + |
| 85 | + expect(stripAnsi(output)).toMatchSnapshot(); |
| 86 | +}); |
0 commit comments