-
-
Notifications
You must be signed in to change notification settings - Fork 548
Animated counter tests clean #1957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,74 @@ | ||||||||
| import React from 'react'; | ||||||||
| import { render, screen } from '@testing-library/react'; | ||||||||
| import AnimatedCounter from './AnimatedCounter'; | ||||||||
| import '@testing-library/jest-dom'; | ||||||||
| import { act } from '@testing-library/react'; | ||||||||
| describe('AnimatedCounter', () => { | ||||||||
| it('renders the counter with the correct value after animation', async () => { | ||||||||
| render(<AnimatedCounter end={42} duration={0.1} />); | ||||||||
|
|
||||||||
| const counterElement = screen.getByRole('status', { name: /animated counter/i }); | ||||||||
| expect(counterElement).toBeInTheDocument(); | ||||||||
|
|
||||||||
| await waitFor(() => { | ||||||||
| expect(counterElement.textContent).toBe('42'); | ||||||||
| }, { timeout: 500 }); | ||||||||
| }); | ||||||||
| }); | ||||||||
|
Comment on lines
+6
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the unimplemented waitFor function. This test uses +import { render, screen, waitFor } from '@testing-library/react';
-import { render, screen } from '@testing-library/react';Also remove the stub function at lines 71-73.
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
|
|
||||||||
| describe('AnimatedCounter', () => { | ||||||||
| beforeEach(() => { | ||||||||
| jest.useFakeTimers(); | ||||||||
| }); | ||||||||
|
|
||||||||
| afterEach(() => { | ||||||||
| jest.runOnlyPendingTimers(); | ||||||||
| jest.useRealTimers(); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('renders without crashing', () => { | ||||||||
| render(<AnimatedCounter end={100} duration={1000} />); | ||||||||
| expect(screen.getByRole('status')).toBeInTheDocument(); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('renders initial value as 0', () => { | ||||||||
| render(<AnimatedCounter end={100} duration={1000} />); | ||||||||
| expect(screen.getByText('0')).toBeInTheDocument(); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('animates from 0 to end value over time', () => { | ||||||||
| render(<AnimatedCounter end={100} duration={1000} />); | ||||||||
| act(() => { | ||||||||
| jest.advanceTimersByTime(500); | ||||||||
| }); | ||||||||
| const midValue = parseInt(screen.getByRole('status').textContent || '', 10); | ||||||||
| expect(midValue).toBeGreaterThan(0); | ||||||||
| expect(midValue).toBeLessThan(100); | ||||||||
|
|
||||||||
| act(() => { | ||||||||
| jest.advanceTimersByTime(500); | ||||||||
| }); | ||||||||
| expect(screen.getByText('100')).toBeInTheDocument(); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('handles duration 0 (renders instantly)', () => { | ||||||||
| render(<AnimatedCounter end={42} duration={0} />); | ||||||||
| expect(screen.getByText('42')).toBeInTheDocument(); | ||||||||
| }); | ||||||||
|
|
||||||||
| it('does not animate if start and end are equal', () => { | ||||||||
| render(<AnimatedCounter end={50} duration={1000} />); | ||||||||
| expect(screen.getByText('50')).toBeInTheDocument(); | ||||||||
| }); | ||||||||
|
Comment on lines
+60
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the test logic for equal start and end values. The test "does not animate if start and end are equal" is incorrect. The component starts at 0 and animates to the - it('does not animate if start and end are equal', () => {
- render(<AnimatedCounter end={50} duration={1000} />);
- expect(screen.getByText('50')).toBeInTheDocument();
- });
+ it('does not animate if start and end are equal', () => {
+ render(<AnimatedCounter end={0} duration={1000} />);
+ expect(screen.getByText('0')).toBeInTheDocument();
+ });🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| it('has proper accessibility attributes', () => { | ||||||||
| render(<AnimatedCounter end={10} duration={1000} />); | ||||||||
| const counter = screen.getByRole('status'); | ||||||||
| expect(counter).toHaveAttribute('aria-label'); | ||||||||
| }); | ||||||||
| }); | ||||||||
| function waitFor(arg0: () => void, arg1: { timeout: number; }) { | ||||||||
| throw new Error('Function not implemented.'); | ||||||||
| } | ||||||||
|
Comment on lines
+71
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the stub waitFor function. This stub function will cause runtime errors and is unnecessary if you import -function waitFor(arg0: () => void, arg1: { timeout: number; }) {
- throw new Error('Function not implemented.');
-}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "devDependencies": { | ||
| "which": "^5.0.0" | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+5
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainClarify the purpose of this standalone package.json. This minimal package.json with only a 🏁 Script executed: #!/bin/bash
# Check if this is part of a workspace setup and verify package security
echo "Checking for workspace configuration..."
find . -name "package.json" -exec echo "Found: {}" \;
echo ""
echo "Checking for yarn/npm workspace files..."
ls -la | grep -E "(yarn\.lock|package-lock\.json|pnpm-lock\.yaml|\.yarnrc|\.npmrc)"
echo ""
echo "Verifying 'which' package security advisories..."
curl -s https://registry.npmjs.org/which | jq '.versions | keys | .[-5:]'Length of output: 737 🏁 Script executed: #!/bin/bash
echo "Root package.json content (first 50 lines):"
sed -n '1,50p' package.json
echo ""
echo "Checking for workspaces field in root package.json:"
grep -n '"workspaces"' package.json || echo "No workspaces field found"Length of output: 396 Remove or consolidate the redundant root package.json The root package.json isn’t configured as a workspace (no • No Suggested action: either delete this root package.json (and rely on frontend/package.json for dev tooling) or fold its devDependencies into your workspace root if you intend to manage shared tooling there. 🤖 Prompt for AI Agents |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version mismatch for 'which' package.
The
whichpackage version infrontend/package.jsonis^2.0.2, but the rootpackage.jsonspecifies^5.0.0. This inconsistency could lead to conflicts.Consider standardizing on one version across both package.json files.
🤖 Prompt for AI Agents