{"id":13185,"date":"2021-02-11T17:33:55","date_gmt":"2021-02-11T08:33:55","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13185"},"modified":"2023-05-27T22:14:23","modified_gmt":"2023-05-27T13:14:23","slug":"%e3%80%90react%e3%80%91%e3%80%8creact-testing-library%e3%80%8d%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13185","title":{"rendered":"\u3010React\u3011\u300cReact-Testing-Library\u300d\u306b\u3064\u3044\u3066"},"content":{"rendered":"<h2>React-Testing-Library\u3068\u306f\uff1f<\/h2>\n<ul>\n<li>2018\u5e74\u306b\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u307e\u3057\u305f\u3002<\/li>\n<li>Enzyme\u306b\u53d6\u3063\u3066\u4ee3\u308f\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/li>\n<li>\u30e6\u30fc\u30b6\u30fc\u8996\u70b9\u3067\u30c6\u30b9\u30c8\u3092\u884c\u3044\u307e\u3059\u3002<\/li>\n<\/ul>\n<h2>Enzyme\u3068\u306e\u6bd4\u8f03<\/h2>\n<p>Enzyme\u306f\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u306b\u7279\u5316\u3057\u3066\u304a\u308a\u3001state\u3084props\u306a\u3069\u306e\u5b9f\u88c5\u306e\u8a73\u7d30\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u304c\u3001React-Testing-Library\u306f\u7d50\u5408\u30c6\u30b9\u30c8\u306b\u7279\u5316\u3057\u3066\u3044\u3066\u5b9f\u969b\u306b\u30ec\u30f3\u30c0\u30fc\u3055\u308c\u3066\u3044\u308bDOM\u306b\u5bfe\u3057\u3066\u30e6\u30fc\u30b6\u30fc\u304c\u884c\u3046\u64cd\u4f5c\u306b\u8fd1\u3044\u5f62\u306e\u30c6\u30b9\u30c8\u3092\u304b\u3051\u307e\u3059\u3002\uff08\u30e6\u30fc\u30b6\u30fc\u304c\u5b9f\u969b\u306b\u753b\u9762\u4e0a\u3067DOM\u64cd\u4f5c\u3059\u308bE2E\u5bc4\u308a\u306e\u30c6\u30b9\u30c8\u306b\u306a\u308b\u3002\u3082\u3061\u308d\u3093\u9650\u754c\u306f\u3042\u308b\u306e\u3067\u4e00\u90e8API\u306a\u3069\u306f\u30e2\u30c3\u30af\u5316\u306f\u5fc5\u8981\u3067\u3059\u304c\u3002\uff09<\/p>\n<h2>\u6a5f\u80fd<\/h2>\n<h3>render<\/h3>\n<p>React\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306eHTML\u69cb\u9020\u3092\u53d6\u5f97\u3057\u3066\u304f\u308c\u307e\u3059\u3002react-testing-library\u5185\u306e\u51e6\u7406\u3067React\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\uff08screen.debug()\u3067\u3069\u306e\u3088\u3046\u306b\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3055\u308c\u3066\u3044\u308b\u304bDOM\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\uff09<\/p>\n<h4>\u5b9f\u88c5\u4f8b<\/h4>\n<p>\u8a73\u3057\u304f\u306f\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"yrBzIEHh3i\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=13187\">\u3010React\u3011\u300creact-testing-library\u300d\u306e\u300cRender\u300d\u30c6\u30b9\u30c8<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=13187&#038;embed=true#?secret=yrBzIEHh3i\" data-secret=\"yrBzIEHh3i\" width=\"500\" height=\"282\" title=\"&#8220;\u3010React\u3011\u300creact-testing-library\u300d\u306e\u300cRender\u300d\u30c6\u30b9\u30c8&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h3>userEvent<\/h3>\n<p>\u30e6\u30fc\u30b6\u30fc\u304c\u30dc\u30bf\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u308a\u3001\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u306b\u5165\u529b\u3057\u305f\u308a\u3068\u8a00\u3063\u305f\u52d5\u4f5c\u3092\u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\u51fa\u6765\u307e\u3059\u3002\u975e\u540c\u671f\u51e6\u7406\u306b\u306a\u308b\u306e\u3067await\u3067\u5165\u529b\u304c\u5b8c\u4e86\u3059\u308b\u307e\u3067\u5f85\u3063\u305f\u4e0a\u3067\u691c\u8a3c\u3059\u308b\u3053\u3068\u304c\u666e\u901a\u3067\u3059\u3002<\/p>\n<h3>custom hook<\/h3>\n<h3>cleanup<\/h3>\n<p>it\u306e\u4e2d\u3067render\u3092\u4f7f\u3046\u5ea6\u306b\u30d6\u30e9\u30a6\u30b6\u306b\u30de\u30a6\u30f3\u30c8\u3055\u308c\u308b\u306e\u3067\u3059\u304c\u3001cleanup\u3092\u4f7f\u3046\u3068\u30de\u30a6\u30f3\u30c8\u3092\u89e3\u9664\uff08\u30a2\u30f3\u30de\u30a6\u30f3\u30c8\uff09\u3057\u3066\u304f\u308c\u307e\u3059\u3002<span style=\"color: #ff0000;\"><strong>\u30c6\u30b9\u30c8\u9593\u3067\u3042\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u30de\u30a6\u30f3\u30c8\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u306b\u3088\u308b\u526f\u4f5c\u7528\u3092\u9664\u53bb\u3067\u304d<\/strong><strong>\u3088\u308a\u6b63\u78ba\u306a\u30c6\u30b9\u30c8\u3092\u5b9f\u65bd\u3059\u308b\u3053\u3068\u306b\u3064\u306a\u304c\u308a\u307e\u3059\u3002<\/strong><\/span>afterEach\u306a\u3069\u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u5404it\u304c\u547c\u3070\u308c\u305f\u5f8c\u3068\u304b\u306b\u6bce\u56de\u30de\u30a6\u30f3\u30c8\u3092\u89e3\u9664\u3055\u305b\u308b\u305f\u3081\u306b\u4f7f\u308f\u308c\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<h4>\u5b9f\u88c5\u4f8b<\/h4>\n<pre class=\"lang:default decode:true \">import { cleanup } from \"@testing-library\/react\";\r\n\r\nafterEach(() =&gt; cleanup());\r\n\r\ndescribe(\"\u30c6\u30b9\u30c81\", () =&gt; {\r\n  it(\"\u30b1\u30fc\u30b91\", () =&gt; {\r\n    xxxx\r\n  });\r\n});\r\n\r\ndescribe(\"\u30c6\u30b9\u30c82\", () =&gt; {\r\n  it(\"\u30b1\u30fc\u30b92\", () =&gt; {\r\n    yyyy\r\n  });\r\n});<\/pre>\n<h5>describe\u30d6\u30ed\u30c3\u30af<\/h5>\n<p>\u30c6\u30b9\u30c8\u30b9\u30a4\u30fc\u30c8<\/p>\n<h5>it\u30d6\u30ed\u30c3\u30af<\/h5>\n<p>\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3001\u5fc5\u305a\u3057\u3082describe\u30d6\u30ed\u30c3\u30af\u306b\u5185\u5305\u3059\u308b\u5fc5\u8981\u306f\u306a\u3044\u3067\u3059\u3002\u5185\u90e8\u306bexpect\u306a\u3069\u306e\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u3092\u8a18\u8ff0\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"React-Testing-Library\u3068\u306f\uff1f 2018\u5e74\u306b\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u307e\u3057\u305f\u3002 Enzyme\u306b\u53d6\u3063\u3066\u4ee3\u308f\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002 \u30e6\u30fc\u30b6\u30fc\u8996\u70b9\u3067\u30c6\u30b9\u30c8\u3092\u884c\u3044\u307e\u3059\u3002 Enzyme\u3068\u306e\u6bd4\u8f03 Enzyme\u306f\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u306b\u7279\u5316\u3057 [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[116],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13185"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13185"}],"version-history":[{"count":7,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13185\/revisions"}],"predecessor-version":[{"id":20438,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13185\/revisions\/20438"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13185"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}