diff --git a/examples/react-native/v12/TestApp/babel.config.cjs b/examples/react-native/v12/TestApp/babel.config.cjs index d7f011f121..1e1584f26e 100644 --- a/examples/react-native/v12/TestApp/babel.config.cjs +++ b/examples/react-native/v12/TestApp/babel.config.cjs @@ -1,7 +1,7 @@ module.exports = { presets: [ ['@babel/preset-env', {targets: {node: 'current'}}], - // 'module:metro-react-native-babel-preset', + 'module:metro-react-native-babel-preset', '@babel/preset-typescript', ], plugins: ['react-native-reanimated/plugin'], diff --git a/examples/react-native/v12/TestApp/jest.config.ts b/examples/react-native/v12/TestApp/jest.config.ts index dd3871dd68..33c36e3364 100644 --- a/examples/react-native/v12/TestApp/jest.config.ts +++ b/examples/react-native/v12/TestApp/jest.config.ts @@ -8,8 +8,10 @@ const config: Config = { preset: 'react-native', testTimeout: 30000, roots: ['/src/'], - setupFiles: ['./testSetup.ts'], - setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'], + setupFilesAfterEnv: [ + '@testing-library/jest-native/extend-expect', + './testSetup.ts', + ], transform: { '^.+\\.(js|jsx|ts|tsx)$': 'babel-jest', }, diff --git a/examples/react-native/v12/TestApp/src/components/authentication/login/Login.test.tsx b/examples/react-native/v12/TestApp/src/components/authentication/login/Login.test.tsx index 0b51a1271c..8577709ce6 100644 --- a/examples/react-native/v12/TestApp/src/components/authentication/login/Login.test.tsx +++ b/examples/react-native/v12/TestApp/src/components/authentication/login/Login.test.tsx @@ -6,7 +6,7 @@ import {render, screen, userEvent, within} from '@testing-library/react-native'; describe('Log in with App Services auth providers', () => { // Make sure the same user isn't persisted across tests. - beforeEach(async () => { + afterEach(async () => { render(); const user = userEvent.setup(); @@ -22,9 +22,8 @@ describe('Log in with App Services auth providers', () => { } // component should render because there's no auth'd user - const newLoginAnonymousButton = await screen.findByTestId( - 'log-in-anonymous', - ); + const newLoginAnonymousButton = + await screen.findByTestId('log-in-anonymous'); expect(newLoginAnonymousButton).toBeInTheDocument; }); @@ -97,9 +96,8 @@ describe('Log in with App Services auth providers', () => { const emailInput = await screen.findByTestId('email-input'); const passwordInput = await screen.findByTestId('password-input'); const registerButton = await screen.findByTestId('register-button'); - const sendResetPasswordEmailButton = await screen.findByTestId( - 'send-reset-email', - ); + const sendResetPasswordEmailButton = + await screen.findByTestId('send-reset-email'); // Register user with email and password await user.type(emailInput, userEmail); diff --git a/examples/react-native/v12/TestApp/src/components/subscribe-api/SubscribeApi.test.tsx b/examples/react-native/v12/TestApp/src/components/subscribe-api/SubscribeApi.test.tsx index 63745325ca..ac629d199b 100644 --- a/examples/react-native/v12/TestApp/src/components/subscribe-api/SubscribeApi.test.tsx +++ b/examples/react-native/v12/TestApp/src/components/subscribe-api/SubscribeApi.test.tsx @@ -8,11 +8,6 @@ import {render, screen, userEvent} from '@testing-library/react-native'; // pass. describe('Subscribe API behavior tests', () => { - beforeEach(async () => { - // Close and remove all realms in the default directory. - Realm.clearTestState(); - }); - test('Basic subscription with a name', async () => { // This test consistently fails in CI. For whatever reason, the // initial sync takes more than 10 seconds, which is the max diff --git a/examples/react-native/v12/TestApp/testSetup.ts b/examples/react-native/v12/TestApp/testSetup.ts index fe5eb54730..35c0a9e085 100644 --- a/examples/react-native/v12/TestApp/testSetup.ts +++ b/examples/react-native/v12/TestApp/testSetup.ts @@ -1,7 +1,7 @@ -import {jest} from '@jest/globals'; +import {jest, beforeEach} from '@jest/globals'; // Needed to clear the test state. -import {flags} from 'realm'; +import Realm, {flags} from 'realm'; flags.ALLOW_CLEAR_TEST_STATE = true; // avoid error: Cannot find module 'NativeAnimatedHelper' @@ -13,3 +13,11 @@ global.console = { error: jest.fn(), warn: jest.fn(), }; + +beforeEach(async () => { + // Close and remove all realms in the default directory. + Realm.clearTestState(); + + // Use promise hack to wait realm to clear + await new Promise(r => setTimeout(r, 100)); +});