test: add AddToCartButton and ToggleCartIcon integration tests, fix timer cleanup
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { render, screen, fireEvent, act } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { cartAdded, cartDismissed } from '@/shared/model/cart-notifications'
|
||||
import { CartSnackbar } from '@/shared/ui/CartSnackbar'
|
||||
|
||||
@@ -15,6 +15,10 @@ beforeEach(() => {
|
||||
navigateMock.mockClear()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
function renderWithRouter() {
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
@@ -53,7 +57,6 @@ describe('CartSnackbar', () => {
|
||||
vi.advanceTimersByTime(4000)
|
||||
})
|
||||
expect(screen.queryByText(/товар добавлен/i)).not.toBeInTheDocument()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('navigates to /cart and closes on "Перейти в корзину" click', () => {
|
||||
|
||||
Reference in New Issue
Block a user