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
setup test #38
setup test #38
Conversation
package.json
Outdated
"@testing-library/react": "^13.2.0", | ||
"@types/jest": "^27.5.1", | ||
"express": "^4.18.0", | ||
"express-history-api-fallback": "^2.2.1", | ||
"jest-environment-jsdom": "^28.1.0", | ||
"jest-snapshot": "^28.1.0", | ||
"react": "18.0.0", | ||
"react-dom": "18.0.0", | ||
"react-router-dom": "6.3.0", | ||
"styled-components": "5.3.5" | ||
"styled-components": "5.3.5", | ||
"ts-jest": "^28.0.2" |
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.
Все, связанное с тестами можно перенести в devDependencies
}); | ||
it('should render label', () => { | ||
const text = 'Button'; | ||
const button = render( |
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.
Чтобы каждый раз не оборачивать компонент в провайдер, можно завести функцию customRender
:
function customRender(children) {
return render(
<ThemeProvider theme={baseTheme}>
{children}
</ThemeProvider>
);
}
И тогда вызывать ее в тестах вот так
customRender(<Button>{text}</Button>);
src/components/Avatar/style.tsx
Outdated
const Avatar = styled.div.attrs((props: AvatarProps) => ({ | ||
backgroundImage: props.backgroundImage, | ||
size: props.size, | ||
role: 'avatar', |
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.
Атрибут role
вообще нужен для обеспечения доступности — чтобы скринридеры могли понять например, что на элемент можно нажать. И у него есть определенный список значений — https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#roles
В данном случае думаю лучше всего подойдет button
, потому что по элементу можно кликнуть
No description provided.