Query context provider - #2
Conversation
| describe('pending', () => { | ||
| beforeEach(() => { | ||
| getTodoById.mockImplementationOnce(() => new Promise(() => {})) | ||
| //getTodoById.mockImplementationOnce(() => new Promise(() => {})) |
There was a problem hiding this comment.
Do you think we should uncomment that? This is to simulate what we are loading. If not I would delete it
There was a problem hiding this comment.
I had a bit of a problem here. I think there should be a fail-safe simulation here (like it was). But enabling this line makes all subsequent tests fail. Right now, the state happens to be "loading" when this test runs, so it passes. But this test is most likely not fail-safe this way.
I don't know enough about the mocking to make a fail-safe fix for this.
| if (result?.isPending) { | ||
| return html`<div>Loading...</div>` | ||
| } | ||
|
|
||
| if (result.isError) { | ||
| if (result?.isError) { | ||
| return html`<div>Error</div>` | ||
| } | ||
|
|
||
| const { userId, id, title, completed } = result.data | ||
| const { userId, id, title, completed } = result?.data ?? {} |
There was a problem hiding this comment.
It's not the best but I don't have any better idea on how to make it better because of the asynchronous nature of the lit-context. Maybe https://github.com/justinfagnani could help us with that.
There was a problem hiding this comment.
Yep, there are a number of ways to go here. Right now the result is initially undefined which is reasonable, but it makes it harder to use destructuring. Therefore the defaulting {}. Another way would be to return an empty result object initially.
There was a problem hiding this comment.
Let's start with that and we can always come back to it.
Gabswim
left a comment
There was a problem hiding this comment.
I will approve right after you address the comments. Thank you for your time! Great job!
Remove unused line Co-authored-by: Gabriel Legault <gablegault1@hotmail.com>
Added a proper query context provider. To get it to work, some things in QueryController had to be changed to allow an asynchronous flow.
Changes: