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

A react native testing library test for the UI #5

Merged
merged 54 commits into from
Feb 27, 2025
Merged

A react native testing library test for the UI #5

merged 54 commits into from
Feb 27, 2025

Conversation

jg210
Copy link
Owner

@jg210 jg210 commented Feb 21, 2025

Copy link

Lines Statements Branches Functions
Coverage: 89%
88.09% (37/42) 100% (6/6) 87.5% (14/16)

… I don't want to stop running tests on merging back to master. Would also need to tune what it reports, since it doesn't give much info in the comment.
@jg210 jg210 self-assigned this Feb 23, 2025
src/__tests__/nodeVersion.tsx:5:33 - error TS2339: Property 'version' does not exist on type 'typeof process'.

Didn't get this error on CI, it's not clear why not.
@jg210
Copy link
Owner Author

jg210 commented Feb 26, 2025

jest test passes locally, but not on CI:

● Authorities › renders

    Unable to find an element with testID: fingerprint

    <Text>
      loading...
    </Text>

      75 |     localAuthorities: LocalAuthority[]
      76 | ) {
    > 77 |     await waitFor(() => {
         |                  ^
      78 |         expect(screen.getByTestId("fingerprint")).toHaveTextContent(fingerprint.slice(0, 8));
      79 |     });
      80 |     const authoritiesList = screen.getByTestId("authoritiesList");

      at src/__tests__/Authorities.test.tsx:77:18
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12
      at apply (src/__tests__/Authorities.test.tsx:88:2)
      at apply (src/__tests__/Authorities.test.tsx:73:31)
      at Object.assertUICorrect (src/__tests__/Authorities.test.tsx:110:39)
      at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:17)
      at _next (node_modules/@babel/runtime/helpers/asyncToGenerator.js:17:9)
      at node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:7
      at Object.<anonymous> (node_modules/@babel/runtime/helpers/asyncToGenerator.js:14:12)

@jg210
Copy link
Owner Author

jg210 commented Feb 26, 2025

Now, jest times out instead:

 FAIL src/__tests__/Authorities.test.tsx (7.107 s)
  ● Authorities › renders

    thrown: "Exceeded timeout of 5000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      94 |     afterAll(() => server.close());
      95 |
    > 96 |     it("renders", async () => {
         |     ^
      97 |
      98 |         // To test drag to refresh works, return different data for first and second requests.
      99 |         const localAuthorities1 = localAuthorities.slice(0, 1);

      at it (src/__tests__/Authorities.test.tsx:96:5)
      at Object.describe (src/__tests__/Authorities.test.tsx:90:1)

@jg210
Copy link
Owner Author

jg210 commented Feb 27, 2025

 FAIL src/__tests__/Authorities.test.tsx (17.056 s)
  ● Authorities › renders

    thrown: "Exceeded timeout of 15000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      94 |     afterAll(() => server.close());
      95 |
    > 96 |     it("renders", async () => {
         |     ^
      97 |
      98 |         // To test drag to refresh works, return different data for first and second requests.
      99 |         const localAuthorities1 = localAuthorities.slice(0, 1);

      at it (src/__tests__/Authorities.test.tsx:96:5)
      at Object.describe (src/__tests__/Authorities.test.tsx:90:1)

@jg210
Copy link
Owner Author

jg210 commented Feb 27, 2025

Tests were failing since mock didn't allow for variation in the number of renders before changing from old to new data. Now it only changes the data after the assertions for the first data have passed.

…t to allow empty set of components. Don't need waitFor in last test. Last test is still giving an act() warning...
…se act(). Fix by moving fingerprint Promise before render(). Same error comes back if add any trivial await after the render() and don't use act(). E.g. a promise that resolves after a 1s setTimeout.
@jg210 jg210 marked this pull request as ready for review February 27, 2025 13:21
@jg210 jg210 merged commit 939a012 into master Feb 27, 2025
1 check passed
@jg210 jg210 deleted the dev/test branch February 27, 2025 13:25
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.

1 participant