Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Commit 23fd9fb

Browse files
committed
chore: cleanup comments in the code
1 parent 474c43a commit 23fd9fb

25 files changed

+48
-225
lines changed

examples/__tests__/input-event.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ test('It should allow a $ to be in the input when the value is changed', () => {
4949

5050
test('It should not allow letters to be inputted', () => {
5151
const { input } = setup();
52-
expect(input.props.value).toBe(''); // empty before
52+
expect(input.props.value).toBe('');
5353
fireEvent.change(input, { text: 'Good Day' });
54-
expect(input.props.value).toBe(''); //empty after
54+
expect(input.props.value).toBe('');
5555
});
5656

5757
test('It should allow the $ to be deleted', () => {
5858
const { input } = setup();
5959
fireEvent.change(input, { text: '23' });
60-
expect(input.props.value).toBe('$23'); // need to make a change so React registers "" as a change
60+
expect(input.props.value).toBe('$23');
6161
fireEvent.change(input, { text: '' });
6262
expect(input.props.value).toBe('');
6363
});

examples/__tests__/react-context.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@ import { Text } from 'react-native';
44
import { render } from '../../src';
55
import { NameContext, NameProvider, NameConsumer } from '../react-context';
66

7-
/**
8-
* Test default values by rendering a context consumer without a
9-
* matching provider
10-
*/
117
test('NameConsumer shows default value', () => {
128
const { getByText } = render(<NameConsumer />);
139
expect(getByText(/^My Name Is:/).props.children.join('')).toBe('My Name Is: Unknown');
1410
});
1511

16-
/**
17-
* To test a component tree that uses a context consumer but not the provider,
18-
* wrap the tree with a matching provider
19-
*/
2012
test('NameConsumer shows value from provider', () => {
2113
const tree = (
2214
<NameContext.Provider value="C3P0">
@@ -27,10 +19,6 @@ test('NameConsumer shows value from provider', () => {
2719
expect(getByText(/^My Name Is:/).props.children.join('')).toBe('My Name Is: C3P0');
2820
});
2921

30-
/**
31-
* To test a component that provides a context value, render a matching
32-
* consumer as the child
33-
*/
3422
test('NameProvider composes full name from first, last', () => {
3523
const tree = (
3624
<NameProvider first="Boba" last="Fett">
@@ -41,9 +29,6 @@ test('NameProvider composes full name from first, last', () => {
4129
expect(getByText(/^Received:/).props.children.join('')).toBe('Received: Boba Fett');
4230
});
4331

44-
/**
45-
* A tree containing both a provider and consumer can be rendered normally
46-
*/
4732
test('NameProvider/Consumer shows name of character', () => {
4833
const tree = (
4934
<NameProvider first="Leia" last="Organa">

examples/__tests__/react-navigation.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { createStackNavigator, createAppContainer, withNavigation } from 'react-
44

55
import { render, fireEvent } from '../../src';
66

7-
// React Navigation uses some packages that don't play nice with Jest
87
jest.mock('NativeAnimatedHelper').mock('react-native-gesture-handler', () => {
98
const View = require('react-native/Libraries/Components/View/View');
109
return {
@@ -15,7 +14,6 @@ jest.mock('NativeAnimatedHelper').mock('react-native-gesture-handler', () => {
1514
};
1615
});
1716

18-
// Even after the mocks, there are some warning message we'll want to filter out
1917
console.warn = arg => {
2018
const warnings = [
2119
'Calling .measureInWindow()',
@@ -55,8 +53,6 @@ const LocationDisplay = withNavigation(({ navigation }) => (
5553
<Text testID="location-display">{navigation.state.routeName}</Text>
5654
));
5755

58-
// this is a handy function that I would utilize for any component
59-
// that relies on the navigation being in context
6056
function renderWithNavigation({ screens = {}, navigatorConfig = {} } = {}) {
6157
const AppNavigator = createStackNavigator(
6258
{

examples/__tests__/react-redux.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { createStore } from 'redux';
44
import { Provider, connect } from 'react-redux';
55
import { render, fireEvent } from '../../src';
66

7-
// counter.js
87
class Counter extends React.Component {
98
increment = () => {
109
this.props.dispatch({ type: 'INCREMENT' });
@@ -28,13 +27,8 @@ class Counter extends React.Component {
2827
}
2928
}
3029

31-
// normally this would be:
32-
// export default connect(state => ({count: state.count}))(Counter)
33-
// but for this test we'll give it a variable name
34-
// because we're doing this all in one file
3530
const ConnectedCounter = connect(state => ({ count: state.count }))(Counter);
3631

37-
// app.js
3832
function reducer(state = { count: 0 }, action) {
3933
switch (action.type) {
4034
case 'INCREMENT':
@@ -50,27 +44,9 @@ function reducer(state = { count: 0 }, action) {
5044
}
5145
}
5246

53-
// normally here you'd do:
54-
// const store = createStore(reducer)
55-
// ReactDOM.render(
56-
// <Provider store={store}>
57-
// <Counter />
58-
// </Provider>,
59-
// document.getElementById('root'),
60-
// )
61-
// but for this test we'll umm... not do that :)
62-
63-
// Now here's what your test will look like:
64-
65-
// this is a handy function that I normally make available for all my tests
66-
// that deal with connected components.
67-
// you can provide initialState or the entire store that the ui is rendered with
6847
function renderWithRedux(ui, { initialState, store = createStore(reducer, initialState) } = {}) {
6948
return {
7049
...render(<Provider store={store}>{ui}</Provider>),
71-
// adding `store` to the returned utilities to allow us
72-
// to reference it in our tests (just try to avoid using
73-
// this to test implementation details).
7450
store,
7551
};
7652
}
@@ -90,7 +66,6 @@ test('can render with redux with custom initial state', () => {
9066
});
9167

9268
test('can render with redux with custom store', () => {
93-
// this is a silly store that can never be changed
9469
const store = createStore(() => ({ count: 1000 }));
9570
const { getByTestId, getByText } = renderWithRedux(<ConnectedCounter />, {
9671
store,

examples/__tests__/update-props.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// This is an example of how to update the props of a rendered component.
2-
// the basic idea is to simply call `render` again and provide the same container
3-
// that your first call created for you.
41
import React from 'react';
52
import { Text, View } from 'react-native';
63
import { render } from '../../src';
74

85
let idCounter = 1;
96

107
class NumberDisplay extends React.Component {
11-
id = idCounter++; // to ensure we don't remount a different instance
8+
id = idCounter++;
129
render() {
1310
return (
1411
<View>
@@ -23,7 +20,6 @@ test('calling render with the same component on the same container does not remo
2320
const { getByTestId, rerender } = render(<NumberDisplay number={1} />);
2421
expect(getByTestId('number-display').props.children).toEqual(1);
2522

26-
// re-render the same component with different props
2723
rerender(<NumberDisplay number={2} />);
2824
expect(getByTestId('number-display').props.children).toEqual(2);
2925

examples/react-hooks.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/__tests__/act.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import 'jest-dom/extend-expect';
32
import { Button } from 'react-native';
43

54
import { render, fireEvent } from '../';
@@ -24,9 +23,8 @@ test('fireEvent triggers useEffect calls', () => {
2423
}
2524
const { getByText } = render(<Counter />);
2625
const buttonNode = getByText('0');
27-
/**/
2826
effectCb.mockClear();
29-
fireEvent.press(buttonNode); /**/
27+
fireEvent.press(buttonNode);
3028
expect(buttonNode.props.children).toEqual('1');
3129
expect(effectCb).toHaveBeenCalledTimes(1);
3230
});

src/__tests__/end-to-end.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ComponentWithLoader extends React.Component {
1616
state = { loading: true };
1717
async componentDidMount() {
1818
const data = await fetchAMessage();
19-
this.setState({ data, loading: false }); // eslint-disable-line
19+
this.setState({ data, loading: false });
2020
}
2121
render() {
2222
if (this.state.loading) {

src/__tests__/fetch.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,17 @@ class Fetch extends React.Component {
3131
}
3232

3333
test('Fetch makes an API call and displays the greeting when load-greeting is clicked', async () => {
34-
// Arrange
3534
fetch.mockResponseOnce(JSON.stringify({ data: { greeting: 'hello there' } }));
3635
const url = '/greeting';
3736
const { container, getByText } = render(<Fetch url={url} />);
3837

39-
// Act
4038
fireEvent.press(getByText('Fetch'));
4139

4240
await wait();
4341

44-
// Assert
4542
expect(fetch).toHaveBeenCalledTimes(1);
4643
expect(fetch).toHaveBeenCalledWith(url);
47-
// this assertion is funny because if the textContent were not "hello there"
48-
// then the `getByText` would throw anyway... 🤔
44+
4945
expect(getByText('hello there').props.children).toEqual('hello there');
5046
expect(container).toMatchSnapshot();
5147
});

src/__tests__/forms.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ test('login form submits', () => {
2929

3030
const submitButtonNode = getByText('Submit');
3131

32-
// Act
3332
fireEvent.press(submitButtonNode);
3433

35-
// Assert
3634
expect(handleSubmit).toHaveBeenCalledTimes(1);
3735
expect(handleSubmit).toHaveBeenCalledWith(fakeUser);
3836
});

src/__tests__/matches.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { fuzzyMatches, matches } from '../matches';
22

3-
// unit tests for text match utils
4-
53
const node = null;
64
const normalizer = str => str;
75

src/__tests__/pretty-print.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Text } from 'react-native';
44
import { render } from '../';
55
import { prettyPrint } from '../pretty-print';
66

7-
test('it prints out the given DOM element tree', () => {
7+
test('it prints out the given element tree', () => {
88
const { container } = render(<Text>Hello World!</Text>);
99
expect(prettyPrint(container)).toMatchInlineSnapshot(`
1010
"<Text>

src/__tests__/queries.find.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { render } from '../.';
55

66
test('find asynchronously finds elements', async () => {
77
const {
8-
rootInstance,
9-
108
findByA11yLabel,
119
findAllByA11yLabel,
1210

@@ -76,11 +74,8 @@ test('find rejects when something cannot be found', async () => {
7674
findAllByTestId,
7775
} = render(<View />);
7876

79-
// I just don't want multiple lines for these.
80-
// qo = queryOptions
81-
// wo = waitForElementOptions
82-
const qo = {}; // query options
83-
const wo = { timeout: 10 }; // wait options
77+
const qo = {};
78+
const wo = { timeout: 10 };
8479

8580
await expect(findByA11yLabel('x', qo, wo)).rejects.toThrow('x');
8681
await expect(findAllByA11yLabel('x', qo, wo)).rejects.toThrow('x');
@@ -103,6 +98,6 @@ test('find rejects when something cannot be found', async () => {
10398

10499
test('actually works with async code', async () => {
105100
const { findByTestId, rerender, container } = render(<View />);
106-
setTimeout(() => rerender(<Text testID="text">correct dom</Text>), 20);
101+
setTimeout(() => rerender(<Text testID="text">correct tree</Text>), 20);
107102
await expect(findByTestId('text', {}, { container })).resolves.toBeTruthy();
108103
});

src/__tests__/render.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import React from 'react';
2-
import { Text, View } from 'react-native';
2+
import { View } from 'react-native';
33
import { render } from '../';
44

5-
test('renders View', () => {
6-
const ref = React.createRef();
7-
const { debug } = render(<View ref={ref} />);
8-
9-
debug(<Text>hi</Text>);
10-
});
11-
125
test('renders View', () => {
136
const ref = React.createRef();
147
const { rootInstance } = render(<View ref={ref} />);

src/__tests__/rerender.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ test('rerender will re-render the element', () => {
99

1010
const message = getByText('hi');
1111

12-
// console.log(message.props.children);
1312
expect(message.props.children).toEqual('hi');
1413
rerender(<Greeting message="hey" />);
1514
expect(message.props.children).toEqual('hey');

src/__tests__/stopwatch.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,9 @@ test('unmounts a component', async () => {
4343
jest.spyOn(console, 'error').mockImplementation(() => {});
4444
const { unmount, getByText, container } = render(<StopWatch />);
4545
fireEvent.press(getByText('Start'));
46+
4647
unmount();
47-
// hey there reader! You don't need to have an assertion like this one
48-
// this is just me making sure that the unmount function works.
49-
// You don't need to do this in your apps. Just rely on the fact that this works.
48+
5049
expect(container.toJSON()).toBeNull();
51-
// just wait to see if the interval is cleared or not
52-
// if it's not, then we'll call setState on an unmounted component
53-
// and get an error.
54-
// eslint-disable-next-line no-console
5550
await wait(() => expect(console.error).not.toHaveBeenCalled());
5651
});

0 commit comments

Comments
 (0)