Telegram Group & Telegram Channel
Лучшие практики для написания тестов с использованием React Testing Library

В статье рассматриваются способы повышения качества тестов, написанных с использованием React Testing Library. Автор делится практическими советами, которые помогут вам писать более надежные и поддерживаемые тесты. Среди ключевых моментов:

- Как избегать тестирования реализаций и сосредотачиваться на поведении компонентов.
- Почему важно работать с пользовательскими событиями вместо прямого взаимодействия с DOM.
- Использование ARIA-атрибутов для более точного поиска элементов.

Эти подходы помогают создавать тесты, которые лучше отражают реальное использование компонентов и упрощают их сопровождение.



export const Form = ({ saveData }) => {
const [state, setState] = useState({
name: "",
email: "",
password: "",
confirmPassword: "",
conditionsAccepted: false,
});

const onFieldChange = (event) => {
let value = event.target.value;
if (event.target.type === "checkbox") {
value = event.target.checked;
}

setState({ ...state, [event.target.id]: value });
};

const onSubmit = (event) => {
event.preventDefault();
saveData(state);
};

return (
<form className="form" onSubmit={onSubmit}>
<div className="field">
<label>Name</label>
<input
id="name"
onChange={onFieldChange}
placeholder="Enter your name"
/>
</div>
<div className="field">
<label>Email</label>
<input
type="email"
id="email"
onChange={onFieldChange}
placeholder="Enter your email address"
/>
</div>
<div className="field">
<label>Password</label>
<input
type="password"
id="password"
onChange={onFieldChange}
placeholder="Password should be at least 8 characters"
/>
</div>
<div className="field">
<label>Confirm password</label>
<input
type="password"
id="confirmPassword"
onChange={onFieldChange}
placeholder="Enter the password once more"
/>
</div>
<div className="field checkbox">
<input type="checkbox" id="conditions" onChange={onFieldChange} />
<label>I agree to the terms and conditions</label>
</div>
<button type="submit">Sign up</button>
</form>
);
};





https://claritydev.net/blog/improving-react-testing-library-tests

✍️ @React_lib



tg-me.com/React_lib/632
Create:
Last Update:

Лучшие практики для написания тестов с использованием React Testing Library

В статье рассматриваются способы повышения качества тестов, написанных с использованием React Testing Library. Автор делится практическими советами, которые помогут вам писать более надежные и поддерживаемые тесты. Среди ключевых моментов:

- Как избегать тестирования реализаций и сосредотачиваться на поведении компонентов.
- Почему важно работать с пользовательскими событиями вместо прямого взаимодействия с DOM.
- Использование ARIA-атрибутов для более точного поиска элементов.

Эти подходы помогают создавать тесты, которые лучше отражают реальное использование компонентов и упрощают их сопровождение.



export const Form = ({ saveData }) => {
const [state, setState] = useState({
name: "",
email: "",
password: "",
confirmPassword: "",
conditionsAccepted: false,
});

const onFieldChange = (event) => {
let value = event.target.value;
if (event.target.type === "checkbox") {
value = event.target.checked;
}

setState({ ...state, [event.target.id]: value });
};

const onSubmit = (event) => {
event.preventDefault();
saveData(state);
};

return (
<form className="form" onSubmit={onSubmit}>
<div className="field">
<label>Name</label>
<input
id="name"
onChange={onFieldChange}
placeholder="Enter your name"
/>
</div>
<div className="field">
<label>Email</label>
<input
type="email"
id="email"
onChange={onFieldChange}
placeholder="Enter your email address"
/>
</div>
<div className="field">
<label>Password</label>
<input
type="password"
id="password"
onChange={onFieldChange}
placeholder="Password should be at least 8 characters"
/>
</div>
<div className="field">
<label>Confirm password</label>
<input
type="password"
id="confirmPassword"
onChange={onFieldChange}
placeholder="Enter the password once more"
/>
</div>
<div className="field checkbox">
<input type="checkbox" id="conditions" onChange={onFieldChange} />
<label>I agree to the terms and conditions</label>
</div>
<button type="submit">Sign up</button>
</form>
);
};





https://claritydev.net/blog/improving-react-testing-library-tests

✍️ @React_lib

BY React




Share with your friend now:
tg-me.com/React_lib/632

View MORE
Open in Telegram


React Telegram | DID YOU KNOW?

Date: |

The lead from Wall Street offers little clarity as the major averages opened lower on Friday and then bounced back and forth across the unchanged line, finally finishing mixed and little changed.The Dow added 33.18 points or 0.10 percent to finish at 34,798.00, while the NASDAQ eased 4.54 points or 0.03 percent to close at 15,047.70 and the S&P 500 rose 6.50 points or 0.15 percent to end at 4,455.48. For the week, the Dow rose 0.6 percent, the NASDAQ added 0.1 percent and the S&P gained 0.5 percent.The lackluster performance on Wall Street came on uncertainty about the outlook for the markets following recent volatility.

Telegram Auto-Delete Messages in Any Chat

Some messages aren’t supposed to last forever. There are some Telegram groups and conversations where it’s best if messages are automatically deleted in a day or a week. Here’s how to auto-delete messages in any Telegram chat. You can enable the auto-delete feature on a per-chat basis. It works for both one-on-one conversations and group chats. Previously, you needed to use the Secret Chat feature to automatically delete messages after a set time. At the time of writing, you can choose to automatically delete messages after a day or a week. Telegram starts the timer once they are sent, not after they are read. This won’t affect the messages that were sent before enabling the feature.

React from ar


Telegram React
FROM USA