Skip to content

Commit

Permalink
test(c-select): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meretamal committed Apr 29, 2023
1 parent 8230ff1 commit cfae58a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/components/c-select/c-select.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { render, screen, RenderOptions } from '@testing-library/vue';
import { describe, it, expect } from 'vitest';
import { CSelect } from './c-select';

const renderComponent = (props?: RenderOptions['props']) =>
render(CSelect, { props });

describe('CSelect', () => {
it('should render the component correctly', () => {
const container = renderComponent();
const selects = container.baseElement.getElementsByTagName('select');
expect(selects.length).toBe(1);
});

it('should display the given label', () => {
renderComponent({ label: 'Name', id: 'name' });
screen.getByLabelText('Name');
});

it('should display the given helper text', () => {
renderComponent({ helperText: 'Error' });
screen.getByText('Error');
});

it('should display the given placeholder', () => {
const container = renderComponent({ placeholder: 'John Doe' });
const select = container.baseElement.getElementsByTagName('select')[0];
const options = select.getElementsByTagName('option');
expect(options.length).toBe(1);
expect(options[0].text).toBe('John Doe');
});

it('should disable the select field', () => {
renderComponent({ label: 'Name', id: 'name', disabled: true });
screen.getByLabelText('Name');
});
});

0 comments on commit cfae58a

Please sign in to comment.