This repository was archived by the owner on Jul 30, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 44
"getByText" doesn't work #63
Comments
Hi San, please follow all of the steps provided here to setup the provided jest preset: https://www.native-testing-library.com/docs/install#jest-preset This will fix your issue. Good luck! |
Thanks, I will try it tomorrow. |
Yes, it helped me. Thanks! |
this is my configuration to use the testing library with expo, but I have this error, not sure if it is related with the testing library node_modules/expo/build/Expo.fx.js:1
|
Relevant code or config:// tests/__tests__/setup.spec.tsx
import React from 'react'
import gql from 'graphql-tag'
import { useQuery } from '@apollo/react-hooks'
import { MockedProvider } from '@apollo/react-testing'
import wait from 'waait'
import { render } from '@testing-library/react-native'
// Make sure the query is also exported -- not just the component
const GET_DOG_QUERY = gql`
query getDog($name: String) {
dog(name: $name) {
id
name
breed
}
}
`
const Dog: React.SFC<{ name: string }> = ({ name }) => {
const {
loading, error, data,
} = useQuery(GET_DOG_QUERY, { variables: { name } })
if (loading) return <p>Loading...</p>
if (error) return <p>Error!</p>
return <p>{`${data.dog.name} is a ${data.dog.breed}`}</p>
}
describe('verify apollo', () => {
it('render', async () => {
const mocks = [
{
request: {
query: GET_DOG_QUERY,
variables: {
name: 'Buck',
},
},
result: {
data: {
dog: {
id: '1',
name: 'Buck',
breed: 'bulldog',
},
},
},
},
]
const {
queryByText, debug,
} = render(
<MockedProvider
mocks={mocks}
addTypename={false}
>
<Dog name='Buck' />
</MockedProvider>,
)
debug()
const loading = queryByText(/Loading/i)
expect(loading).not.toBeNull()
await wait(0) // wait for response
debug()
expect(queryByText('Buck is a bulldog')).toBeTruthy()
})
})
What you did:setup a test to verify demo from https://www.apollographql.com/docs/react/development-testing/testing/ What happened:failed to query text Problem description:
from debug output. we could see |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
react-native
orexpo
:react-native
native-testing-library
version: 4.0.12jest-preset
: 'react-native'react-native
version: 0.60.5node
version: 8.15.1Relevant code or config:
What you did:
I just use example from docs
What happened:
Reproduction:
Just use example from docs
Problem description:
When I tried use example from docs I had got this error.
The text was updated successfully, but these errors were encountered: