Skip to content

Commit

Permalink
Stabilize tests against internal DOM changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Jan 2, 2025
1 parent dc38c87 commit 9134490
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/components/src/badge/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,32 @@ import { render, screen } from '@testing-library/react';
/**
* Internal dependencies
*/
import Badge from '..';
import _Badge from '..';

const testid = 'my-badge';
const Badge = ( props: React.ComponentProps< typeof _Badge > ) => (
<_Badge data-testid={ testid } { ...props } />
);

describe( 'Badge', () => {
it( 'should render correctly with default props', () => {
render( <Badge>Code is Poetry</Badge> );
const badge = screen.getByText( 'Code is Poetry' );
const badge = screen.getByTestId( testid );
expect( badge ).toBeInTheDocument();
expect( badge.tagName ).toBe( 'SPAN' );
expect( badge ).toHaveClass( 'components-badge' );
} );

it( 'should render as per its intent and contain an icon', () => {
render( <Badge intent="error">Code is Poetry</Badge> );
const badge = screen.getByText( 'Code is Poetry' );
const badge = screen.getByTestId( testid );
expect( badge ).toHaveClass( 'components-badge', 'is-error' );
expect( badge ).toHaveClass( 'has-icon' );
} );

it( 'should combine custom className with default class', () => {
render( <Badge className="custom-class">Code is Poetry</Badge> );
const badge = screen.getByText( 'Code is Poetry' );
const badge = screen.getByTestId( testid );
expect( badge ).toHaveClass( 'components-badge' );
expect( badge ).toHaveClass( 'custom-class' );
} );
Expand Down

0 comments on commit 9134490

Please sign in to comment.