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

How to Buy Bitcoin?

Most people buy Bitcoin via exchanges, such as Coinbase. Exchanges allow you to buy, sell and hold cryptocurrency, and setting up an account is similar to opening a brokerage account—you’ll need to verify your identity and provide some kind of funding source, such as a bank account or debit card. Major exchanges include Coinbase, Kraken, and Gemini. You can also buy Bitcoin at a broker like Robinhood. Regardless of where you buy your Bitcoin, you’ll need a digital wallet in which to store it. This might be what’s called a hot wallet or a cold wallet. A hot wallet (also called an online wallet) is stored by an exchange or a provider in the cloud. Providers of online wallets include Exodus, Electrum and Mycelium. A cold wallet (or mobile wallet) is an offline device used to store Bitcoin and is not connected to the Internet. Some mobile wallet options include Trezor and Ledger.

Can I mute a Telegram group?

In recent times, Telegram has gained a lot of popularity because of the controversy over WhatsApp’s new privacy policy. In January 2021, Telegram was the most downloaded app worldwide and crossed 500 million monthly active users. And with so many active users on the app, people might get messages in bulk from a group or a channel that can be a little irritating. So to get rid of the same, you can mute groups, chats, and channels on Telegram just like WhatsApp. You can mute notifications for one hour, eight hours, or two days, or you can disable notifications forever.

React from vn


Telegram React
FROM USA