Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonguo committed Apr 17, 2024
1 parent 01f66d9 commit d62ddac
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion __tests__/Renderer-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import Renderer from '../src/Renderer';

it('refault is rendering', () => {
Expand All @@ -12,3 +12,24 @@ it('should render a test div', () => {

expect(container.querySelector('.rcv-render')).toContainHTML('<div>test</div>');
});

it('should render a test div with footer', () => {
render(<Renderer renderExtraFooter={() => <div>footer</div>} />);

expect(screen.getByText('footer')).toBeInTheDocument();
});

it('should call onOpenEditor and onCloseEditor callback', () => {
const onOpenEditor = jest.fn();
const onCloseEditor = jest.fn();

render(<Renderer onOpenEditor={onOpenEditor} onCloseEditor={onCloseEditor} />);

fireEvent.click(screen.getByRole('switch', { name: 'Show the full source' }));

expect(onOpenEditor).toHaveBeenCalled();

fireEvent.click(screen.getByRole('switch', { name: 'Show the full source' }));

expect(onCloseEditor).toHaveBeenCalled();
});

0 comments on commit d62ddac

Please sign in to comment.