-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests for expo-52 issues with jest
- Loading branch information
Showing
2 changed files
with
93 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,93 @@ | ||
import React from 'react'; | ||
import React from "react"; | ||
|
||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { render, waitFor } from '@testing-library/react-native'; | ||
import { Provider } from 'react-redux'; | ||
import { configureStore } from "@reduxjs/toolkit"; | ||
import { render, waitFor } from "@testing-library/react-native"; | ||
import { Provider } from "react-redux"; | ||
|
||
import gamesReducer, { gameDefaults } from '../redux/GamesSlice'; | ||
import settingsReducer, { initialState as settingsState } from '../redux/SettingsSlice'; | ||
import { useNavigationMock } from '../test/test-helpers'; | ||
import gamesReducer, { gameDefaults } from "../redux/GamesSlice"; | ||
import settingsReducer, { | ||
initialState as settingsState, | ||
} from "../redux/SettingsSlice"; | ||
import { useNavigationMock } from "../test/test-helpers"; | ||
|
||
import ListScreen from './screens/ListScreen'; | ||
import ListScreen from "./screens/ListScreen"; | ||
|
||
jest.mock('Analytics'); | ||
jest.mock("Analytics"); | ||
jest.mock("expo-font"); // https://github.com/callstack/react-native-paper/issues/4561 | ||
|
||
const mockStore = () => { | ||
return configureStore({ | ||
reducer: { | ||
settings: settingsReducer, | ||
games: gamesReducer, | ||
return configureStore({ | ||
reducer: { | ||
settings: settingsReducer, | ||
games: gamesReducer, | ||
}, | ||
preloadedState: { | ||
settings: { | ||
...settingsState, | ||
currentGameId: "123", | ||
}, | ||
games: { | ||
entities: { | ||
"123": { | ||
...gameDefaults, | ||
id: "123", | ||
title: "Game", | ||
dateCreated: 1, | ||
playerIds: [], | ||
}, | ||
}, | ||
preloadedState: { | ||
settings: { | ||
...settingsState, | ||
currentGameId: '123' | ||
}, | ||
games: { | ||
entities: { | ||
'123': { | ||
...gameDefaults, | ||
id: '123', | ||
title: 'Game', | ||
dateCreated: 1, | ||
playerIds: [], | ||
} | ||
}, | ||
ids: ['123'] | ||
} | ||
} | ||
}); | ||
ids: ["123"], | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
describe('Navigation', () => { | ||
it('show the onboarding screen when onboardedSemVer 1.0.0', async () => { | ||
const navigation = useNavigationMock(); | ||
const { Application } = require('expo-application'); | ||
expect(Application.nativeApplicationVersion).toBe('1.0.0'); | ||
describe("Navigation", () => { | ||
it("show the onboarding screen when onboardedSemVer 1.0.0", async () => { | ||
const navigation = useNavigationMock(); | ||
const { Application } = require("expo-application"); | ||
expect(Application.nativeApplicationVersion).toBe("1.0.0"); | ||
|
||
const store = mockStore(); | ||
const store = mockStore(); | ||
|
||
render( | ||
<Provider store={store}> | ||
<ListScreen navigation={navigation} /> | ||
</Provider> | ||
); | ||
render( | ||
<Provider store={store}> | ||
<ListScreen navigation={navigation} /> | ||
</Provider> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(navigation.navigate).toHaveBeenCalledWith('Onboarding', expect.objectContaining({ | ||
onboarding: true, | ||
})); | ||
}); | ||
await waitFor(() => { | ||
expect(navigation.navigate).toHaveBeenCalledWith( | ||
"Onboarding", | ||
expect.objectContaining({ | ||
onboarding: true, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('does not show the onboarding screen when onboardedSemVer is equal or greater than 2.5.7', async () => { | ||
const navigation = useNavigationMock(); | ||
it("does not show the onboarding screen when onboardedSemVer is equal or greater than 2.5.7", async () => { | ||
const navigation = useNavigationMock(); | ||
|
||
jest.doMock('expo-application', () => ({ | ||
Application: { | ||
nativeApplicationVersion: '2.5.7', | ||
}, | ||
})); | ||
jest.doMock("expo-application", () => ({ | ||
Application: { | ||
nativeApplicationVersion: "2.5.7", | ||
}, | ||
})); | ||
|
||
const { Application } = require('expo-application'); | ||
expect(Application.nativeApplicationVersion).toBe('2.5.7'); | ||
const { Application } = require("expo-application"); | ||
expect(Application.nativeApplicationVersion).toBe("2.5.7"); | ||
|
||
const store = mockStore(); | ||
const store = mockStore(); | ||
|
||
render( | ||
<Provider store={store}> | ||
<ListScreen navigation={navigation} /> | ||
</Provider> | ||
); | ||
render( | ||
<Provider store={store}> | ||
<ListScreen navigation={navigation} /> | ||
</Provider> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(navigation.navigate).not.toHaveBeenCalledWith('Onboarding'); | ||
}); | ||
await waitFor(() => { | ||
expect(navigation.navigate).not.toHaveBeenCalledWith("Onboarding"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
import { fireEvent, render, waitFor } from '@testing-library/react-native'; | ||
import { fireEvent, render, waitFor } from "@testing-library/react-native"; | ||
|
||
import { useNavigationMock } from '../../../test/test-helpers'; | ||
import { logEvent } from '../../Analytics'; | ||
import { useNavigationMock } from "../../../test/test-helpers"; | ||
import { logEvent } from "../../Analytics"; | ||
|
||
import AppInfoButton from './AppInfoButton'; | ||
import AppInfoButton from "./AppInfoButton"; | ||
|
||
jest.mock('../../Analytics'); | ||
jest.mock("../../Analytics"); | ||
jest.mock("expo-font"); // https://github.com/callstack/react-native-paper/issues/4561 | ||
|
||
describe('AppInfoButton', () => { | ||
const navigation = useNavigationMock(); | ||
describe("AppInfoButton", () => { | ||
const navigation = useNavigationMock(); | ||
|
||
it('should navigate to AppInfo screen when pressed', () => { | ||
const { getByRole } = render(<AppInfoButton navigation={navigation} />); | ||
const button = getByRole('button'); | ||
fireEvent.press(button); | ||
expect(navigation.navigate).toHaveBeenCalledWith('AppInfo'); | ||
}); | ||
it("should navigate to AppInfo screen when pressed", () => { | ||
const { getByRole } = render(<AppInfoButton navigation={navigation} />); | ||
const button = getByRole("button"); | ||
fireEvent.press(button); | ||
expect(navigation.navigate).toHaveBeenCalledWith("AppInfo"); | ||
}); | ||
|
||
it('should log an analytics event when pressed', async () => { | ||
const { getByRole } = render(<AppInfoButton navigation={navigation} />); | ||
const button = getByRole('button'); | ||
it("should log an analytics event when pressed", async () => { | ||
const { getByRole } = render(<AppInfoButton navigation={navigation} />); | ||
const button = getByRole("button"); | ||
|
||
fireEvent.press(button); | ||
fireEvent.press(button); | ||
|
||
await waitFor(() => { | ||
expect(logEvent).toHaveBeenCalledWith('app_info'); | ||
}); | ||
await waitFor(() => { | ||
expect(logEvent).toHaveBeenCalledWith("app_info"); | ||
}); | ||
}); | ||
}); |