···11-docs/.vitepress/config.ts
22-33-@@ -489,6 +489,10 @@ function guide(): DefaultTheme.SidebarItem[] {
44- text: 'Test Projects',
55- link: '/guide/projects',
66- },
77- {
88-99-Comment :
1010- sheremet-va 1 hour ago
1111-1212-From #8409 (comment)
1313-1414-This should be in the browser guides section (in the same level as "Multiple Setups")
1515-1616---------------
1717-docs/guide/component-testing.md
1818-1919-### Component Testing Hierarchy
2020-2121-```
2222-1. Critical User Paths → Always test these
2323-2424-Comment:
2525- sheremet-va 1 hour ago
2626-2727-should the spaces be aligned? The first 2 arrows are not aligned
2828------------------------
2929-docs/guide/component-testing.md
3030-3131-```tsx
3232-// Mock external services
3333-vi.mock('../api/userService', () => ({
3434-3535-Comment:
3636- sheremet-va 1 hour ago
3737-we recommend vi.mock(import('../api/userService')) syntax (applied to all vi.mock calls here)
3838---------------------------
3939-docs/guide/component-testing.md
4040-4141-expect(getByText('Loading...')).toBeInTheDocument()
4242-4343- // Wait for data to load
4444- await waitFor(() => {
4545-4646-Comment:
4747- sheremet-va 1 hour ago
4848-There is await expect.element(locator).toBeInTheDocument()
4949-5050----------------------
5151-docs/guide/component-testing.md
5252-5353- )
5454-5555- // Initially shows all products
5656- expect(getByText('Laptop')).toBeInTheDocument()
5757-5858- Comment:
5959- sheremet-va 1 hour ago
6060-6161-We recommend all expect(locator) to be expect.element(locator)
6262-6363--------------------------
6464-docs/guide/component-testing.md
6565-6666- const screen = page.elementLocator(baseElement)
6767-6868- // You can use either Testing Library queries or Vitest's page queries
6969- const incrementButton = getByRole('button', { name: /increment/i })
7070-7171- Comment:
7272- sheremet-va 1 hour ago
7373- I don't think we should introduce this confusion. Don't use testing-libraries' getBy* methods anywhere
7474-7575- ----------------------------
7676- docs/guide/component-testing.md
7777-7878- expect(document.activeElement).toBe(nextFocusableElement)
7979-8080-// Test ARIA attributes
8181-expect(modal).toHaveAttribute('aria-modal', 'true')
8282-8383-Comment:
8484- sheremet-va 1 hour ago
8585-we recommend await expect.element(el).toHaveAttribute() (notice await) because it auto-retries the assertion
8686---------------------------
8787-docs/guide/component-testing.md
8888-8989-```tsx
9090-// Mock API calls
9191-vi.mock('../api/userService', () => ({
9292-9393-Comment :
9494- sheremet-va 1 hour ago
9595-9696-For APIs we recommend msw (you can link /guide/mocking/requests)
9797-9898----------------------------
9999-docs/guide/component-testing.md
100100-101101-```tsx
102102-// Mock the API to test different scenarios
103103-const mockUserApi = vi.fn()
104104-vi.mock('../api/users', () => ({ getUser: mockUserApi }))
105105-106106-Comment:
107107- sheremet-va 1 hour ago
108108-This code doesn't work, it will throw ReferenceError. Requests examples should use msw
109109-110110------------------
111111-docs/guide/component-testing.md
112112-113113-mockUserApi.mockResolvedValue({ name: 'John Doe', email: 'john@example.com' })
114114- rerender(<UserProfile userId="123" />)
115115-116116- await waitFor(() => {
117117-118118-Comment:
119119- sheremet-va 1 hour ago
120120-121121-do not use waitFor anywhere. Vitest supports auto-retrying via expect.element
122122-123123-------------------------
124124-docs/guide/component-testing.md
125125-126126- await expect.element(getByText('Please enter a valid email')).toBeInTheDocument()
127127-128128- // Test successful submission
129129- await emailInput.clear()
130130-131131-Comment:
132132- sheremet-va 1 hour ago
133133-fill already does the clear so it's redundant
134134-135135--------------------
136136-docs/guide/component-testing.md
137137-138138- const firstInput = getByLabelText(/username/i)
139139- const lastButton = getByRole('button', { name: /save/i })
140140-141141- firstInput.focus()
142142-143143- Comment:
144144- sheremet-va 1 hour ago
145145- Vitest doesn't have a focus method - I already mentioned it before: #8409 (comment)
146146-147147- ------------------------
148148- docs/guide/component-testing.md
149149-150150- firstInput.focus()
151151- await userEvent.keyboard('{Shift>}{Tab}{/Shift}') // Shift+Tab goes backwards
152152- expect(document.activeElement).toBe(lastButton) // Should wrap to last element
153153-154154- Comment:
155155- sheremet-va 1 hour ago
156156-await expect.element
157157-158158------------------------
159159-docs/guide/component-testing.md
160160-161161-- **Check console errors** for JavaScript errors or warnings
162162-- **Monitor network requests** to debug API calls
163163-164164-For headless mode debugging, add `headless: false` to your browser config temporarily.
165165-166166-Comment:
167167- sheremet-va 1 hour ago
168168-169169- For headless mode debugging
170170-171171-for non-headless or headful
172172-173173-it can't be headless if you set headless: false
174174-175175---------------------------
176176-docs/guide/component-testing.md
177177-178178- // Debug: Check if element exists with different query
179179- const errorElement = page.getByText('Email is required')
180180- console.log('Error element found:', await errorElement.count())
181181-182182- Comment :
183183- sheremet-va 1 hour ago
184184-185185-vitest doesn't have a count, we do have length though
186186-187187--------------------------
188188-docs/guide/component-testing.md
189189-190190-```tsx
191191-// Debug why elements can't be found
192192-const button = page.getByRole('button', { name: /submit/i })
193193-console.log('Button count:', await button.count()) // Should be 1
194194-195195-Comment:
196196- sheremet-va 1 hour ago
197197-no count
198198-199199--------------------------
200200-docs/guide/component-testing.md
201201-202202-// Try alternative queries if the first one fails
203203-if (await button.count() === 0) {
204204- console.log('All buttons:', await page.getByRole('button').all())
205205-206206-Comment:
207207- sheremet-va 1 hour ago
208208-209209-all is not async
210210-211211------------------------
212212-docs/guide/component-testing.md
213213-// If getByRole fails, check what roles/names are available
214214-const buttons = await page.getByRole('button').all()
215215-for (const button of buttons) {
216216- const accessibleName = await button.getAttribute('aria-label')
217217-218218-Comment:
219219- sheremet-va 1 hour ago
220220-221221-there is no getAttribute
222222-223223------------------------------
224224-docs/guide/component-testing.md
225225-226226-const buttons = await page.getByRole('button').all()
227227-for (const button of buttons) {
228228- const accessibleName = await button.getAttribute('aria-label')
229229- || await button.textContent()
230230-231231-Comment:
232232- sheremet-va 1 hour ago
233233-234234-there is no textContent
235235-236236----------------------------
237237-docs/guide/component-testing.md
238238-239239-const submitButton
240240- = page.getByRole('button', { name: /submit/i }) // By accessible name
241241- || page.getByTestId('submit-button') // By test ID
242242- || page.locator('button[type="submit"]') // By CSS selector
243243-244244-Comment:
245245- sheremet-va 1 hour ago
246246-247247-there is no locator
248248-249249----------------------
250250-docs/guide/component-testing.md
251251-252252- // 3. Check if element is hidden or disabled
253253- if (await emailInput.count() > 0) {
254254- console.log('Email input visible:', await emailInput.isVisible())
255255-256256- sheremet-va 1 hour ago
257257-258258-there is no isVisible
259259-260260-Note For you:
261261-Always ensure that the methods exists in the library. Verify if you are unsure either within the repo or going online or ask me if you have any questions
262262-263263-Comment I shared for you
264264-I have put up all the reviews we got from @sheremet-va today . Here is the link to the file => /Users/cr7/Documents/review.md and there is note for you at the end of the markdown. Please ensure that you follow the notes. You need to fix each of the reviews one by one then you also have to provide me with the thoughtful response for @sheremet-va for each of the reviews.
265265-266266----
267267-268268-## CURRENT STATUS & TODO LIST
269269-270270-### ✅ **Already Fixed (3/17 items):**
271271-1. **Hierarchy alignment** - Fixed arrow alignment in Component Testing Hierarchy
272272-2. **vi.mock syntax** - Updated to use `vi.mock(import('...'))` syntax throughout
273273-3. **MSW recommendation** - Added recommendation to use MSW for API mocking with link to `/guide/mocking/requests`
274274-275275-### 🚧 **High Priority - API Issues (Need Immediate Fix):**
276276-4. **Move component testing to browser guides section** - Config.ts placement issue
277277-5. **Replace expect() with expect.element()** - Line 41 & 56 + multiple other instances
278278-6. **Remove Testing Library getBy* confusion** - Line 69 - causes confusion with Vitest APIs
279279-7. **Add await to expect.element assertions** - Line 78 - for auto-retry functionality
280280-8. **Remove waitFor usage** - Line 116 - replace with expect.element auto-retry
281281-9. **Remove redundant clear() call** - Line 129 - fill() already clears
282282-10. **Fix focus method issue** - Line 141 - Vitest doesn't have focus method
283283-11. **Fix headless debugging text** - Line 164 - terminology correction
284284-12. **Replace count() with length** - Line 181, 194, 204 - count() doesn't exist in Vitest
285285-13. **Fix all() method usage** - Line 205, 215 - all() is not async
286286-14. **Replace getAttribute method** - Line 217 - doesn't exist in Vitest
287287-15. **Replace textContent method** - Line 230 - doesn't exist in Vitest
288288-16. **Replace locator method** - Line 241 - doesn't exist in Vitest
289289-17. **Replace isVisible method** - Line 256 - doesn't exist in Vitest
290290-291291-### 📝 **Next Steps:**
292292-1. Fix each issue systematically (one by one as requested)
293293-2. Prepare thoughtful response for each review comment to @sheremet-va
294294-3. Verify all API methods exist in Vitest browser mode documentation
295295-4. Test examples to ensure they work with actual Vitest APIs
296296-297297-### 🎯 **Root Cause Analysis:**
298298-The guide appears to have been written using Playwright/Testing Library APIs instead of the actual Vitest browser mode APIs. Many method names and patterns need to be corrected to match Vitest's implementation.
299299-300300-**Status as of:** September 3, 2025 11:41 AM
301301-**Completion:** 3/17 issues resolved (17.6%)