Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(user-event): Decouple press events from Jest dependency
  • Loading branch information
JoseLion committed Mar 13, 2024
commit c834440e2c60bffb8dd4604ae4f8f20a8610bc82
8 changes: 6 additions & 2 deletions src/user-event/event-builder/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function touch() {
timestamp: Date.now(),
touches: [],
},
persist: jest.fn(),
currentTarget: { measure: jest.fn() },
persist: noop,
currentTarget: { measure: noop },
target: {},
};
}
Expand Down Expand Up @@ -69,3 +69,7 @@ export const CommonEventBuilder = {
};
},
};

function noop(): void {
// do nothing
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,7 @@ exports[`userEvent.longPress with fake timers calls onLongPress if the delayLong
"name": "longPress",
"payload": {
"currentTarget": {
"measure": [MockFunction] {
"calls": [
[
[Function],
],
[
[Function],
],
],
"results": [
{
"type": "return",
"value": undefined,
},
{
"type": "return",
"value": undefined,
},
],
},
"measure": [Function],
},
"dispatchConfig": {
"registrationName": "onResponderGrant",
Expand All @@ -41,17 +22,7 @@ exports[`userEvent.longPress with fake timers calls onLongPress if the delayLong
"timestamp": 0,
"touches": [],
},
"persist": [MockFunction] {
"calls": [
[],
],
"results": [
{
"type": "return",
"value": undefined,
},
],
},
"persist": [Function],
"target": {},
},
},
Expand Down
61 changes: 6 additions & 55 deletions src/user-event/press/__tests__/__snapshots__/press.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,7 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu
"name": "pressIn",
"payload": {
"currentTarget": {
"measure": [MockFunction] {
"calls": [
[
[Function],
],
[
[Function],
],
],
"results": [
{
"type": "return",
"value": undefined,
},
{
"type": "return",
"value": undefined,
},
],
},
"measure": [Function],
},
"dispatchConfig": {
"registrationName": "onResponderGrant",
Expand All @@ -41,25 +22,15 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu
"timestamp": 0,
"touches": [],
},
"persist": [MockFunction] {
"calls": [
[],
],
"results": [
{
"type": "return",
"value": undefined,
},
],
},
"persist": [Function],
"target": {},
},
},
{
"name": "press",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"dispatchConfig": {
"registrationName": "onResponderRelease",
Expand All @@ -75,25 +46,15 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu
"timestamp": 0,
"touches": [],
},
"persist": [MockFunction] {
"calls": [
[],
],
"results": [
{
"type": "return",
"value": undefined,
},
],
},
"persist": [Function],
"target": {},
},
},
{
"name": "pressOut",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"dispatchConfig": {
"registrationName": "onResponderRelease",
Expand All @@ -109,17 +70,7 @@ exports[`userEvent.press with fake timers calls onPressIn, onPress and onPressOu
"timestamp": 0,
"touches": [],
},
"persist": [MockFunction] {
"calls": [
[],
],
"results": [
{
"type": "return",
"value": undefined,
},
],
},
"persist": [Function],
"target": {},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = `
"name": "pressIn",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -19,7 +19,7 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = `
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand All @@ -37,7 +37,7 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = `
"name": "pressOut",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -50,7 +50,7 @@ exports[`type() for managed TextInput supports basic case: input: "Wow" 1`] = `
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand Down Expand Up @@ -201,7 +201,7 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC"
"name": "pressIn",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -214,7 +214,7 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC"
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand All @@ -232,7 +232,7 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC"
"name": "pressOut",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -245,7 +245,7 @@ exports[`type() for managed TextInput supports rejecting TextInput: input: "ABC"
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand Down
32 changes: 16 additions & 16 deletions src/user-event/type/__tests__/__snapshots__/type.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1
"name": "pressIn",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -19,7 +19,7 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand All @@ -37,7 +37,7 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1
"name": "pressOut",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -50,7 +50,7 @@ exports[`type() supports backspace: input: "{Backspace}a", defaultValue: "xxx" 1
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand Down Expand Up @@ -162,7 +162,7 @@ exports[`type() supports basic case: input: "abc" 1`] = `
"name": "pressIn",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -175,7 +175,7 @@ exports[`type() supports basic case: input: "abc" 1`] = `
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand All @@ -193,7 +193,7 @@ exports[`type() supports basic case: input: "abc" 1`] = `
"name": "pressOut",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -206,7 +206,7 @@ exports[`type() supports basic case: input: "abc" 1`] = `
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand Down Expand Up @@ -357,7 +357,7 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`]
"name": "pressIn",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -370,7 +370,7 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`]
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand All @@ -388,7 +388,7 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`]
"name": "pressOut",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -401,7 +401,7 @@ exports[`type() supports defaultValue prop: input: "ab", defaultValue: "xxx" 1`]
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand Down Expand Up @@ -513,7 +513,7 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
"name": "pressIn",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -526,7 +526,7 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand All @@ -544,7 +544,7 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
"name": "pressOut",
"payload": {
"currentTarget": {
"measure": [MockFunction],
"measure": [Function],
},
"nativeEvent": {
"changedTouches": [],
Expand All @@ -557,7 +557,7 @@ exports[`type() supports multiline: input: "{Enter}\\n", multiline: true 1`] = `
"timestamp": 100100100100,
"touches": [],
},
"persist": [MockFunction],
"persist": [Function],
"target": {},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/user-event/utils/warn-about-real-timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { jestFakeTimersAreEnabled } from '../../helpers/timers';

export const warnAboutRealTimersIfNeeded = () => {
const areFakeTimersEnabled = jestFakeTimersAreEnabled();
if (areFakeTimersEnabled) {
if (process.env.RNTL_SKIP_AUTO_DETECT_FAKE_TIMERS || areFakeTimersEnabled) {
return;
}

Expand Down