import { h } from 'preact'; import { render } from '@testing-library/preact'; import '@testing-library/jest-dom'; import { axe } from 'jest-axe'; import { Message } from '../message'; const msg = { username: 'asdf', used_id: 12345, message: 'WE BUILT THIS CITY', color: '#00FFFF', }; const getMessage = (message, props) => ( ); describe('', () => { it('should have no a11y violations', async () => { const { container } = render(getMessage(msg)); const results = await axe(container); expect(results).toHaveNoViolations(); }); it('should render', () => { const { getByText, getByAltText } = render(getMessage(msg)); getByAltText('asdf profile'); getByText(msg.message); const profileLink = getByText(msg.username); expect(profileLink.parentElement).toHaveStyle({ color: msg.color }); }); it('should highlight @mentions to the logged in user', () => { const testMessage = { username: 'testUser', user_id: 456, message: "

hello @testUser

", }; const { getByText } = render( getMessage(testMessage, { currentUserId: testMessage.user_id }), ); const profileLink = getByText(`@${testMessage.username}`); expect(profileLink.parentElement.innerHTML).toMatch( new RegExp(`@${testMessage.username}`, 'i'), ); }); });