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

Commit 6faa701

Browse files
author
Brandon Carroll
committed
feat: mostly the same api as DTL
1 parent e55e8ce commit 6faa701

24 files changed

+117
-109
lines changed

babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
module.exports = {
22
presets: ['module:metro-react-native-babel-preset'],
3+
overrides: [
4+
{
5+
compact: false,
6+
},
7+
],
38
};

examples/__tests__/react-intl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const renderWithReactIntl = component => {
3939
setupTests();
4040

4141
test('it should render FormattedDate and have a formatted pt date', () => {
42-
const { container } = renderWithReactIntl(<FormatDateView />);
42+
const { baseElement } = renderWithReactIntl(<FormatDateView />);
4343

44-
getByText(container, '11/03/2019');
44+
getByText(baseElement, '11/03/2019');
4545
});

examples/__tests__/react-navigation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function renderWithNavigation({ screens = {}, navigatorConfig = {} } = {}) {
5151

5252
const App = createAppContainer(AppNavigator);
5353

54-
return { ...render(<App detached />), navigationContainer: App };
54+
return { ...render(<App detached />), navigationBaseElement: App };
5555
}
5656

5757
test('full app rendering/navigating', async () => {

examples/__tests__/update-props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NumberDisplay extends React.Component {
1717
}
1818
}
1919

20-
test('calling render with the same component on the same container does not remount', () => {
20+
test('calling render with the same component on the same baseElement does not remount', () => {
2121
const { getByTestId, rerender } = render(<NumberDisplay number={1} />);
2222
expect(getByTestId('number-display')).toHaveTextContent(1);
2323

src/lib/__tests__/debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ afterEach(() => {
1111
console.log.mockRestore();
1212
});
1313

14-
test('debug pretty prints the container', () => {
14+
test('debug pretty prints the baseElement', () => {
1515
const HelloWorld = () => <Text>Hello World</Text>;
1616
const { debug } = render(<HelloWorld />);
1717
debug();

src/lib/__tests__/events.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Object.keys(eventMap).forEach(key => {
1313

1414
config.validTargets.forEach(element => {
1515
const handler = jest.fn();
16-
const { baseElement } = render(React.createElement(element, { [handlerName]: handler }));
16+
const { container } = render(React.createElement(element, { [handlerName]: handler }));
1717

18-
fireEvent[key](baseElement);
18+
fireEvent[key](container);
1919

2020
expect(handler).toHaveBeenCalledTimes(1);
2121
});
@@ -24,8 +24,8 @@ Object.keys(eventMap).forEach(key => {
2424

2525
test('onChange works', () => {
2626
const handleChange = jest.fn();
27-
const { baseElement } = render(<TextInput onChange={handleChange} />);
28-
fireEvent.change(baseElement, { target: { value: 'a' } });
27+
const { container } = render(<TextInput onChange={handleChange} />);
28+
fireEvent.change(container, { target: { value: 'a' } });
2929
expect(handleChange).toHaveBeenCalledTimes(1);
3030
});
3131

@@ -67,9 +67,9 @@ test('assigns target properties', async () => {
6767

6868
test('calling `fireEvent` directly works too', () => {
6969
const handleEvent = jest.fn();
70-
const { baseElement } = render(<Button onPress={handleEvent} title="test" />);
70+
const { container } = render(<Button onPress={handleEvent} title="test" />);
7171

72-
fireEvent(baseElement, new NativeEvent('press'));
72+
fireEvent(container, new NativeEvent('press'));
7373
expect(handleEvent).toBeCalledTimes(1);
7474
});
7575

@@ -78,8 +78,8 @@ test('calling a custom event works as well', () => {
7878
const onMyEvent = jest.fn(({ nativeEvent }) => expect(nativeEvent).toEqual({ value: 'testing' }));
7979
const MyComponent = ({ onMyEvent }) => <TextInput value="test" onChange={onMyEvent} />;
8080

81-
const { baseElement } = render(<MyComponent onMyEvent={onMyEvent} />);
82-
fireEvent(baseElement, new NativeEvent('myEvent', event));
81+
const { container } = render(<MyComponent onMyEvent={onMyEvent} />);
82+
fireEvent(container, new NativeEvent('myEvent', event));
8383

8484
expect(onMyEvent).toHaveBeenCalledWith({
8585
nativeEvent: { value: 'testing' },

src/lib/__tests__/fetch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Fetch extends React.Component {
3434
test('Fetch makes an API call and displays the greeting when load-greeting is clicked', async () => {
3535
fetch.mockResponseOnce(JSON.stringify({ data: { greeting: 'hello there' } }));
3636
const url = '/greeting';
37-
const { container, getByText } = render(<Fetch url={url} />);
37+
const { baseElement, getByText } = render(<Fetch url={url} />);
3838

3939
fireEvent.press(getByText('Fetch'));
4040

@@ -44,5 +44,5 @@ test('Fetch makes an API call and displays the greeting when load-greeting is cl
4444
expect(fetch).toHaveBeenCalledWith(url);
4545

4646
expect(getByText('hello there')).toHaveTextContent('hello there');
47-
expect(container).toMatchSnapshot();
47+
expect(baseElement).toMatchSnapshot();
4848
});

src/lib/__tests__/misc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import { Picker, View } from 'react-native';
44
import { fireEvent, render, queryByProp, queryByTestId } from '../';
55

66
test('queryByProp', () => {
7-
const { container } = render(
7+
const { baseElement } = render(
88
<View>
99
<View testID="foo" importantForAccessibility="no" />
1010
<View importantForAccessibility="no" />
1111
<View importantForAccessibility="no-hide-descendants" />
1212
</View>,
1313
);
1414

15-
expect(queryByTestId(container, 'foo')).not.toBeNull();
16-
expect(queryByProp('importantForAccessibility', container, 'auto')).toBeNull();
17-
expect(() => queryByProp('importantForAccessibility', container, /no/)).toThrow(
15+
expect(queryByTestId(baseElement, 'foo')).not.toBeNull();
16+
expect(queryByProp('importantForAccessibility', baseElement, 'auto')).toBeNull();
17+
expect(() => queryByProp('importantForAccessibility', baseElement, /no/)).toThrow(
1818
/multiple elements/,
1919
);
2020
});

src/lib/__tests__/pretty-print.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { render } from '../';
55
import { prettyPrint } from '../pretty-print';
66

77
test('it prints correctly with no children', () => {
8-
const { container } = render(<View />);
8+
const { baseElement } = render(<View />);
99

10-
expect(prettyPrint(container.toJSON())).toMatchInlineSnapshot(`"[36m<View />[39m"`);
10+
expect(prettyPrint(baseElement.toJSON())).toMatchInlineSnapshot(`"[36m<View />[39m"`);
1111
});
1212

1313
test('it prints correctly with one child', () => {
14-
const { container } = render(
14+
const { baseElement } = render(
1515
<View>
1616
<Text>Hello World!</Text>
1717
</View>,
1818
);
1919

20-
expect(prettyPrint(container.toJSON())).toMatchInlineSnapshot(`
20+
expect(prettyPrint(baseElement.toJSON())).toMatchInlineSnapshot(`
2121
"<View>
2222
<Text>
2323
Hello World!
@@ -27,14 +27,14 @@ test('it prints correctly with one child', () => {
2727
});
2828

2929
test('it prints correctly with multiple children', () => {
30-
const { container } = render(
30+
const { baseElement } = render(
3131
<View>
3232
<Text>Hello</Text>
3333
<Text>World!</Text>
3434
</View>,
3535
);
3636

37-
expect(prettyPrint(container.toJSON())).toMatchInlineSnapshot(`
37+
expect(prettyPrint(baseElement.toJSON())).toMatchInlineSnapshot(`
3838
"<View>
3939
<Text>
4040
Hello
@@ -47,11 +47,11 @@ test('it prints correctly with multiple children', () => {
4747
});
4848

4949
test('it supports truncating the output length', () => {
50-
const { container } = render(
50+
const { baseElement } = render(
5151
<View>
5252
<Text>Hello World!</Text>
5353
</View>,
5454
);
5555

56-
expect(prettyPrint(container.toJSON(), 5)).toMatch(/\.\.\./);
56+
expect(prettyPrint(baseElement.toJSON(), 5)).toMatch(/\.\.\./);
5757
});

src/lib/__tests__/render.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import { View } from 'react-native';
33
import { render } from '../';
44

55
test('renders View', () => {
6-
const { baseElement } = render(<View />);
7-
expect(baseElement).not.toBeNull();
6+
const { container } = render(<View />);
7+
expect(container).not.toBeNull();
88
});
99

10-
test('returns baseElement', () => {
11-
const { baseElement } = render(<View />);
12-
expect(baseElement).toBeTruthy();
10+
test('returns container', () => {
11+
const { container } = render(<View />);
12+
expect(container).toBeTruthy();
1313
});
1414

1515
test('renders options.wrapper around node', () => {
1616
const WrapperComponent = ({ children }) => <View testID="wrapper">{children}</View>;
1717

18-
const { container, getByTestId } = render(<View testID="inner" />, {
18+
const { baseElement, getByTestId } = render(<View testID="inner" />, {
1919
wrapper: WrapperComponent,
2020
});
2121

2222
expect(getByTestId('wrapper')).toBeTruthy();
23-
expect(container.toJSON()).toMatchInlineSnapshot(`
23+
expect(baseElement.toJSON()).toMatchInlineSnapshot(`
2424
<View
2525
testID="wrapper"
2626
>

0 commit comments

Comments
 (0)