Kurs z testowania - etap 8 - Testy promochatora#107
Conversation
| }); | ||
|
|
||
| expect(res.output.recommended_supervisors.length).toBe(0); | ||
| console.log("Response for nonsense input:", res); |
There was a problem hiding this comment.
Remove the console.log used for debugging unless it's intended for persistent logging.
| console.log("Response for nonsense input:", res); |
Rei-x
left a comment
There was a problem hiding this comment.
no muszę Ci powiedzieć, że jestem dumny, bardzo solidne teściki, pokryłeś wszystko to co miałeś zrobić i jestem zadowolony (mam nadzieję, że ty )
tak jak Ci wcześniej mówiłem te testy czy promochator zwraca prawidłowego promotora raczej powinny być w repo backendu promochatora, bo tutaj jedyne co robisz właściwe to wykonujesz zapytanie do API, tam myślę, że byłoby dla nich odpowiedniejsze miejsce
poza tym jest spoczko, dużo dziwnych rzeczy też pozmieniałeś poza samymi testami 😭
| if (process.env.NODE_ENV === "development") { | ||
| return NextResponse.json(null, { status: 201 }); | ||
| } |
| if (process.env.NODE_ENV === "development") { | ||
| const response = await mockFetch("/recommend/invoke"); | ||
| return NextResponse.json(await response.json()); | ||
| } |
| } | ||
|
|
||
| const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
| ({ className, variant, size, asChild = false, ...props }, reference) => { |
|
|
||
| return ( | ||
| <Comp | ||
| ref={reference} |
|
|
||
| import { ClientOnly } from "./client-only"; | ||
| import { PromptForm } from "./prompt-form"; | ||
| import React from "react"; |
There was a problem hiding this comment.
zamiast dodawać importy reacta mogłeś dodać plugin do vite'a z obsługą reacta, nic byś nie musiał zmieniać
|
|
||
| await waitFor(() => { | ||
| expect(mockAddChat).toHaveBeenCalledWith({ | ||
| uuid: "mock-uuid-1234", |
There was a problem hiding this comment.
trochę magic string, fajnie jakbyś wyciągnął to do stałej (albo w ogóle tego nie sprawdzał, przy użyciu expect.objectContaining({ }) - wtedy możesz podać tylko część pól)
|
|
||
| it("should return an error message in case of code 500", async () => { | ||
| const user = userEvent.setup(); | ||
| mockAddChat.mockRejectedValueOnce(new Error("Błąd serwera")); |
There was a problem hiding this comment.
czemu to zrobiłeś mockami a nie msw?
| beforeAll(() => server.listen()); | ||
| afterEach(() => server.resetHandlers()); | ||
| afterAll(() => server.close()); |
There was a problem hiding this comment.
to akurat mogło pójść do pliku z setupem
a jak byś potrzebował, żeby request dochodził do prawdziwego backendu to możesz użyć: https://mswjs.io/docs/api/passthrough
| const nextConfig: NextConfig = { | ||
| /* config options here */ | ||
| eslint: { | ||
| ignoreDuringBuilds: true, |
| "devDependencies": { | ||
| "@next/eslint-plugin-next": "^15.2.3", | ||
| "@solvro/config": "^1.13.1", | ||
| "@solvro/config": "^2.0.1", |
Hej, jak zwykle byłem trochę w deficycie czasu przez Wakacyjne Wyzwanie, ale starałem się jak mogłem, by testy przyniosły wartość biznesową.
Btw wybaczcie autorzy repo za PR'kę :p
Important
This PR adds comprehensive tests for the Promochator chat component and API interactions, updates configurations for testing, and includes minor code adjustments for error handling and consistency.
chat.test.tsxto test chat component interactions, including form submission and error handling.failedData.test.tsto test API error handling for 500 responses.fetchData-recommend.test.tsfor integration tests on/recommend/invokeendpoint.nonsenseSupervisor.test.tsto test handling of nonsense input in recommendations.setup.tsfor test environment setup.vitest.config.tsfor Vitest configuration with JSDOM environment and setup file.next.config.tsto ignore ESLint during builds.package.jsonto adjust scripts and dependencies for testing.feedback/route.tsandrecommend/route.ts.PromptForminprompt-form.tsxfor chat submission errors.chat.tsx,client-only.tsx, andprompt-form.tsxfor consistency.Buttoncomponent inbutton.tsxto userefdirectly.This description was created by
for a24adf5. You can customize this summary. It will automatically update as commits are pushed.