-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add @testing-library/react-native (#5197)
* deps: add rn-testing-library dependencies * chore: setup rn-testing-library * feat: add renderWithWrappersTL * fix: changed rntl version * chore: removed test that doesn't add value * fix: removed unused import * chore: testing out stuff * chore: remove unused import * fix: fixed timer problems * spec: moved relay createEnv mock to setupJest * chore: cleanup * fix: refactor fetchmock and added helper Co-authored-by: Pavlos Vinieratos <[email protected]> * chore: fix url * fix: attempt to fix ci failing test * fix: fetch await problem ci fix * chore: use jest-fetch-mock for mocking fetch Co-authored-by: Pavlos Vinieratos <[email protected]>
- Loading branch information
1 parent
c0c8e18
commit 93784b8
Showing
21 changed files
with
221 additions
and
183 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
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
4 changes: 0 additions & 4 deletions
4
src/lib/Components/Bidding/Screens/__tests__/ConfirmBid-tests.tsx
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
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
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
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
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
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
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,4 +1,5 @@ | ||
import { Checkbox } from "lib/Components/Bidding/Components/Checkbox" | ||
import { fetchMockResponseOnce } from "lib/tests/fetchMockHelpers" | ||
import { renderWithWrappers } from "lib/tests/renderWithWrappers" | ||
import React from "react" | ||
import { __globalStoreTestUtils__ } from "../../../../store/GlobalStore" | ||
|
@@ -13,25 +14,7 @@ const navigationMock = { | |
replace: replaceMock, | ||
} | ||
|
||
const mockFetch = jest.fn() | ||
|
||
;(global as any).fetch = mockFetch | ||
|
||
function mockFetchResponseOnce(response: Partial<Response>) { | ||
mockFetch.mockResolvedValueOnce(response) | ||
} | ||
function mockFetchJsonOnce(json: object, status: number = 200) { | ||
mockFetch.mockResolvedValueOnce({ | ||
status, | ||
json: () => Promise.resolve(json), | ||
}) | ||
} | ||
|
||
describe("OnboardingCreateAccount", () => { | ||
beforeEach(() => { | ||
mockFetch.mockClear() | ||
}) | ||
|
||
it("form validation works properly", async () => { | ||
const tree = renderWithWrappers(<OnboardingCreateAccount navigation={navigationMock as any} route={null as any} />) | ||
|
||
|
@@ -56,12 +39,17 @@ describe("OnboardingCreateAccount", () => { | |
expect(signUpButton.props.disabled).toEqual(false) | ||
expect(signUpButton.props.error).toEqual(undefined) | ||
|
||
mockFetchJsonOnce({ | ||
xapp_token: "my-special-token", | ||
expires_in: "never", | ||
fetchMockResponseOnce( | ||
JSON.stringify({ | ||
xapp_token: "my-special-token", | ||
expires_in: "never", | ||
}) | ||
) | ||
|
||
fetchMockResponseOnce({ | ||
status: 404, | ||
}) | ||
|
||
mockFetchResponseOnce({ status: 404 }) | ||
signUpButton.props.onPress() | ||
|
||
await flushPromiseQueue() | ||
|
@@ -92,21 +80,25 @@ describe("OnboardingCreateAccount", () => { | |
|
||
expect(signUpButton.props.disabled).toEqual(false) | ||
|
||
mockFetchResponseOnce({ status: 201 }) | ||
mockFetchJsonOnce({ | ||
xapp_token: "my-special-token", | ||
expires_in: "never", | ||
}) | ||
mockFetchJsonOnce( | ||
{ | ||
fetchMockResponseOnce({ status: 201 }) | ||
fetchMockResponseOnce( | ||
JSON.stringify({ | ||
xapp_token: "my-special-token", | ||
expires_in: "never", | ||
}) | ||
) | ||
fetchMockResponseOnce( | ||
JSON.stringify({ | ||
access_token: "my-access-token", | ||
expires_in: "a billion years", | ||
}, | ||
201 | ||
status: 201, | ||
}) | ||
) | ||
fetchMockResponseOnce( | ||
JSON.stringify({ | ||
id: "my-user-id", | ||
}) | ||
) | ||
mockFetchJsonOnce({ | ||
id: "my-user-id", | ||
}) | ||
const isLoggedIn = !!__globalStoreTestUtils__?.getCurrentState().auth.userAccessToken | ||
expect(isLoggedIn).toEqual(false) | ||
|
||
|
@@ -126,12 +118,14 @@ describe("OnboardingCreateAccount", () => { | |
|
||
emailInput.props.onChangeText("[email protected]") | ||
|
||
mockFetchJsonOnce({ | ||
xapp_token: "my-special-token", | ||
expires_in: "never", | ||
}) | ||
fetchMockResponseOnce( | ||
JSON.stringify({ | ||
xapp_token: "my-special-token", | ||
expires_in: "never", | ||
}) | ||
) | ||
|
||
mockFetchResponseOnce({ status: 200 }) | ||
fetchMockResponseOnce({ status: 200 }) | ||
signUpButton.props.onPress() | ||
|
||
setTimeout(() => { | ||
|
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
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
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
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
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
Oops, something went wrong.