-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for useProfile and usePublication
- Loading branch information
Showing
10 changed files
with
148 additions
and
59 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
2 changes: 1 addition & 1 deletion
2
...src/apollo/cache/createFeedFieldPolicy.ts → ...e/field-policies/createFeedFieldPolicy.ts
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { mockProfileFragment, mockProfileResponse } from '@lens-protocol/api-bindings/mocks'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
import { NotFoundError } from '../../NotFoundError'; | ||
import { setupHookTestScenario } from '../../__helpers__/setupHookTestScenario'; | ||
import { useProfile } from '../useProfile'; | ||
|
||
describe(`Given the ${useProfile.name} hook`, () => { | ||
const profile = mockProfileFragment(); | ||
const expectations = { __typename: 'Profile', id: profile.id }; | ||
|
||
describe.each([ | ||
{ | ||
description: 'when invoked with a profile id', | ||
args: { forProfileId: profile.id }, | ||
}, | ||
{ | ||
description: 'when invoked with a profile handle', | ||
args: { forHandle: profile.handle }, | ||
}, | ||
])('$description', ({ args }) => { | ||
it('should settle with the profile data', async () => { | ||
const { renderHook } = setupHookTestScenario([ | ||
mockProfileResponse({ | ||
variables: { | ||
request: args, | ||
}, | ||
result: profile, | ||
}), | ||
]); | ||
|
||
const { result } = renderHook(() => useProfile(args)); | ||
|
||
await waitFor(() => expect(result.current.loading).toBeFalsy()); | ||
expect(result.current.data).toMatchObject(expectations); | ||
}); | ||
|
||
it(`should settle with a ${NotFoundError.name} if not found`, async () => { | ||
const { renderHook } = setupHookTestScenario([ | ||
mockProfileResponse({ | ||
variables: { | ||
request: args, | ||
}, | ||
result: null, | ||
}), | ||
]); | ||
|
||
const { result } = renderHook(() => useProfile(args)); | ||
|
||
await waitFor(() => expect(result.current.loading).toBeFalsy()); | ||
expect(result.current.error).toBeInstanceOf(NotFoundError); | ||
}); | ||
}); | ||
}); |
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
54 changes: 54 additions & 0 deletions
54
packages/react/src/publication/__tests__/usePublication.spec.ts
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { mockPostFragment, mockPublicationResponse } from '@lens-protocol/api-bindings/mocks'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
import { NotFoundError } from '../../NotFoundError'; | ||
import { setupHookTestScenario } from '../../__helpers__/setupHookTestScenario'; | ||
import { usePublication } from '../usePublication'; | ||
|
||
describe(`Given the ${usePublication.name} hook`, () => { | ||
const publication = mockPostFragment(); | ||
const expectations = { __typename: 'Post', id: publication.id }; | ||
|
||
describe.each([ | ||
{ | ||
description: 'when invoked with a publication id', | ||
args: { forId: publication.id }, | ||
}, | ||
{ | ||
description: 'when invoked with a txHash', | ||
args: { forTxHash: publication.txHash }, | ||
}, | ||
])('$description', ({ args }) => { | ||
it('should settle with the publication data', async () => { | ||
const { renderHook } = setupHookTestScenario([ | ||
mockPublicationResponse({ | ||
variables: { | ||
request: args, | ||
}, | ||
result: publication, | ||
}), | ||
]); | ||
|
||
const { result } = renderHook(() => usePublication(args)); | ||
|
||
await waitFor(() => expect(result.current.loading).toBeFalsy()); | ||
expect(result.current.data).toMatchObject(expectations); | ||
}); | ||
|
||
it(`should settle with a ${NotFoundError.name} if not found`, async () => { | ||
const { renderHook } = setupHookTestScenario([ | ||
mockPublicationResponse({ | ||
variables: { | ||
request: args, | ||
}, | ||
result: null, | ||
}), | ||
]); | ||
|
||
const { result } = renderHook(() => usePublication(args)); | ||
|
||
await waitFor(() => expect(result.current.loading).toBeFalsy()); | ||
expect(result.current.error).toBeInstanceOf(NotFoundError); | ||
}); | ||
}); | ||
}); |
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