Conversation
|
|
||
| it('should display a label and input elements with empty userName value', () => { | ||
| // Arrange | ||
| it('Set the email and name and trigger handleAdd "', () => { |
There was a problem hiding this comment.
handleAdd triggering is not being tested with the current test.
| ) as HTMLButtonElement; | ||
| buttonElement.click(); | ||
| const spy = spyOn(myApi, 'getContactList'); | ||
| expect(spy).toBeCalled(); |
|
|
||
| const labelElement = getByTestId('userName-label'); | ||
| const inputElement = getByTestId('userName-input') as HTMLInputElement; | ||
| it('Change the email state and trigger handle Change "', async () => { |
There was a problem hiding this comment.
handleChange triggering is not being tested here with the current test.
| return <h1>Something went wrong...</h1>; | ||
| } | ||
|
|
||
| const handleChange = (contact: ContactType) => { |
There was a problem hiding this comment.
When modifiying contacts (add, updated or delete), we are not asking for the updated contacts list in the current code, we are modifying the store directly by the action with the data of the component instead. Could it cause any issue with our data?
There was a problem hiding this comment.
Hello could you specify your question??
Do you mean i should set first data in the state and after that call api and dispatch?
There was a problem hiding this comment.
I'll put an example. Let's say that you are adding a new user, and the backend fails in storing it. With the current code you would have the new user in the local store, but not in backend.
The data that you are passing to the store is the data from the input and not the one from backend. This specific situation will cause to have different users in local and in the server.
This is only an example and could be more situations where we would end with incoherent data. The backend does not have to fail to be in this situation.
Could you change it and avoid this problem?
There was a problem hiding this comment.
In my current code when api fails i catch the error and i dont save anything in the store.
I think is imossible that i have inconsistent data because i dispach after getting good response.
There was a problem hiding this comment.
No, you should concatenate actions and request the contact list after any change (update, delete or add). I am not saying that you should update the store with the response, you should request the full list.
There was a problem hiding this comment.
So you want me to do double request like for multi users??
If yes no problem i can do it but this is not gonna work in this api (the fake api which you suggest in the issue) because the get request returns always the same static list of users, so you are not gonna see any changes in the app.
There was a problem hiding this comment.
I know, but we would like to see how you implement the solution.
There was a problem hiding this comment.
Of course! give a while!
There was a problem hiding this comment.
hello already done!
…om/dailymp/samples-for-react-testing-library-training into feature/redux-architecture-example

No description provided.