Skip to content

Commit b252550

Browse files
authored
Merge pull request #811 from Lemoncode/xvii/testing
Xvii/testing
2 parents b7ed76d + 99017c7 commit b252550

File tree

121 files changed

+7678
-5827
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+7678
-5827
lines changed

05-testing/01-react/01-base/05-async/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,38 @@ import { getMembers } from './api';
200200

201201
```
202202

203+
Alternatively, you can use `expect().rejects`:
204+
205+
_./src/api.spec.ts_
206+
207+
```diff
208+
...
209+
it('should throw an error with "Unavailable service" when it rejects the request with 503 status code', async () => {
210+
// Arrange
211+
vi.spyOn(Axios, 'get').mockRejectedValue({
212+
response: {
213+
status: 403,
214+
},
215+
} as AxiosError);
216+
217+
// Act
218+
- try {
219+
- const result = await getMembers();
220+
+ const result = () => getMembers();
221+
- } catch (error) {
222+
// Assert
223+
expect(Axios.get).toHaveBeenCalledWith(
224+
'https://api.github.com/orgs/lemoncode/members'
225+
);
226+
- expect(error).toEqual('Too much Github API calls!');
227+
+ expect(result).rejects.toEqual('Too much Github API calls!');
228+
}
229+
});
230+
231+
```
232+
233+
> Or like `expect(getMembers).rejects.toEqual('Too much Github API calls!');`
234+
203235
Should throw an error with "Unavailable service" when it rejects the request with 503 status code:
204236

205237
_./src/api.spec.ts_

05-testing/01-react/05-real-project/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ import { SelectComponent } from './select.component';
244244

245245
+ const selectElement = screen.getByRole('combobox', { name: "Test label" });
246246

247-
+ expect(selectElement.textContent).toEqual('Item 1');
247+
+ expect(selectElement).toHaveTextContent('Item 1');
248248

249249
+ await userEvent.click(selectElement);
250250
+ const itemElementList = screen.getAllByRole('option');

0 commit comments

Comments
 (0)