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: |

Export WhatsApp stickers to Telegram on Android

From the Files app, scroll down to Internal storage, and tap on WhatsApp. Once you’re there, go to Media and then WhatsApp Stickers. Don’t be surprised if you find a large number of files in that folder—it holds your personal collection of stickers and every one you’ve ever received. Even the bad ones.Tap the three dots in the top right corner of your screen to Select all. If you want to trim the fat and grab only the best of the best, this is the perfect time to do so: choose the ones you want to export by long-pressing one file to activate selection mode, and then tapping on the rest. Once you’re done, hit the Share button (that “less than”-like symbol at the top of your screen). If you have a big collection—more than 500 stickers, for example—it’s possible that nothing will happen when you tap the Share button. Be patient—your phone’s just struggling with a heavy load.On the menu that pops from the bottom of the screen, choose Telegram, and then select the chat named Saved messages. This is a chat only you can see, and it will serve as your sticker bank. Unlike WhatsApp, Telegram doesn’t store your favorite stickers in a quick-access reservoir right beside the typing field, but you’ll be able to snatch them out of your Saved messages chat and forward them to any of your Telegram contacts. This also means you won’t have a quick way to save incoming stickers like you did on WhatsApp, so you’ll have to forward them from one chat to the other.

Find Channels On Telegram?

Telegram is an aspiring new messaging app that’s taking the world by storm. The app is free, fast, and claims to be one of the safest messengers around. It allows people to connect easily, without any boundaries.You can use channels on Telegram, which are similar to Facebook pages. If you’re wondering how to find channels on Telegram, you’re in the right place. Keep reading and you’ll find out how. Also, you’ll learn more about channels, creating channels yourself, and the difference between private and public Telegram channels.

React from it


Telegram React
FROM USA