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

Commit c215251

Browse files
author
Brandon Carroll
committed
test(events): test that touchables disable properly
1 parent efcdc0f commit c215251

File tree

3 files changed

+14
-47
lines changed

3 files changed

+14
-47
lines changed

examples/__tests__/docs.js

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

src/__tests__/events.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Button, Image, Text, TextInput } from 'react-native';
2+
import { Button, Image, Text, TextInput, TouchableHighlight } from 'react-native';
33

44
import { render, fireEvent } from '../';
55
import { NativeEvent } from '../events';
@@ -55,13 +55,24 @@ test('calling a handler when there is no valid target throws', () => {
5555
expect(handleEvent).toBeCalledTimes(0);
5656
});
5757

58-
test('calling a handler the target is disabled throws', () => {
58+
test('calling a handler if a Button is disabled throws', () => {
5959
const handleEvent = jest.fn();
6060
const { getByText } = render(<Button disabled onPress={handleEvent} title="button" />);
6161
expect(() => fireEvent.press(getByText('button'))).toThrow();
6262
expect(handleEvent).toBeCalledTimes(0);
6363
});
6464

65+
test('calling a handler if a Touchable is disabled throws', () => {
66+
const handleEvent = jest.fn();
67+
const { getByText } = render(
68+
<TouchableHighlight disabled onPress={jest.fn()}>
69+
<Text>touchable</Text>
70+
</TouchableHighlight>
71+
);
72+
expect(() => fireEvent.press(getByText('touchable'))).toThrow();
73+
expect(handleEvent).toBeCalledTimes(0);
74+
});
75+
6576
test('calling an event that has no defined handler throws', () => {
6677
const { getByText } = render(<Text>test</Text>);
6778
expect(() => fireEvent.press(getByText('test'))).toThrow();

src/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function findEventHandler(element, event) {
258258

259259
if (typeof element.props[eventHandler] === 'function' && valid) {
260260
if (disabled) {
261-
throw new Error(`A target was found for event: "${typeArg}", but the target is disabled!`);
261+
throw new Error(`A target was found for event: "${typeArg}", but the target is disabled`);
262262
}
263263
return element.props[eventHandler];
264264
}

0 commit comments

Comments
 (0)