From ba4fa49c9067b890a057336c61935b2ca8690632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Thu, 24 Oct 2024 09:13:01 +0200 Subject: [PATCH 1/4] chore: add Animated tests --- jest.config.js | 2 +- package.json | 2 +- src/__tests__/react-native-animated.tsx | 68 ++++++++++++ yarn.lock | 132 ++++++++++++------------ 4 files changed, 136 insertions(+), 68 deletions(-) create mode 100644 src/__tests__/react-native-animated.tsx diff --git a/jest.config.js b/jest.config.js index d99aa4dc6..5018adce5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,7 @@ module.exports = { preset: './jest-preset', setupFilesAfterEnv: ['./jest-setup.ts'], - testPathIgnorePatterns: ['timer-utils', 'examples/', 'experiments-app/', 'experiments-rtl/'], + testPathIgnorePatterns: ['build/', 'examples/', 'experiments-app/', 'timer-utils'], testTimeout: 60000, transformIgnorePatterns: ['/node_modules/(?!(@react-native|react-native)/).*/'], snapshotSerializers: ['@relmify/jest-serializer-strip-ansi/always'], diff --git a/package.json b/package.json index b8adbaeaf..d4bb14aa2 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "jest": "^29.7.0", "prettier": "^2.8.8", "react": "18.3.1", - "react-native": "0.76.0-rc.6", + "react-native": "0.76.0", "react-test-renderer": "18.3.1", "release-it": "^17.6.0", "strip-ansi": "^6.0.1", diff --git a/src/__tests__/react-native-animated.tsx b/src/__tests__/react-native-animated.tsx new file mode 100644 index 000000000..c39b87daa --- /dev/null +++ b/src/__tests__/react-native-animated.tsx @@ -0,0 +1,68 @@ +import * as React from 'react'; +import { Animated, ViewStyle } from 'react-native'; +import { act, render, screen } from '..'; +import '../matchers/extend-expect'; + +type AnimatedViewProps = { + fadeInDuration?: number; + style?: ViewStyle; + children: React.ReactNode; + useNativeDriver?: boolean; +}; + +function AnimatedView(props: AnimatedViewProps) { + const fadeAnim = React.useRef(new Animated.Value(0)).current; // Initial value for opacity: 0 + + React.useEffect(() => { + Animated.timing(fadeAnim, { + toValue: 1, + duration: props.fadeInDuration ?? 250, + useNativeDriver: props.useNativeDriver ?? true, + }).start(); + }, [fadeAnim, props.fadeInDuration, props.useNativeDriver]); + + return ( + + {props.children} + + ); +} + +describe('AnimatedView', () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + it('should use native driver when useNativeDriver is true', async () => { + render( + + Test + , + ); + expect(screen.root).toHaveStyle({ opacity: 0 }); + + await act(() => jest.advanceTimersByTime(250)); + expect(screen.root).toHaveStyle({ opacity: 1 }); + }); + + it('should not use native driver when useNativeDriver is false', async () => { + render( + + Test + , + ); + expect(screen.root).toHaveStyle({ opacity: 0 }); + + await act(() => jest.advanceTimersByTime(250)); + expect(screen.root).toHaveStyle({ opacity: 1 }); + }); +}); diff --git a/yarn.lock b/yarn.lock index d65b82e02..4b580a77c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2311,25 +2311,25 @@ __metadata: languageName: node linkType: hard -"@react-native/assets-registry@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/assets-registry@npm:0.76.0-rc.6" - checksum: 10c0/1b56e945d826c30caa9392cf111086ffc88cd9dfe28058d1f85f570f5d8684336633170ad1b9181949c13c7e1b7c3bf8cb1b382219a5426d9988850a2740c709 +"@react-native/assets-registry@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/assets-registry@npm:0.76.0" + checksum: 10c0/a8543167afbd2a2d63ec8518f41efddbb3de39ad5905cb98002fdfad7441ade6ae05d86321aea43e366fa9b2336a9bca67d14c89f064e5c7064cd98334ba82c0 languageName: node linkType: hard -"@react-native/babel-plugin-codegen@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/babel-plugin-codegen@npm:0.76.0-rc.6" +"@react-native/babel-plugin-codegen@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/babel-plugin-codegen@npm:0.76.0" dependencies: - "@react-native/codegen": "npm:0.76.0-rc.6" - checksum: 10c0/78a3b9d17a3dfb7aace63a30e2fc7970f93f8439ebf4a97ee66058c54d336ace0a723b16edd8666c2f6bf88225b7c449c11934f9731f40b19ebb4657bcaf28ad + "@react-native/codegen": "npm:0.76.0" + checksum: 10c0/c1816b80c0cde1f48f91584f873ad5740669c6324c533239ccc7131fbbbc6b810ca2a0d7e8da21783e004a7dc2660b2501a868b4375ba835679eb05d1c239044 languageName: node linkType: hard -"@react-native/babel-preset@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/babel-preset@npm:0.76.0-rc.6" +"@react-native/babel-preset@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/babel-preset@npm:0.76.0" dependencies: "@babel/core": "npm:^7.25.2" "@babel/plugin-proposal-export-default-from": "npm:^7.24.7" @@ -2372,19 +2372,19 @@ __metadata: "@babel/plugin-transform-typescript": "npm:^7.25.2" "@babel/plugin-transform-unicode-regex": "npm:^7.24.7" "@babel/template": "npm:^7.25.0" - "@react-native/babel-plugin-codegen": "npm:0.76.0-rc.6" + "@react-native/babel-plugin-codegen": "npm:0.76.0" babel-plugin-syntax-hermes-parser: "npm:^0.23.1" babel-plugin-transform-flow-enums: "npm:^0.0.2" react-refresh: "npm:^0.14.0" peerDependencies: "@babel/core": "*" - checksum: 10c0/8d7d0eaf9d44c7b797306f040200644e2bcb324b0256e07a859143b14398a3be8b75c79871def21e57d4628268d4adaec11a12cd5d37090f2ebe2897341232c8 + checksum: 10c0/43074771fe1c74379d3fdefa54b15e60c08b7cbc4649e1c0ab53d3d86e3776ad4ca5627985b6e98bab9c5927cf1fcf820a66fb5397d5ffb4174de33ed8b8877b languageName: node linkType: hard -"@react-native/codegen@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/codegen@npm:0.76.0-rc.6" +"@react-native/codegen@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/codegen@npm:0.76.0" dependencies: "@babel/parser": "npm:^7.25.3" glob: "npm:^7.1.1" @@ -2396,16 +2396,16 @@ __metadata: yargs: "npm:^17.6.2" peerDependencies: "@babel/preset-env": ^7.1.6 - checksum: 10c0/4f806b77037758040894f88b4db78c6c1600e9e5cbfa7e87a5e369a9b33f10594840d800486ec23e4f93ff0a6ef168d391c85f7ed7e6fab8f6bccb65e1a636d3 + checksum: 10c0/0cdad654b4f4b86ad526188f5adda59dd9f1b38057749580c72e21e58b1183d8e7593fc7b8614dd1330b101fd4418d2f96d4c0e5af70ad2f2fc1639b1832d76f languageName: node linkType: hard -"@react-native/community-cli-plugin@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/community-cli-plugin@npm:0.76.0-rc.6" +"@react-native/community-cli-plugin@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/community-cli-plugin@npm:0.76.0" dependencies: - "@react-native/dev-middleware": "npm:0.76.0-rc.6" - "@react-native/metro-babel-transformer": "npm:0.76.0-rc.6" + "@react-native/dev-middleware": "npm:0.76.0" + "@react-native/metro-babel-transformer": "npm:0.76.0" chalk: "npm:^4.0.0" execa: "npm:^5.1.1" invariant: "npm:^2.2.4" @@ -2419,23 +2419,23 @@ __metadata: peerDependenciesMeta: "@react-native-community/cli-server-api": optional: true - checksum: 10c0/f9282893c10a95ff770a57568d5ef56af8993ef93d1f1008423616f76f0ec486f784779db185619107883eb3d985085f22006478dd35704f097ea52c399288d9 + checksum: 10c0/b7bf144542264e52bdc49e124a6613debc9c590283999e3e6ef420b36cbb77578f99f05a9ca57dd802e042108a6b5a46428014f9d1f6fe48c18a8b52f9697801 languageName: node linkType: hard -"@react-native/debugger-frontend@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/debugger-frontend@npm:0.76.0-rc.6" - checksum: 10c0/f7165edf061faa9cc4f70b5b537f84489f6cecfe6e11995a32fac1e699db0eaef9c6a8756596a2e0ee2d07269b3d5eaadc1e680b2d61a60162b2663e30c0cba6 +"@react-native/debugger-frontend@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/debugger-frontend@npm:0.76.0" + checksum: 10c0/115db2f3fab68791606bea674718fb96ed684754f346a4d3e12f44f2486cb0bb0935c6c7bce318bcf5be8010eca4e111e0ae74a591c8f845d0e106a5ecac2dbf languageName: node linkType: hard -"@react-native/dev-middleware@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/dev-middleware@npm:0.76.0-rc.6" +"@react-native/dev-middleware@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/dev-middleware@npm:0.76.0" dependencies: "@isaacs/ttlcache": "npm:^1.4.1" - "@react-native/debugger-frontend": "npm:0.76.0-rc.6" + "@react-native/debugger-frontend": "npm:0.76.0" chrome-launcher: "npm:^0.15.2" chromium-edge-launcher: "npm:^0.2.0" connect: "npm:^3.6.5" @@ -2445,7 +2445,7 @@ __metadata: selfsigned: "npm:^2.4.1" serve-static: "npm:^1.13.1" ws: "npm:^6.2.3" - checksum: 10c0/e2e61b8bbfef3dd4e1d7e18019884c63e5880f208b43b365a17a8acd0e4787fb0cae47a925de41ff2f7d48fd577d44ec00f6262f854e67c769a8e55382a11db9 + checksum: 10c0/b39deb0db79a2e8cc7b72417fdbbb3907dc7c178a8974cce928e7acf061e961793c9fa3ce2f1dfda53a6fcc5e5bcdf00bd37b291e0b0d860e6d6970159115362 languageName: node linkType: hard @@ -2456,44 +2456,44 @@ __metadata: languageName: node linkType: hard -"@react-native/gradle-plugin@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/gradle-plugin@npm:0.76.0-rc.6" - checksum: 10c0/709fca442b5f361f17f4e11b6933d6ff3f2218068fd362f4dd869a6561b18a42d2fdc6697c5bdebd78481a03a5859b394f47256f89ffbc0ae3194fcc33b7f5c3 +"@react-native/gradle-plugin@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/gradle-plugin@npm:0.76.0" + checksum: 10c0/4d88a2df24356a4c9ea9438bb2ff623377d69276802e7a3dfa6e441cbc79a42f0ca216abec8a55d104e4146c72f8e4404c06cd7a4071bc91af9a733966689637 languageName: node linkType: hard -"@react-native/js-polyfills@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/js-polyfills@npm:0.76.0-rc.6" - checksum: 10c0/1f52ea386de0ee00bad058dd3036a7f7470518720bbc2d1d0041ecf48ace7b2906bd7611c448c433592866a3373b84a65f40457506c54d40a73a1e9e947c04da +"@react-native/js-polyfills@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/js-polyfills@npm:0.76.0" + checksum: 10c0/ca9ed75a1920ae84ca393d22681fa7d99482ee627e6f6e30c83eb513554a905029d40ffb019c63b57b8548d8ffd3e1160c86f667b91c6ec21dd1d22aefad7215 languageName: node linkType: hard -"@react-native/metro-babel-transformer@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/metro-babel-transformer@npm:0.76.0-rc.6" +"@react-native/metro-babel-transformer@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/metro-babel-transformer@npm:0.76.0" dependencies: "@babel/core": "npm:^7.25.2" - "@react-native/babel-preset": "npm:0.76.0-rc.6" + "@react-native/babel-preset": "npm:0.76.0" hermes-parser: "npm:0.23.1" nullthrows: "npm:^1.1.1" peerDependencies: "@babel/core": "*" - checksum: 10c0/1b3d927f5abc930851f11811a3204c450918cd7ae64b560c35c6015333e8b5b9d2f611d5deb1897c9c1b006103d9032bf13872b7885dd64786a6dd9419868e0a + checksum: 10c0/1d425615136e2f951dd153f8fd7d41e7fbf41fbbc6d205335d3863a67c0ab51f0e9e7804e506012bbd52dcb229bfeee6d6d6264eac3a9499439e7db823b4d708 languageName: node linkType: hard -"@react-native/normalize-colors@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/normalize-colors@npm:0.76.0-rc.6" - checksum: 10c0/648f1aef7ed9b3036f05664948bf0fc95aba11ba8412a188891427cc45a0198d523f1bdecbb41e195a1f2806d86eed62e3bd29a2aec288d94513c5e390d07e12 +"@react-native/normalize-colors@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/normalize-colors@npm:0.76.0" + checksum: 10c0/4218ef1f785ab5f4d9fe29a314abdce9e1ba5a193cb8b0f2c8fa821bb72c33c54548bda2128c6de488f055898e407e8553db1adecd6cbe34503f2b55e9e35c0f languageName: node linkType: hard -"@react-native/virtualized-lists@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "@react-native/virtualized-lists@npm:0.76.0-rc.6" +"@react-native/virtualized-lists@npm:0.76.0": + version: 0.76.0 + resolution: "@react-native/virtualized-lists@npm:0.76.0" dependencies: invariant: "npm:^2.2.4" nullthrows: "npm:^1.1.1" @@ -2504,7 +2504,7 @@ __metadata: peerDependenciesMeta: "@types/react": optional: true - checksum: 10c0/1e87281b87105d6d8198644dc7b0eefe9996dc9c29f4ae585e87a2e66344f3874115dd7ab1fe2625643529ecb43b4b1e8b0af5bcb69b878c227273147863e07c + checksum: 10c0/37979b170b9ac4768efb4306c05424613f7f7339b3496fd7eeac074b1439a3b16323d5cd91a94d81ee314c5841e238c49a25401a4e6cfbd06d9c87424796c79f languageName: node linkType: hard @@ -2597,7 +2597,7 @@ __metadata: prettier: "npm:^2.8.8" pretty-format: "npm:^29.7.0" react: "npm:18.3.1" - react-native: "npm:0.76.0-rc.6" + react-native: "npm:0.76.0" react-test-renderer: "npm:18.3.1" redent: "npm:^3.0.0" release-it: "npm:^17.6.0" @@ -8992,18 +8992,18 @@ __metadata: languageName: node linkType: hard -"react-native@npm:0.76.0-rc.6": - version: 0.76.0-rc.6 - resolution: "react-native@npm:0.76.0-rc.6" +"react-native@npm:0.76.0": + version: 0.76.0 + resolution: "react-native@npm:0.76.0" dependencies: "@jest/create-cache-key-function": "npm:^29.6.3" - "@react-native/assets-registry": "npm:0.76.0-rc.6" - "@react-native/codegen": "npm:0.76.0-rc.6" - "@react-native/community-cli-plugin": "npm:0.76.0-rc.6" - "@react-native/gradle-plugin": "npm:0.76.0-rc.6" - "@react-native/js-polyfills": "npm:0.76.0-rc.6" - "@react-native/normalize-colors": "npm:0.76.0-rc.6" - "@react-native/virtualized-lists": "npm:0.76.0-rc.6" + "@react-native/assets-registry": "npm:0.76.0" + "@react-native/codegen": "npm:0.76.0" + "@react-native/community-cli-plugin": "npm:0.76.0" + "@react-native/gradle-plugin": "npm:0.76.0" + "@react-native/js-polyfills": "npm:0.76.0" + "@react-native/normalize-colors": "npm:0.76.0" + "@react-native/virtualized-lists": "npm:0.76.0" abort-controller: "npm:^3.0.0" anser: "npm:^1.4.9" ansi-regex: "npm:^5.0.0" @@ -9042,7 +9042,7 @@ __metadata: optional: true bin: react-native: cli.js - checksum: 10c0/98d260a1de63fc26c131571475e775608b1838a0ca2c637d6308b04595636fd31054392e8a6e822946a8e2e337e3b71c8c0802d9ac358828419f5dbd446303d5 + checksum: 10c0/a24304cc08e3409a820704c4f45f47b994d72906835abb32e8b5289de2bcb6e1f029cba0238163fce88fb7dde6c1b8624934ec4ad937902dc08ee15e7db43503 languageName: node linkType: hard From 40dd5900e28967d25da5fb9578c3fe2b91c7670e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Thu, 24 Oct 2024 09:13:32 +0200 Subject: [PATCH 2/4] chore: add AnimatedView tests --- examples/basic/components/AnimatedView.tsx | 32 +++++++++++++++++ .../components/__tests__/AnimatedView.tsx | 34 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 examples/basic/components/AnimatedView.tsx create mode 100644 examples/basic/components/__tests__/AnimatedView.tsx diff --git a/examples/basic/components/AnimatedView.tsx b/examples/basic/components/AnimatedView.tsx new file mode 100644 index 000000000..d2f2a2e12 --- /dev/null +++ b/examples/basic/components/AnimatedView.tsx @@ -0,0 +1,32 @@ +import * as React from 'react'; +import { Animated, ViewStyle } from 'react-native'; + +type AnimatedViewProps = { + fadeInDuration?: number; + style?: ViewStyle; + children: React.ReactNode; + useNativeDriver?: boolean; +}; + +export function AnimatedView(props: AnimatedViewProps) { + const fadeAnim = React.useRef(new Animated.Value(0)).current; // Initial value for opacity: 0 + + React.useEffect(() => { + Animated.timing(fadeAnim, { + toValue: 1, + duration: props.fadeInDuration ?? 250, + useNativeDriver: props.useNativeDriver ?? true, + }).start(); + }, [fadeAnim]); + + return ( + + {props.children} + + ); +} diff --git a/examples/basic/components/__tests__/AnimatedView.tsx b/examples/basic/components/__tests__/AnimatedView.tsx new file mode 100644 index 000000000..8a3309aee --- /dev/null +++ b/examples/basic/components/__tests__/AnimatedView.tsx @@ -0,0 +1,34 @@ +import { act, render, screen } from '@testing-library/react-native'; +import { AnimatedView } from '../AnimatedView'; + +describe('AnimatedView', () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + it('should use native driver when useNativeDriver is true', async () => { + render( + + Test + , + ); + expect(screen.root).toHaveStyle({ opacity: 0 }); + await act(() => jest.advanceTimersByTime(250)); + expect(screen.root).toHaveStyle({ opacity: 1 }); + }); + + it('should not use native driver when useNativeDriver is false', async () => { + render( + + Test + , + ); + expect(screen.root).toHaveStyle({ opacity: 0 }); + await act(() => jest.advanceTimersByTime(250)); + expect(screen.root).toHaveStyle({ opacity: 1 }); + }); +}); From ab9438c973baaf16c058ab7a8cc9b33ae6807f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Thu, 24 Oct 2024 09:18:38 +0200 Subject: [PATCH 3/4] chore: extend `expect` by default in internal tests --- jest-setup.ts | 1 + src/__tests__/fire-event.test.tsx | 1 - src/__tests__/react-native-animated.tsx | 1 - src/matchers/__tests__/extend-expect.test.tsx | 13 ------------- src/matchers/__tests__/to-be-busy.test.tsx | 1 - src/matchers/__tests__/to-be-checked.test.tsx | 1 - src/matchers/__tests__/to-be-disabled.test.tsx | 1 - src/matchers/__tests__/to-be-empty-element.test.tsx | 1 - src/matchers/__tests__/to-be-expanded.test.tsx | 1 - src/matchers/__tests__/to-be-on-the-screen.test.tsx | 1 - .../__tests__/to-be-partially-checked.test.tsx | 1 - src/matchers/__tests__/to-be-selected.test.tsx | 1 - src/matchers/__tests__/to-be-visible.test.tsx | 1 - src/matchers/__tests__/to-contain-element.test.tsx | 1 - .../__tests__/to-have-accessibility-value.test.tsx | 1 - .../__tests__/to-have-accessible-name.test.tsx | 1 - .../__tests__/to-have-display-value.test.tsx | 1 - src/matchers/__tests__/to-have-prop.test.tsx | 1 - src/matchers/__tests__/to-have-style.test.tsx | 1 - .../__tests__/to-have-text-content.test.tsx | 1 - src/user-event/__tests__/clear.test.tsx | 1 - src/user-event/__tests__/paste.test.tsx | 1 - .../scroll/__tests__/scroll-to-flat-list.test.tsx | 1 - src/user-event/type/__tests__/type.test.tsx | 1 - 24 files changed, 1 insertion(+), 35 deletions(-) delete mode 100644 src/matchers/__tests__/extend-expect.test.tsx diff --git a/jest-setup.ts b/jest-setup.ts index f120a77e7..a4d893a18 100644 --- a/jest-setup.ts +++ b/jest-setup.ts @@ -1,4 +1,5 @@ import { resetToDefaults } from './src/pure'; +import './src/matchers/extend-expect'; beforeEach(() => { resetToDefaults(); diff --git a/src/__tests__/fire-event.test.tsx b/src/__tests__/fire-event.test.tsx index 2adf0ba78..d8671e1a3 100644 --- a/src/__tests__/fire-event.test.tsx +++ b/src/__tests__/fire-event.test.tsx @@ -9,7 +9,6 @@ import { View, } from 'react-native'; import { fireEvent, render, screen } from '..'; -import '../matchers/extend-expect'; type OnPressComponentProps = { onPress: () => void; diff --git a/src/__tests__/react-native-animated.tsx b/src/__tests__/react-native-animated.tsx index c39b87daa..7c33ed5e6 100644 --- a/src/__tests__/react-native-animated.tsx +++ b/src/__tests__/react-native-animated.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { Animated, ViewStyle } from 'react-native'; import { act, render, screen } from '..'; -import '../matchers/extend-expect'; type AnimatedViewProps = { fadeInDuration?: number; diff --git a/src/matchers/__tests__/extend-expect.test.tsx b/src/matchers/__tests__/extend-expect.test.tsx deleted file mode 100644 index 1889926aa..000000000 --- a/src/matchers/__tests__/extend-expect.test.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import * as React from 'react'; -import { View } from 'react-native'; - -// Note: that must point to root of the /src to reliably replicate default import. -import { render } from '../..'; - -// This is check that RNTL does not extend "expect" by default, until we actually want to expose Jest matchers publically. -test('does not extend "expect" by default', () => { - render(); - - // @ts-expect-error - expect(expect.toBeOnTheScreen).toBeUndefined(); -}); diff --git a/src/matchers/__tests__/to-be-busy.test.tsx b/src/matchers/__tests__/to-be-busy.test.tsx index 8de385f42..db189fabd 100644 --- a/src/matchers/__tests__/to-be-busy.test.tsx +++ b/src/matchers/__tests__/to-be-busy.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toBeBusy() basic case', () => { render( diff --git a/src/matchers/__tests__/to-be-checked.test.tsx b/src/matchers/__tests__/to-be-checked.test.tsx index 85dc39aa7..6cf432b85 100644 --- a/src/matchers/__tests__/to-be-checked.test.tsx +++ b/src/matchers/__tests__/to-be-checked.test.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { type AccessibilityRole, Switch, View } from 'react-native'; import render from '../../render'; import { screen } from '../../screen'; -import '../extend-expect'; function renderViewsWithRole(role: AccessibilityRole) { render( diff --git a/src/matchers/__tests__/to-be-disabled.test.tsx b/src/matchers/__tests__/to-be-disabled.test.tsx index f43757cb4..cceb24037 100644 --- a/src/matchers/__tests__/to-be-disabled.test.tsx +++ b/src/matchers/__tests__/to-be-disabled.test.tsx @@ -11,7 +11,6 @@ import { View, } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toBeDisabled()/toBeEnabled() supports basic case', () => { render( diff --git a/src/matchers/__tests__/to-be-empty-element.test.tsx b/src/matchers/__tests__/to-be-empty-element.test.tsx index a63256012..bb90012d0 100644 --- a/src/matchers/__tests__/to-be-empty-element.test.tsx +++ b/src/matchers/__tests__/to-be-empty-element.test.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { View } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; // eslint-disable-next-line @typescript-eslint/no-unused-vars function DoNotRenderChildren({ children }: { children: React.ReactNode }) { diff --git a/src/matchers/__tests__/to-be-expanded.test.tsx b/src/matchers/__tests__/to-be-expanded.test.tsx index b82dd6ed7..e1e92e806 100644 --- a/src/matchers/__tests__/to-be-expanded.test.tsx +++ b/src/matchers/__tests__/to-be-expanded.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toBeExpanded() basic case', () => { render( diff --git a/src/matchers/__tests__/to-be-on-the-screen.test.tsx b/src/matchers/__tests__/to-be-on-the-screen.test.tsx index 217f06d0b..9b01b7354 100644 --- a/src/matchers/__tests__/to-be-on-the-screen.test.tsx +++ b/src/matchers/__tests__/to-be-on-the-screen.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View, Text } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toBeOnTheScreen() example test', () => { render( diff --git a/src/matchers/__tests__/to-be-partially-checked.test.tsx b/src/matchers/__tests__/to-be-partially-checked.test.tsx index 69df9b76c..03ab58290 100644 --- a/src/matchers/__tests__/to-be-partially-checked.test.tsx +++ b/src/matchers/__tests__/to-be-partially-checked.test.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { type AccessibilityRole, View } from 'react-native'; import render from '../../render'; import { screen } from '../../screen'; -import '../extend-expect'; function renderViewsWithRole(role: AccessibilityRole) { return render( diff --git a/src/matchers/__tests__/to-be-selected.test.tsx b/src/matchers/__tests__/to-be-selected.test.tsx index aedbacf08..7787cb34e 100644 --- a/src/matchers/__tests__/to-be-selected.test.tsx +++ b/src/matchers/__tests__/to-be-selected.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toBeSelected() basic case', () => { render( diff --git a/src/matchers/__tests__/to-be-visible.test.tsx b/src/matchers/__tests__/to-be-visible.test.tsx index 380bf84dd..df04f5e2f 100644 --- a/src/matchers/__tests__/to-be-visible.test.tsx +++ b/src/matchers/__tests__/to-be-visible.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View, Modal } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toBeVisible() on empty view', () => { render(); diff --git a/src/matchers/__tests__/to-contain-element.test.tsx b/src/matchers/__tests__/to-contain-element.test.tsx index 28071ed7b..dabb95182 100644 --- a/src/matchers/__tests__/to-contain-element.test.tsx +++ b/src/matchers/__tests__/to-contain-element.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toContainElement() supports basic case', () => { render( diff --git a/src/matchers/__tests__/to-have-accessibility-value.test.tsx b/src/matchers/__tests__/to-have-accessibility-value.test.tsx index 57efe8f31..fd2602eaa 100644 --- a/src/matchers/__tests__/to-have-accessibility-value.test.tsx +++ b/src/matchers/__tests__/to-have-accessibility-value.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; describe('toHaveAccessibilityValue', () => { it('supports "accessibilityValue.min"', () => { diff --git a/src/matchers/__tests__/to-have-accessible-name.test.tsx b/src/matchers/__tests__/to-have-accessible-name.test.tsx index 4bb8f92cc..d797bacaf 100644 --- a/src/matchers/__tests__/to-have-accessible-name.test.tsx +++ b/src/matchers/__tests__/to-have-accessible-name.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View, Text, TextInput, Image } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toHaveAccessibleName() handles view with "accessibilityLabel" prop', () => { render(); diff --git a/src/matchers/__tests__/to-have-display-value.test.tsx b/src/matchers/__tests__/to-have-display-value.test.tsx index e5ebd7e47..547d3c1d5 100644 --- a/src/matchers/__tests__/to-have-display-value.test.tsx +++ b/src/matchers/__tests__/to-have-display-value.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { TextInput, View } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toHaveDisplayValue() example test', () => { render(); diff --git a/src/matchers/__tests__/to-have-prop.test.tsx b/src/matchers/__tests__/to-have-prop.test.tsx index 5eb1c214b..42d811a96 100644 --- a/src/matchers/__tests__/to-have-prop.test.tsx +++ b/src/matchers/__tests__/to-have-prop.test.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { View, Text, TextInput } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toHaveProp() basic case', () => { render( diff --git a/src/matchers/__tests__/to-have-style.test.tsx b/src/matchers/__tests__/to-have-style.test.tsx index d102acc8a..a47b712e1 100644 --- a/src/matchers/__tests__/to-have-style.test.tsx +++ b/src/matchers/__tests__/to-have-style.test.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { StyleSheet, View, Pressable } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; const styles = StyleSheet.create({ container: { borderBottomColor: 'white' }, diff --git a/src/matchers/__tests__/to-have-text-content.test.tsx b/src/matchers/__tests__/to-have-text-content.test.tsx index 082555a96..54801b088 100644 --- a/src/matchers/__tests__/to-have-text-content.test.tsx +++ b/src/matchers/__tests__/to-have-text-content.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { View, Text } from 'react-native'; import { render, screen } from '../..'; -import '../extend-expect'; test('toHaveTextContent() example test', () => { render( diff --git a/src/user-event/__tests__/clear.test.tsx b/src/user-event/__tests__/clear.test.tsx index c7f4b1d95..cb4c715a7 100644 --- a/src/user-event/__tests__/clear.test.tsx +++ b/src/user-event/__tests__/clear.test.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { TextInput, TextInputProps, View } from 'react-native'; import { createEventLogger, getEventsNames } from '../../test-utils'; import { render, userEvent, screen } from '../..'; -import '../../matchers/extend-expect'; beforeEach(() => { jest.useRealTimers(); diff --git a/src/user-event/__tests__/paste.test.tsx b/src/user-event/__tests__/paste.test.tsx index 9226a6595..cbfb6c323 100644 --- a/src/user-event/__tests__/paste.test.tsx +++ b/src/user-event/__tests__/paste.test.tsx @@ -2,7 +2,6 @@ import * as React from 'react'; import { TextInput, TextInputProps, View } from 'react-native'; import { createEventLogger, getEventsNames } from '../../test-utils'; import { render, userEvent, screen } from '../..'; -import '../../matchers/extend-expect'; beforeEach(() => { jest.useRealTimers(); diff --git a/src/user-event/scroll/__tests__/scroll-to-flat-list.test.tsx b/src/user-event/scroll/__tests__/scroll-to-flat-list.test.tsx index 84be91eda..61e843a5a 100644 --- a/src/user-event/scroll/__tests__/scroll-to-flat-list.test.tsx +++ b/src/user-event/scroll/__tests__/scroll-to-flat-list.test.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { FlatList, ScrollViewProps, Text, View } from 'react-native'; import { render, screen } from '../../..'; -import '../../../matchers/extend-expect'; import { EventEntry, createEventLogger } from '../../../test-utils'; import { userEvent } from '../..'; diff --git a/src/user-event/type/__tests__/type.test.tsx b/src/user-event/type/__tests__/type.test.tsx index 8e55c7744..5753f4168 100644 --- a/src/user-event/type/__tests__/type.test.tsx +++ b/src/user-event/type/__tests__/type.test.tsx @@ -3,7 +3,6 @@ import { TextInput, TextInputProps, View } from 'react-native'; import { createEventLogger, getEventsNames, lastEventPayload } from '../../../test-utils'; import { render, screen } from '../../..'; import { userEvent } from '../..'; -import '../../../matchers/extend-expect'; beforeEach(() => { jest.useRealTimers(); From 837895796d93bee0be52415352f8e674f8121530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Thu, 24 Oct 2024 09:31:36 +0200 Subject: [PATCH 4/4] chore: tweaks --- .../__tests__/{AnimatedView.tsx => AnimatedView.test.tsx} | 2 ++ 1 file changed, 2 insertions(+) rename examples/basic/components/__tests__/{AnimatedView.tsx => AnimatedView.test.tsx} (99%) diff --git a/examples/basic/components/__tests__/AnimatedView.tsx b/examples/basic/components/__tests__/AnimatedView.test.tsx similarity index 99% rename from examples/basic/components/__tests__/AnimatedView.tsx rename to examples/basic/components/__tests__/AnimatedView.test.tsx index 8a3309aee..ceea50575 100644 --- a/examples/basic/components/__tests__/AnimatedView.tsx +++ b/examples/basic/components/__tests__/AnimatedView.test.tsx @@ -17,6 +17,7 @@ describe('AnimatedView', () => { , ); expect(screen.root).toHaveStyle({ opacity: 0 }); + await act(() => jest.advanceTimersByTime(250)); expect(screen.root).toHaveStyle({ opacity: 1 }); }); @@ -28,6 +29,7 @@ describe('AnimatedView', () => { , ); expect(screen.root).toHaveStyle({ opacity: 0 }); + await act(() => jest.advanceTimersByTime(250)); expect(screen.root).toHaveStyle({ opacity: 1 }); });