Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]feat: add react native testing library #5132

Closed
wants to merge 15 commits into from

Conversation

gkartalis
Copy link
Member

@gkartalis gkartalis commented Jul 15, 2021

The type of this PR is: Enhancement

This PR resolves []

@pvinis

Description

  • Added @testing-library/react-native
  • Fixed problems with timers
  • Fixed relay mockenvironment problems that were surfaced

Another thing that is worth mentioning here is that the version is one minor release behind the latest cause of this issue fixed in this PR but not yet released.

Problems

The problem at the moment is that 4 tests are failing more specifically:

  1. OrderDetails-tests.tsx
  2. RegistrationFlow-tests.tsx
  3. MyBids-tests.tsx
  4. Consignments/tests/index-tests.tsx

~~Reason: ~~

Failed: "TypeError: Cannot read property '_responseForQueryIDWithVariables' of undefined"
Failed: "TypeError: Cannot read property '_setResponseForQueryIDWithVariables' of undefined"

These two come from the following:

Artsy/eigen/src/lib/NativeModules/GraphQLQueryCache.ts
Artsy/eigen/emission/Pod/Classes/GraphQL/ARGraphQLQueryCache.m

The above where solved when added these lines to mock createEnvironment to setupJest.ts.

PR Checklist (tick all before merging)

  • I have included screenshots or videos to illustrate my changes, or I have not changed anything that impacts the UI.
  • I have tested my changes on iOS and Android.
  • I have added tests for my changes, or my changes don't require testing, or I have included a link to a separate Jira ticket covering the tests.
  • I have added a feature flag, or my changes don't require a feature flag. (How do I add one?)
  • I have documented any follow-up work that this PR will require, or it does not require any.
  • I have added an app state migration, or my changes do not require one. (What are migrations?)
  • I have added a changelog entry below or my changes do not require one.
Changelog updates

Changelog updates

Cross-platform user-facing changes

iOS user-facing changes

Android user-facing changes

Dev changes

  • introduces @testing-library/react-native - gkartalis

@ArtsyOpenSource
Copy link
Contributor

ArtsyOpenSource commented Jul 15, 2021

This PR contains the following changes:

  • Dev changes (introduces @testing-library/react-native - gkartalis)

Generated by 🚫 dangerJS against 051f130

@@ -40,7 +41,7 @@ describe(ArtsyReactWebViewPage, () => {
it("shares the correct URL", () => {
const tree = render({ showShareButton: true })
tree.root.findByType(FancyModalHeader).props.onRightButtonPress()
setTimeout(() => expect(jest.fn()).toHaveBeenCalledWith())
waitFor(() => expect(jest.fn()).toHaveBeenCalledTimes(1))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here when adding @testing-library/react-native setTimeouts like this were breaking. I am not sure if it is the BEST approach to use waitFor from @testing-library/react-native in tests that are not written with this library.

What do you think?

Comment on lines -167 to -172
beforeAll(() => {
jest.useFakeTimers()
})
afterAll(() => {
jest.useRealTimers()
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the timers since with waitFor we don't actually need them.

import { ReactElement } from "simple-markdown"

export const Wrappers: React.FC = ({ children }) => {
return (
// <RelayEnvironmentProvider environment={defaultEnvironment}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually want this here? 🤔

@gkartalis gkartalis closed this Jul 29, 2021
@gkartalis gkartalis deleted the gkartalis/rn-testing-library branch July 29, 2021 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants