{"id":332018,"date":"2022-04-16T21:00:12","date_gmt":"2022-04-16T21:00:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=332018"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=332018","title":{"rendered":"<span>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 Test-Driven Development \u043d\u0430 React \u0434\u043b\u044f \u0447\u0430\u0439\u043d\u0438\u043a\u043e\u0432<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e Test-Driven Development (TDD) \u2013 \u044d\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0430. \u042d\u0442\u043e \u0437\u0432\u0443\u0447\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0434\u043b\u044f \u0431\u044d\u043a\u0435\u043d\u0434\u0430, \u0435\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0434\u043b\u044f \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f React, \u0447\u0442\u043e \u0436\u0435, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u043e TDD \u043d\u0430 React \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c.<\/p>\n<h2>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043e\u0447\u0435\u043d\u044c \u0443\u0436\u0430\u0441\u043d\u044b\u0439 <strong><em>\u0441\u0447\u0435\u0442\u0447\u0438\u043a<\/em><\/strong>.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3a6\/54c\/312\/3a654c312a533042708abc6679fd68c4.png\" width=\"158\" height=\"159\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3a6\/54c\/312\/3a654c312a533042708abc6679fd68c4.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u043d \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0441\u0447\u0435\u0442\u0435 \u043c\u044b \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435\u0436\u0435\u043b\u0438 \u043d\u0430 \u044d\u0441\u0442\u0435\u0442\u0438\u043a\u0435.<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 React \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<pre><code>yarn create react-app react-test-driven-development<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u043d, \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0432\u0441\u0435 \u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<pre><code>cd react-test-driven-development yarn start<\/code><\/pre>\n<p>\u0412\u044b \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/localhost:3000\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:3000<\/a>.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/796\/ccb\/248\/796ccb248b021c4328b35c084c76e9db.png\" width=\"880\" height=\"415\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/796\/ccb\/248\/796ccb248b021c4328b35c084c76e9db.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u0443\u044e \u043f\u0430\u043f\u043a\u0443 <strong><em>components<\/em><\/strong> \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043f\u043a\u0438 <strong><em>src<\/em><\/strong>. \u0414\u0430\u043d\u043d\u0430\u044f \u043f\u0430\u043f\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c. \u0418 \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0439 \u043f\u0430\u043f\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <strong><em>Counter.test.js<\/em><\/strong>. \u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 TDD \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u0443\u0436\u0435 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0437\u0430\u043b\u043e\u0436\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u044b \u043b\u0443\u0447\u0448\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0443\u043c\u0430\u0435\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0438 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7bc\/527\/312\/7bc5273123c2538f132cdff36585d96f.png\" width=\"286\" height=\"338\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7bc\/527\/312\/7bc5273123c2538f132cdff36585d96f.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430<\/h2>\n<p>\u041d\u0430\u0448 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043f\u0440\u043e\u043f value, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u0442\u044d\u0433\u0435.<\/p>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0442\u0435\u0441\u0442.<\/p>\n<h2>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430<\/h2>\n<p>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 <strong><em>Counter.test.js<\/em><\/strong>.<\/p>\n<pre><code class=\"javascript\">import { render, screen } from '@testing-library\/react'; import Counter from \"Counter\";<\/code><\/pre>\n<p>\u041c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432. \u041d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0439\u0442\u0435\u0441\u044c \u043e 2 \u0441\u0442\u0440\u043e\u0447\u043a\u0435, \u043c\u044b \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430. \u0417\u0430\u0434\u0430\u0447\u0430 TDD \u044d\u0442\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u0441\u044f, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.<\/p>\n<p>\u0421 \u044d\u0442\u0438\u043c \u0432\u0441\u0435\u043c, \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442.<\/p>\n<pre><code class=\"javascript\">test('renders counter component', () => {     render(&lt;Counter value={2} \/>);     const counterElement = screen.getByTestId(\"counter-test\"); });<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0432 DOM \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u0430\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043b\u0441\u044f?<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;2&#187;?<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"javascript\">test('renders counter component', () => {     render(&lt;Counter value={2} \/>);     const counterElement = screen.getByTestId(\"counter-test\");      \/\/ \u0422\u0435\u0441\u0442, \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043b\u0441\u044f \u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430     expect(counterElement).toBeInTheDocument();      \/\/ \u0422\u0435\u0441\u0442, \u0432\u0435\u0440\u043d\u043e \u043b\u0438, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0440\u0430\u0432\u043d\u043e 2     expect(counterElement).toHaveTextContent(\"2\"); });<\/code><\/pre>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b.<\/p>\n<pre><code>yarn test<\/code><\/pre>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ca3\/afd\/2cd\/ca3afd2cdfce7e6f02e42d984c48b582.png\" width=\"880\" height=\"222\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ca3\/afd\/2cd\/ca3afd2cdfce7e6f02e42d984c48b582.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<h2>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/h2>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043f\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b <strong><em>Counter.jsx<\/em><\/strong>. \u0418 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 \u0435\u0433\u043e.<\/p>\n<pre><code class=\"javascript\">import React from \"react\";   \/\/ \u042d\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c  function Counter({value}) {     return (         &lt;p data-testid=\"counter-test\">             {value}         &lt;\/p>     ); }  export default Counter;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043d\u043e\u0432\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432, \u0432\u0441\u0451 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0435\u043b\u0435\u043d\u044b\u043c.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0a4\/014\/dd9\/0a4014dd9b72b982f53304a1f83870c0.png\" width=\"394\" height=\"186\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0a4\/014\/dd9\/0a4014dd9b72b982f53304a1f83870c0.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432 <strong><em>App.js<\/em><\/strong> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0418 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c TDD \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e.<\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432.<\/em><\/p>\n<pre><code>Warning: ReactDOM.render is no longer supported in React 18...<\/code><\/pre>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0430 <a href=\"https:\/\/stackoverflow.com\/questions\/71685441\/react-testing-library-gives-console-error-for-reactdom-render-in-react-18\/71716003#71716003\" rel=\"noopener noreferrer nofollow\">StackOverflow<\/a>.<\/p>\n<h2>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430<\/h2>\n<p>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0432 <strong><em>Counter.jsx<\/em><\/strong>. \u0418 \u043c\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0438 <strong><em>App.js<\/em><\/strong>, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <strong><em>App.test.js<\/em><\/strong>.<\/p>\n<h3>\u0427\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c<\/h3>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u043d\u0430 1<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e, \u043d\u0435 \u0442\u0430\u043a \u043b\u0438? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442.<\/p>\n<h3>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430<\/h3>\n<p>\u0411\u0438\u0431\u043b\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/testing-library.com\/\" rel=\"noopener noreferrer nofollow\"><strong><em>testing-library<\/em><\/strong><\/a> \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438. \u0427\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e!<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043d\u0443\u0436\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d (\u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443) \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u043b\u043e\u0441\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430, \u0442\u043e \u0442\u0435\u0441\u0442\u044b \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438.<\/p>\n<pre><code class=\"javascript\">import { render, screen } from '@testing-library\/react'; import App from '.\/App'; import userEvent from \"@testing-library\/user-event\";<\/code><\/pre>\n<p><strong><em>UserEvent<\/em><\/strong> \u044d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043c\u044b\u0448\u043a\u0438, \u0432\u0432\u043e\u0434 \u0442\u0435\u043a\u0441\u0442\u0430, \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435. \u0410 \u0432\u043e\u0442 \u0438 \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430.<\/p>\n<pre><code class=\"javascript\">import { render, screen } from '@testing-library\/react'; import App from '.\/App'; import userEvent from \"@testing-library\/user-event\";  describe('Render the counter with Button', () => {   render(&lt;App \/>);    it(\"render counter\", async () => {     const appElement = screen.getByTestId('app-test');     expect(appElement).toBeInTheDocument();      \/\/ \u0422\u0435\u0441\u0442, \u0438\u043c\u0435\u0435\u0442 \u043b\u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0432\u0435\u0440\u043d\u043e\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435     const counterElement = screen.getByTestId('counter-test');     expect(counterElement).toHaveTextContent('0');      \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a\u043d\u043e\u043f\u043a\u0438     const buttonElement = screen.getByTestId('button-counter-test');     expect(buttonElement).toBeInTheDocument();      \/\/ \u0421\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438      await userEvent.click(buttonElement);      \/\/ \u0422\u0435\u0441\u0442, \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u043d\u0430 \u043d\u043e\u0432\u043e\u0435, \u0438 \u0432\u0435\u0440\u043d\u043e \u043b\u0438 \u043e\u043d\u043e     expect(counterElement).toHaveTextContent('1');   }) });<\/code><\/pre>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e, \u0442\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u043a\u0430\u043a \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u043d\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435.<\/p>\n<h3>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430<\/h3>\n<p>\u0412\u043d\u0443\u0442\u0440\u044c \u0444\u0430\u0439\u043b\u0430 <strong><em>App.js<\/em><\/strong> \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<pre><code class=\"javascript\">import React, { useState } from \"react\"; import Counter from \".\/components\/Counter\";  function App() {    const [count, setCount] = useState(0);    return (     &lt;div data-testid=\"app-test\">       &lt;Counter value={count} \/>       &lt;button data-testid=\"button-counter-test\" onClick={() => setCount(count + 1)}>Increase&lt;\/button>     &lt;\/div>   ); }  export default App;<\/code><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0443\u043a useState \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<br \/>\u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0442\u0435\u0441\u0442\u044b \u0441\u043d\u043e\u0432\u0430. \u0412\u0441\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0435\u043b\u0435\u043d\u044b\u043c.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/653\/d90\/de1\/653d90de1dc8402ff27e9d683b8c68e5.png\" width=\"451\" height=\"192\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/653\/d90\/de1\/653d90de1dc8402ff27e9d683b8c68e5.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0439\u0442\u0435 \u043c\u043e\u0438 \u043f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f ?! \u041c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043d\u0430\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0435, \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435, \u0441\u0442\u0440\u0430\u0448\u043d\u0435\u043d\u044c\u043a\u043e\u0435, \u043d\u043e \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 React \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f TDD . <\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/661335\/\"> https:\/\/habr.com\/ru\/post\/661335\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0435\u0440\u0432\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e Test-Driven Development (TDD) \u2013 \u044d\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0430. \u042d\u0442\u043e \u0437\u0432\u0443\u0447\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0434\u043b\u044f \u0431\u044d\u043a\u0435\u043d\u0434\u0430, \u0435\u0441\u043b\u0438 \u0447\u0435\u0441\u0442\u043d\u043e, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438 \u0434\u0430\u043d\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0434\u043b\u044f \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434\u0430, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f React, \u0447\u0442\u043e \u0436\u0435, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c.<\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u043e TDD \u043d\u0430 React \u0441 \u043f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c.<\/p>\n<h2>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u0414\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043e\u0447\u0435\u043d\u044c \u0443\u0436\u0430\u0441\u043d\u044b\u0439 <strong><em>\u0441\u0447\u0435\u0442\u0447\u0438\u043a<\/em><\/strong>.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u043d \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043d\u0430\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0441\u0447\u0435\u0442\u0435 \u043c\u044b \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435\u0436\u0435\u043b\u0438 \u043d\u0430 \u044d\u0441\u0442\u0435\u0442\u0438\u043a\u0435.<\/p>\n<h2>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h2>\n<p>\u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 React \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<pre><code>yarn create react-app react-test-driven-development<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u043e\u0437\u0434\u0430\u043d, \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0432\u0441\u0435 \u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u043f\u0440\u043e\u0435\u043a\u0442.<\/p>\n<pre><code>cd react-test-driven-development yarn start<\/code><\/pre>\n<p>\u0412\u044b \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443 <a href=\"http:\/\/localhost:3000\" rel=\"noopener noreferrer nofollow\">http:\/\/localhost:3000<\/a>.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u0443\u044e \u043f\u0430\u043f\u043a\u0443 <strong><em>components<\/em><\/strong> \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043f\u043a\u0438 <strong><em>src<\/em><\/strong>. \u0414\u0430\u043d\u043d\u0430\u044f \u043f\u0430\u043f\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c. \u0418 \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u0442\u043e\u0439 \u043f\u0430\u043f\u043a\u0438 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <strong><em>Counter.test.js<\/em><\/strong>. \u041a\u0430\u043a \u0431\u044b\u043b\u043e \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0430\u043d\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 TDD \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0442\u0435\u0441\u0442\u044b, \u0430 \u0437\u0430\u0442\u0435\u043c \u0443\u0436\u0435 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0437\u0430\u043b\u043e\u0436\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u044b \u043b\u0443\u0447\u0448\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0443\u043c\u0430\u0435\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438 \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0438 \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h2>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430<\/h2>\n<p>\u041d\u0430\u0448 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u043f\u0440\u043e\u043f value, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u0442\u044d\u0433\u0435.<\/p>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e! \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0432\u043d\u0430\u0447\u0430\u043b\u0435 \u0442\u0435\u0441\u0442.<\/p>\n<h2>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430<\/h2>\n<p>\u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 <strong><em>Counter.test.js<\/em><\/strong>.<\/p>\n<pre><code class=\"javascript\">import { render, screen } from '@testing-library\/react'; import Counter from \"Counter\";<\/code><\/pre>\n<p>\u041c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432. \u041d\u0435 \u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0439\u0442\u0435\u0441\u044c \u043e 2 \u0441\u0442\u0440\u043e\u0447\u043a\u0435, \u043c\u044b \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u0435\u0449\u0451 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430. \u0417\u0430\u0434\u0430\u0447\u0430 TDD \u044d\u0442\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442 \u043f\u0440\u043e\u0432\u0430\u043b\u0438\u0442\u0441\u044f, \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.<\/p>\n<p>\u0421 \u044d\u0442\u0438\u043c \u0432\u0441\u0435\u043c, \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0435\u0441\u0442.<\/p>\n<pre><code class=\"javascript\">test('renders counter component', () => {     render(&lt;Counter value={2} \/>);     const counterElement = screen.getByTestId(\"counter-test\"); });<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0432 DOM \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u0430\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0435 \u0432\u0435\u0449\u0438:<\/p>\n<ul>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043b\u0441\u044f?<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 &#171;2&#187;?<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"javascript\">test('renders counter component', () => {     render(&lt;Counter value={2} \/>);     const counterElement = screen.getByTestId(\"counter-test\");      \/\/ \u0422\u0435\u0441\u0442, \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u043b\u0441\u044f \u043b\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430     expect(counterElement).toBeInTheDocument();      \/\/ \u0422\u0435\u0441\u0442, \u0432\u0435\u0440\u043d\u043e \u043b\u0438, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0440\u0430\u0432\u043d\u043e 2     expect(counterElement).toHaveTextContent(\"2\"); });<\/code><\/pre>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b.<\/p>\n<pre><code>yarn test<\/code><\/pre>\n<p>\u041a\u043e\u043c\u0430\u043d\u0434\u0430, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e! \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<h2>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/h2>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u043f\u0430\u043f\u043a\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b <strong><em>Counter.jsx<\/em><\/strong>. \u0418 \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u043d\u0443\u0442\u0440\u0438 \u0435\u0433\u043e.<\/p>\n<pre><code class=\"javascript\">import React from \"react\";   \/\/ \u042d\u0442\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c  function Counter({value}) {     return (         &lt;p data-testid=\"counter-test\">             {value}         &lt;\/p>     ); }  export default Counter;<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043d\u043e\u0432\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0435\u0441\u0442\u043e\u0432, \u0432\u0441\u0451 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0435\u043b\u0435\u043d\u044b\u043c.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u044b \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043e\u0442\u043b\u0438\u0447\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432 <strong><em>App.js<\/em><\/strong> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0418 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c TDD \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e.<\/p>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0434\u0430\u043d\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432.<\/em><\/p>\n<pre><code>Warning: ReactDOM.render is no longer supported in React 18...<\/code><\/pre>\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0430 <a href=\"https:\/\/stackoverflow.com\/questions\/71685441\/react-testing-library-gives-console-error-for-reactdom-render-in-react-18\/71716003#71716003\" rel=\"noopener noreferrer nofollow\">StackOverflow<\/a>.<\/p>\n<h2>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430<\/h2>\n<p>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043d\u043e\u043f\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0432 <strong><em>Counter.jsx<\/em><\/strong>. \u0418 \u043c\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0438 <strong><em>App.js<\/em><\/strong>, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e. \u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <strong><em>App.test.js<\/em><\/strong>.<\/p>\n<h3>\u0427\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c<\/h3>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e \u043d\u0430\u0436\u0430\u0442\u0438\u044e \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u043d\u0430 1<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043b\u0435\u0433\u043a\u043e, \u043d\u0435 \u0442\u0430\u043a \u043b\u0438? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0435\u0441\u0442.<\/p>\n<h3>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u0430<\/h3>\n<p>\u0411\u0438\u0431\u043b\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/testing-library.com\/\" rel=\"noopener noreferrer nofollow\"><strong><em>testing-library<\/em><\/strong><\/a> \u0434\u0430\u0451\u0442 \u043d\u0430\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438. \u0427\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e!<\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043d\u0443\u0436\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043d\u0430 \u044d\u043a\u0440\u0430\u043d (\u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443) \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u043b\u043e\u0441\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430, \u0442\u043e \u0442\u0435\u0441\u0442\u044b \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438.<\/p>\n<pre><code class=\"javascript\">import { render, screen } from '@testing-library\/react'; import App from '.\/App'; import userEvent from \"@testing-library\/user-event\";<\/code><\/pre>\n<p><strong><em>UserEvent<\/em><\/strong> \u044d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043d\u0430\u0436\u0430\u0442\u0438\u0435 \u043c\u044b\u0448\u043a\u0438, \u0432\u0432\u043e\u0434 \u0442\u0435\u043a\u0441\u0442\u0430, \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435. \u0410 \u0432\u043e\u0442 \u0438 \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430.<\/p>\n<pre><code class=\"javascript\">import { render, screen } from '@testing-library\/react'; import App from '.\/App'; import userEvent from \"@testing-library\/user-event\";  describe('Render the counter with Button', () => {   render(&lt;App \/>);    it(\"render counter\", async () => {     const appElement = screen.getByTestId('app-test');     expect(appElement).toBeInTheDocument();      \/\/ \u0422\u0435\u0441\u0442, \u0438\u043c\u0435\u0435\u0442 \u043b\u0438 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0432\u0435\u0440\u043d\u043e\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435     const counterElement = screen.getByTestId('counter-test');     expect(counterElement).toHaveTextContent('0');      \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043a\u043d\u043e\u043f\u043a\u0438     const buttonElement = screen.getByTestId('button-counter-test');     expect(buttonElement).toBeInTheDocument();      \/\/ \u0421\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438      await userEvent.click(buttonElement);      \/\/ \u0422\u0435\u0441\u0442, \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u043d\u0430 \u043d\u043e\u0432\u043e\u0435, \u0438 \u0432\u0435\u0440\u043d\u043e \u043b\u0438 \u043e\u043d\u043e     expect(counterElement).toHaveTextContent('1');   }) });<\/code><\/pre>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e, \u0442\u0435\u0441\u0442\u044b \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u043a\u0430\u043a \u043d\u0430\u043c \u0438 \u043d\u0443\u0436\u043d\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435.<\/p>\n<h3>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430<\/h3>\n<p>\u0412\u043d\u0443\u0442\u0440\u044c \u0444\u0430\u0439\u043b\u0430 <strong><em>App.js<\/em><\/strong> \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<pre><code class=\"javascript\">import React, { useState } from \"react\"; import Counter from \".\/components\/Counter\";  function App() {    const [count, setCount] = useState(0);    return (     &lt;div data-testid=\"app-test\">       &lt;Counter value={count} \/>       &lt;button data-testid=\"button-counter-test\" onClick={() => setCount(count + 1)}>Increase&lt;\/button>     &lt;\/div>   ); }  export default App;<\/code><\/pre>\n<p>\u041c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0445\u0443\u043a useState \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<br \/>\u041f\u043e\u0441\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0442\u0435\u0441\u0442\u044b \u0441\u043d\u043e\u0432\u0430. \u0412\u0441\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0437\u0435\u043b\u0435\u043d\u044b\u043c.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0418 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0439\u0442\u0435 \u043c\u043e\u0438 \u043f\u043e\u0437\u0434\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f ?! \u041c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043d\u0430\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0435, \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435, \u0441\u0442\u0440\u0430\u0448\u043d\u0435\u043d\u044c\u043a\u043e\u0435, \u043d\u043e \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 React \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f TDD . <\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/661335\/\"> https:\/\/habr.com\/ru\/post\/661335\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-332018","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332018"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/332018\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}