{"id":13180,"date":"2021-02-11T10:58:41","date_gmt":"2021-02-11T01:58:41","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13180"},"modified":"2023-05-27T22:15:27","modified_gmt":"2023-05-27T13:15:27","slug":"%e3%80%90react%e3%80%91%e3%83%86%e3%82%b9%e3%83%88%e6%89%8b%e6%b3%95%e6%a6%82%e8%a6%81","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13180","title":{"rendered":"\u3010React\u3011\u30c6\u30b9\u30c8\u624b\u6cd5\u6982\u8981\u3001Next.js\u3078\u306ecypress\u306e\u5c0e\u5165\u65b9\u6cd5\u306a\u3069"},"content":{"rendered":"<h2>\u30c6\u30b9\u30c8\u306e\u7a2e\u985e<\/h2>\n<h3>Unit\u30c6\u30b9\u30c8<\/h3>\n<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5358\u4f4d\u306e\u30c6\u30b9\u30c8\u3001\u89aa\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u4f7f\u308f\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30e2\u30c3\u30af\u5316\u3057\u3066\u5207\u308a\u96e2\u3057\u3066\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002\uff08\u64ec\u4f3c\u7684\u306a\u95a2\u6570\u3084props\u3092\u53d7\u3051\u53d6\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\uff09<\/p>\n<h4>\u4f7f\u3048\u308b\u30e9\u30a4\u30d6\u30e9\u30ea<\/h4>\n<p>\u4ee5\u4e0b\u3069\u3061\u3089\u304b\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u884c\u3046\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n<ul>\n<li>Jest + React-Testing-Library<\/li>\n<li>Jest + Enzyme<\/li>\n<\/ul>\n<h3>Integration\u30c6\u30b9\u30c8<\/h3>\n<p>Redux\u306e\u30b9\u30c8\u30a2\u306b\u30a2\u30af\u30bb\u30b9\u3057\u306a\u304c\u3089\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002<\/p>\n<h3>E2E\u30c6\u30b9\u30c8(end to end)<\/h3>\n<p>\u30d6\u30e9\u30a6\u30b6\u304c\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u64cd\u4f5c\u3057\u3066\u3044\u308b\u3088\u3046\u306a\u30c6\u30b9\u30c8\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<h4>\u4f7f\u3048\u308b\u30c4\u30fc\u30eb<\/h4>\n<ul>\n<li>cypress.io<\/li>\n<\/ul>\n<h2>\u30c6\u30b9\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u7a2e\u985e<\/h2>\n<h3>Jest<\/h3>\n<p>\u30c6\u30b9\u30c8\u30e9\u30f3\u30ca\u30fc\u3068\u3057\u3066\u30c6\u30b9\u30c8\u306b\u95a2\u308f\u308b\u57fa\u672c\u7684\u306a\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001React\u516c\u5f0f\u304c\u63a8\u5968\u3057\u3066\u3044\u308b\u30c6\u30b9\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306a\u306e\u3067\u300creact-create-app\u300d\u3068\u304b\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3068\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>React-Testing-Library<\/h3>\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<li>\u306a\u304a\u3001React\u516c\u5f0f\u304c\u63a8\u5968\u3057\u3066\u3044\u308b\u30c6\u30b9\u30c8\u30e9\u30a4\u30d6\u30e9\u30ea\u306a\u306e\u3067\u300creact-create-app\u300d\u3068\u304b\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3068\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/li>\n<\/ul>\n<h3>Enzyme<\/h3>\n<ul>\n<li>2015\u5e74\u306b\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u307e\u3057\u305f\u3002<\/li>\n<li>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u5185\u90e8\u3092\u8a73\u7d30\u306b\u30c6\u30b9\u30c8\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u3046\u306e\u3067Unit\u30c6\u30b9\u30c8\u306b\u5411\u3044\u3066\u3044\u307e\u3059\u3002<\/li>\n<li>Hooks(useEffect\u306a\u3069)\u306e\u30c6\u30b9\u30c8\u3068\u76f8\u6027\u304c\u60aa\u3044\u3067\u3059\u3002<\/li>\n<\/ul>\n<h2>cypress.io(\u30b5\u30a4\u30d7\u30ec\u30b9\uff09<\/h2>\n<p>React\u306eE2E\u30c6\u30b9\u30c8\u30c4\u30fc\u30eb\u3068\u3057\u3066\u3088\u304f\u4f7f\u308f\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u672c\u8a18\u4e8b\u306fcypress10.1.0\u306b\u3066\u691c\u8a3c\u3057\u3066\u3044\u307e\u3059\u3002(9\u4ee5\u524d\u3068\u306f\u7d50\u69cb\u66f8\u304d\u65b9\u304c\u5909\u308f\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002\uff09<\/p>\n<h3>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n<pre class=\"lang:default decode:true\">yarn add -D cypress<\/pre>\n<h3>package.json\u306b\u8d77\u52d5\u30b3\u30de\u30f3\u30c9\u3092\u8ffd\u52a0<\/h3>\n<pre class=\"lang:default decode:true\">  \"scripts\": {\r\n    \"cy:open\": \"cypress open\",\r\n    \"cy:run\": \"cypress run\"\r\n  },<\/pre>\n<h4>cypress open<\/h4>\n<p>\u521d\u56de\u8d77\u52d5\u6642\u306f\u3053\u308c\u3067\u8d77\u52d5\u3059\u308b\u3053\u3068\u3067\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306a\u3069\u3092\u81ea\u52d5\u751f\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u5b9f\u969b\u306b\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u52d5\u304d\u3092\u898b\u306a\u304c\u3089E2E\u30c6\u30b9\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h4>cypress run<\/h4>\n<p>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u4e0a\u3067E2E\u30c6\u30b9\u30c8\u3092\u30d0\u30c3\u30af\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u5b9f\u884c\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<h3>\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c<\/h3>\n<pre class=\"lang:default decode:true\">yarn cypress<\/pre>\n<p>\u305d\u3046\u3059\u308b\u3068cypress\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306a\u3069\u304c\u81ea\u52d5\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<h3>\u8a2d\u5b9a<\/h3>\n<h4>cypress\/e2e\/(\u4efb\u610f\u306e\u30d5\u30a1\u30a4\u30eb\u540d).spec.cy.ts<\/h4>\n<p>\u4efb\u610f\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u8a18\u8ff0\u3092\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">describe(\"empty spec\", () =&gt; {\r\n  \/\/ \u4ee5\u4e0b\u306fit\u3092\u5b9f\u884c\u3059\u308b\u524d\u306b\u5171\u901a\u3067\u5b9f\u884c\u3059\u308b\u51e6\u7406\u306b\u306a\u308a\u307e\u3059\u3002\r\n  beforeEach(() =&gt; {\r\n    cy.visit(\"http:\/\/localhost:3000\");\r\n  });\r\n  it(\"passes\", () =&gt; {\r\n    cy.get('[id=\"player\"]').should(\"be.visible\");\r\n  });\r\n});\r\n\r\nexport {};\u3000\/\/ TypeScript\u306e\u5834\u5408\u3053\u308c\u304c\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/pre>\n<h3>\u5b9f\u884c\u65b9\u6cd5<\/h3>\n<ol>\n<li>Next.js\u306e\u30ed\u30fc\u30ab\u30eb\u30b5\u30fc\u30d0\u30fc\u3092\u4e8b\u524d\u306b\u8d77\u52d5\u3057\u3066\u304a\u304f\u3002\uff08Next.js\u3067\u3042\u308c\u3070\u300cyarn dev\u300d\u306a\u3069\uff09<\/li>\n<li>\u300cyarn cypress\u300d\u3067cypress\u8d77\u52d5<\/li>\n<li>cypress\u306eUI\u4e0a\u306e\u300cSpecs\u300d\u306e\u300c(\u4efb\u610f\u306e\u30d5\u30a1\u30a4\u30eb\u540d).spec.cy.ts\u300d\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001\u5b9f\u884c\u3057\u307e\u3059\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"\u30c6\u30b9\u30c8\u306e\u7a2e\u985e Unit\u30c6\u30b9\u30c8 \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5358\u4f4d\u306e\u30c6\u30b9\u30c8\u3001\u89aa\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u4f7f\u308f\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30e2\u30c3\u30af\u5316\u3057\u3066\u5207\u308a\u96e2\u3057\u3066\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002\uff08\u64ec\u4f3c\u7684\u306a\u95a2\u6570\u3084props\u3092\u53d7\u3051\u53d6\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\uff09 \u4f7f\u3048\u308b\u30e9\u30a4\u30d6\u30e9\u30ea [&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\/13180"}],"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=13180"}],"version-history":[{"count":7,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13180\/revisions"}],"predecessor-version":[{"id":20440,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13180\/revisions\/20440"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13180"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}