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

Telegram announces Search Filters

With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.

Telegram and Signal Havens for Right-Wing Extremists

Since the violent storming of Capitol Hill and subsequent ban of former U.S. President Donald Trump from Facebook and Twitter, the removal of Parler from Amazon’s servers, and the de-platforming of incendiary right-wing content, messaging services Telegram and Signal have seen a deluge of new users. In January alone, Telegram reported 90 million new accounts. Its founder, Pavel Durov, described this as “the largest digital migration in human history.” Signal reportedly doubled its user base to 40 million people and became the most downloaded app in 70 countries. The two services rely on encryption to protect the privacy of user communication, which has made them popular with protesters seeking to conceal their identities against repressive governments in places like Belarus, Hong Kong, and Iran. But the same encryption technology has also made them a favored communication tool for criminals and terrorist groups, including al Qaeda and the Islamic State.

React from br


Telegram React
FROM USA