{"id":497,"date":"2018-10-29T19:27:18","date_gmt":"2018-10-29T10:27:18","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2018\/10\/29\/testing-nuxtjs"},"modified":"2018-10-29T19:27:18","modified_gmt":"2018-10-29T10:27:18","slug":"testing-nuxtjs","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2018\/10\/29\/testing-nuxtjs\/","title":{"rendered":"Nuxt.js\u306e\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3044\u3044\u611f\u3058\u306e\u30c6\u30b9\u30c8\u74b0\u5883\u3092\u3064\u304f\u308b@2018"},"content":{"rendered":"
<\/head><\/p>\n\u73fe\u5728\u3001\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3001Nuxt.js+TypeScript\u3092\u4f7f\u3063\u305fSPA\u306e\u958b\u767a\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u305d\u3046\u3044\u3063\u305f\u30b1\u30fc\u30b9\u306b\u304a\u3044\u3066\u306e\u3001Nuxt.js\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306e\u30c6\u30b9\u30c8\u306b\u5bfe\u3059\u308b\u8003\u3048\u65b9\u3068\u3001\u305d\u306e\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n
\u7c21\u5358\u306b\u3001\u4eca\u56de\u767b\u5834\u3059\u308b\u30c6\u30b9\u30c8\u7a2e\u5225\u306e\u6574\u7406\u3092\u3057\u3066\u304a\u304d\u307e\u3059\u3002\u3088\u308a\u8a73\u3057\u304f\u306f\u3001\u30b0\u30b0\u3063\u305f\u308a\u66f8\u7c4d\u3092\u8aad\u3093\u3060\u308a\u3059\u308b\u306e\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/p>\n
\u3053\u308c\u306b\u52a0\u3048\u3066\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306e\u30c6\u30b9\u30c8\u3067\u306f\u30d6\u30e9\u30a6\u30b6\u74b0\u5883\u304bNode\u74b0\u5883\u304b\u3068\u3044\u3046\u9055\u3044\u3082\u51fa\u3066\u304f\u308b\u305f\u3081\u3001\u30c6\u30b9\u30c8\u3092\u5c0e\u5165\u3059\u308b\u969b\u306f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u3088\u3063\u3066\u65b9\u91dd\u3092\u6c7a\u3081\u3066\u304a\u304f\u306e\u304c\u3044\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
\u7d30\u304b\u306a\u6ce8\u610f\u3068\u3057\u3066\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u70b9\u3067\u3059\u3002<\/p>\n
\u30c6\u30b9\u30c8\u3092\u66f8\u304f\u3053\u3068\u3067\u591a\u304f\u306e\u30e1\u30ea\u30c3\u30c8\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u306a\u305c\u304b\u66f8\u304b\u308c\u306a\u3044\u3053\u3068\u3082\u3042\u308a\u307e\u3059<\/strong>\u3002\u305d\u306e\u7406\u7531\u306e\u4e00\u3064\u306b\u306f\u3001\u300c\u3068\u306b\u304b\u304f\u6642\u9593\u304c\u306a\u3044<\/strong>\u300d\u3068\u3044\u3046\u306e\u304c\u3042\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u7279\u306b\u3001\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3060\u3068\u3001\u30c6\u30b9\u30c8\u74b0\u5883\u3092\u6574\u5099\u3059\u308b\u306e\u306b\u3082\u5de5\u6570\u304c\u304b\u304b\u308b\u305f\u3081\u3001\u3068\u308a\u3042\u3048\u305a\u958b\u767a\u304c\u30b4\u30fc\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u3001\u30c6\u30b9\u30c8\u3092\u5c0e\u5165\u3059\u308b\u9593\u3082\u306a\u304f\u6642\u9593\u304c\u904e\u304e\u3066\u3086\u304f\u3001\u307f\u305f\u3044\u306a\u3053\u3068\u306f\u3042\u308a\u304c\u3061\u3067\u3059\u3002<\/p>\n \u305f\u3060\u3057\u3001\u30c6\u30b9\u30c8\u3092\u66f8\u304f\u3053\u3068\u3067\u958b\u767a\u4e2d\u671f\u4ee5\u964d\u3001\u78ba\u5b9f\u306b\u697d\u306b\u306a\u308a\u307e\u3059\u3057\u3001\u54c1\u8cea\u9762\u3067\u3082\u3001\u4eba\u9593\u306e\u624b\u52d5\u30c1\u30a7\u30c3\u30af\u3067\u306f\b\u691c\u51fa\u3067\u304d\u306a\u3044\u7b87\u6240\u306f\u5897\u3048\u3066\u304d\u307e\u3059<\/strong>\u3002<\/p>\n \u305d\u3053\u3067\u3001\u500b\u4eba\u7684\u306b\u601d\u3046\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u304a\u3051\u308b\u30c6\u30b9\u30c8\u306e\u8003\u3048\u65b9<\/strong>\u3092\u66f8\u3044\u3066\u307f\u307e\u3059\u3002 \u307e\u305a\u3001\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u306f100%\u66f8\u304f\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059<\/strong>\u3002\u30ed\u30b8\u30c3\u30af\u306f\u7db2\u7f85\u3067\u304d\u3066\u3044\u306a\u304f\u3066\u3082\u3001\u5c11\u306a\u304f\u3068\u3082\u30c6\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u7c21\u5358\u306a\u30a2\u30b5\u30fc\u30b7\u30e7\u30f3\u3092\u66f8\u3044\u3066\u304a\u304f\u3001\u3053\u308c\u3060\u3051\u3067\u3082\u3044\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u305f\u3057\u304b\u306b\u6700\u521d\u306f\u5c11\u3057\u5de5\u6570\u3092\u53d6\u3089\u308c\u308b\u3068\u306f\u601d\u3044\u307e\u3059\u304c\u3001\u30c6\u30b9\u30c8\u3092\u66f8\u304f\u3053\u3068\u3067\u3001\u958b\u767a\u5f8c\u671f\u3067\u3082\u5b89\u5fc3\u3067\u304d\u307e\u3059\u3057\u3001\u624b\u52d5\u3067\u306e\u30d0\u30b0\u691c\u51fa\u6642\u9593\u3092\u524a\u6e1b\u3067\u304d\u3001\u52b9\u7387\u3082\u4e0a\u304c\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n \u6b21\u306b\u3001\u7d50\u5408\u30c6\u30b9\u30c8\u306b\u306f\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u307b\u3069\u6642\u9593\u3092\u5272\u304f\u3079\u304d\u3067\u306f\u306a\u3044\u3068\u8003\u3048\u307e\u3059<\/strong>\u3002\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092100%\u3068\u3059\u308b\u3068\u3001\u521d\u671f\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306f10%-20%\u307b\u3069\u304c\u76ee\u5b89\u3067\u3059\u3002\u30c6\u30b9\u30c8\u30d4\u30e9\u30df\u30c3\u30c9\u306f\u610f\u8b58\u3057\u307e\u3059\u304c\u3001\u6b63\u4e09\u89d2\u5f62\u3088\u308a\u306f\u30a2\u30b9\u30c6\u30ed\u30a4\u30c9<\/a>\u306e\u3088\u3046\u306a\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u3002<\/p>\n \u305f\u3060\u3057\u3001\u3053\u308c\u306f\u4ee5\u4e0b\u306e\u6761\u4ef6\u304c\u524d\u63d0\u3068\u306a\u3063\u3066\u304d\u307e\u3059\u3002<\/p>\n \u3082\u3061\u308d\u3093\u7406\u60f3\u7684\u306b\u306f\u4e21\u65b9\u3042\u308b\u3068\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u306b\u3042\u308b\u7a0b\u5ea6\u4efb\u305b\u3089\u308c\u308b\u304b\u3089\u3053\u305d\u3001\u7d50\u5408\u30c6\u30b9\u30c8\u306f\u6700\u5c0f\u9650\u306b\u3057\u305f\u308a\u5f8c\u56de\u3057\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u306e\u3061\u307b\u3069\u7d39\u4ecb\u3057\u307e\u3059\u304c\u3001\u4f8b\u3048\u3070\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30c6\u30b9\u30c8\u3067\u3001\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30c6\u30b9\u30c8\u3092\u91cd\u70b9\u7684\u306b\u884c\u3063\u3066\u3044\u308b\u306e\u306f\u305d\u306e\u305f\u3081\u3067\u3059\u3002<\/p>\n \u9577\u304f\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u5f8c\u56de\u3057\u3067\u304d\u308b\u3068\u3053\u308d\u306f\u5f8c\u56de\u3057\u306b\u3057\u3066\u3001\u6700\u5c0f\u9650\u306e\u30b3\u30b9\u30c8\u3067\u3001\u304b\u3064\u3001\u958b\u767a\u8005\u3082\u697d\u306b\u306a\u308c\u308b\u3088\u3046\u306a\u30c6\u30b9\u30c8\u3068\u306e\u4ed8\u304d\u5408\u3044\u65b9\u304c\u3001\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306f\u7406\u60f3\u304b\u3068\u8003\u3048\u307e\u3059<\/strong>\u3002<\/p>\n TL;DR\u306b\u3082\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u7c21\u5358\u306b\u30c6\u30b9\u30c8\u65b9\u91dd\u3092\u307e\u3068\u3081\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n \u305d\u308c\u305e\u308c\u3001\u30c6\u30b9\u30c8\u5bfe\u8c61\u306b\u308f\u3051\u3066\u898b\u3066\u3086\u304d\u307e\u3059\u3002<\/p>\n \u57fa\u672c\u306fJest<\/a>\u3092\u4f7f\u3063\u3066\u666e\u901a\u306b\u30c6\u30b9\u30c8\u3092\u66f8\u3044\u3066\u3086\u304d\u307e\u3059\u3002<\/p>\n \u3053\u308c\u3092\u5fdc\u7528\u3057\u3066\u7d9a\u304f\u30c6\u30b9\u30c8\u3082\u66f8\u3044\u3066\u3086\u304d\u307e\u3059\u3002<\/p>\n Vuex\u5b9f\u88c5\u306e\u30c6\u30b9\u30c8\u306f\u3001\u4e3b\u306b\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3067\u307e\u304b\u306a\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u57fa\u672c\u7684\u306b\u306fRedux\u306a\u3069\u3068\u540c\u69d8\u306b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u89b3\u70b9\u3067\u30c6\u30b9\u30c8\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n \u8a73\u7d30\u306f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u3092\u898b\u308b\u3068\u826f\u3044\u3067\u3059\u304c\u3001action\u306e\u30c6\u30b9\u30c8\u3067\u306f\u3001mutation\u306e \u307e\u305f\u3001\u30d5\u30a1\u30c3\u30c8action\u3092\u9632\u3050\u305f\u3081\u3001\u5171\u901a\u306eaction\u306f\u30d8\u30eb\u30d1\u30fc\u3068\u3057\u3066\u5916\u51fa\u3057\u3057\u305f\u308a\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u51e6\u7406\u306a\u3069action\u306e\u8cac\u52d9\u306b\u95a2\u4fc2\u306a\u3044\u30ed\u30b8\u30c3\u30af\u3092\u5225\u306e\u95a2\u6570\u306b\u79fb\u3057\u305f\u308a\u7b49\u3092\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u30c6\u30b9\u30c8\u306e\u8907\u96d1\u5ea6\u3092\u4e0a\u3052\u305a\u306b\u7db2\u7f85\u6027\u3092\u9ad8\u3081\u308b\u3053\u3068\u306b\u3082\u3064\u306a\u304c\u308a\u307e\u3059\u3002<\/p>\n \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30c6\u30b9\u30c8\u306b\u95a2\u3057\u3066\u306fStorybook\u3092\u30d9\u30fc\u30b9\u3068\u3057\u3001Jest\u3067\u8db3\u308a\u306a\u3044\u90e8\u5206\u3092\u88dc\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n \u5927\u307e\u304b\u306a\u65b9\u91dd\u3068\u3057\u3066\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u3067\u304d\u308b\u3060\u3051\u30b9\u30c6\u30fc\u30c8\u30ec\u30b9\u306b\u3057\u3066\u3001\u89aa\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3088\u308a\u3082\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u632f\u308b\u821e\u3044\u306b\u6ce8\u610f\u3057\u3066\u30c6\u30b9\u30c8\u3057\u3066\u3086\u304f\u3068\u3044\u3046\u3053\u3068\u3092\u8003\u3048\u307e\u3057\u305f\u3002\u5177\u4f53\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u4e8b\u67c4\u3067\u3059\u3002<\/p>\n \u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u7740\u76ee\u3059\u308b\u305f\u3081\u3001\u30c6\u30b9\u30c8\u306f\u81ea\u7136\u3068\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u7684\u3001\u30db\u30ef\u30a4\u30c8\u30dc\u30c3\u30af\u30b9\u7684\u306b\u306a\u308a\u307e\u3059\u3002\u305d\u308c\u3067\u3082\u6a5f\u80fd\u304c\u62c5\u4fdd\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u89b3\u70b9\u3067\u30c6\u30b9\u30c8\u304c\u3067\u304d\u308b\u3068\u3044\u3044\u304b\u306a\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002\u8a73\u3057\u304f\u898b\u3066\u3086\u304d\u307e\u3059\u3002<\/p>\n \u5b9f\u969b\u306eDOM\u306e\u898b\u305f\u76ee\u306e\u30c6\u30b9\u30c8\u3067\u3059\u3002\u3053\u308c\u306fStorybook\u306e\u672c\u6765\u306e\u76ee\u7684\u3067\u3001\u307e\u305a\u306fUI\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u3057\u3066\u6b8b\u3057\u3066\u304a\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4f8b\u3048\u3070\u30d5\u30a9\u30fc\u30e0\u306e\u6b63\u5e38\u7cfb\u3068\u7570\u5e38\u7cfb\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n <\/a><\/p>\n 2\u91cd\u7ba1\u7406\u306f\u8f9b\u3044\u306e\u3067\u3001\u63cf\u753b\u3059\u308bstory\u306fJest\u3067\u66f8\u3044\u305f\u3082\u306e\u3092\u6d41\u7528\u3057\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u304c\u3042\u3063\u305f\u3068\u3057\u305f\u3089\u3001<\/p>\n Storybook\u5074\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306bJest\u304b\u3089\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3054\u3068\u306estory\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u30c6\u30b9\u30c8\u3068\bUI\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u9023\u52d5\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n \u52a0\u3048\u3066\u3053\u306e\u30c6\u30b9\u30c8\u9818\u57df\u306b\u306f\u3001Visual Regression\u30c6\u30b9\u30c8\u3082\u306f\u3044\u3063\u3066\u304f\u308b\u3068\u601d\u3044\u307e\u3059\u3002Visual Regression\u30c6\u30b9\u30c8\u306f\u305d\u306e\u540d\u306e\u901a\u308a\u3001UI\u306e\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3092\u6bd4\u8f03\u3057\u3066\u5dee\u5206\u691c\u51fa\u3059\u308b\u30c6\u30b9\u30c8\u306e\u3053\u3068\u3067\u3059\u3002\u6570\u5e74\u524d\u306a\u3069\u306f\u3064\u3089\u307f\u306e\u3042\u3063\u305f\u3053\u306e\u624b\u6cd5\u3067\u3059\u304c\u3001\u6700\u8fd1\u3067\u306fHeadless Chrome\u306a\u3069\u306e\u6069\u6075\u3082\u3042\u308a\u305a\u3044\u3076\u3093\u3084\u308a\u3084\u3059\u304f\u306a\u308a\u307e\u3057\u305f\u3002\u307e\u3060\u73fe\u5728\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u306f\u5c0e\u5165\u3057\u3066\u3044\u307e\u305b\u3093\u304c\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u5f8c\u671f\u306b\u3044\u308c\u3066\u3082\u554f\u984c\u306f\u306a\u3044\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002<\/p>\n \u30af\u30ea\u30c3\u30af\u3084\u5165\u529b\u306a\u3069\u306eDOM\u30a4\u30d9\u30f3\u30c8\u306b\u5bfe\u3059\u308b\u632f\u308b\u821e\u3044\u306e\u30c6\u30b9\u30c8\u3067\u3059\u3002\u3053\u3061\u3089\u304c\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u4e3b\u306a\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3068\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002Jest\u3068Vue Test Utils\u3092\u7528\u3044\u3066\u3001\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9f\u88c5\u3057\u307e\u3059\u3002<\/p>\n Storybook\u306e\u30a2\u30c9\u30aa\u30f3\u3067\u30c6\u30b9\u30c8\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u81ea\u52d5\u5316\u3092\u8003\u3048Jest\u3067\u5b9f\u88c5\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n \u307e\u305f\u3001Jest\u3001Vue Test Utils\u3092\u4f7f\u3048\u3070\u3001\u3042\u308b\u7a0b\u5ea6\u8907\u96d1\u306a\u30e1\u30bd\u30c3\u30c9\u3084\u30ed\u30b8\u30c3\u30af\u3082\u30c6\u30b9\u30c8\u53ef\u80fd\u3067\u3059\u304c\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u53ef\u80fd\u306a\u9650\u308a\u3001\u30c7\u30fc\u30bf\u306e\u63cf\u753b\u3068\u3001\u30a4\u30d9\u30f3\u30c8\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u767a\u706b\u306e\u307f\u3092\u8cac\u52d9\u3068\u3055\u305b\u3001\u30d3\u30b8\u30cd\u30b9\u30ed\u30b8\u30c3\u30af\u3068\u8a00\u3048\u308b\u5b9f\u88c5\u306f\u3001Vuex\u5074\u3084\u30b5\u30fc\u30d3\u30b9\u306b\u5207\u308a\u51fa\u3059\u3053\u3068\u3092\u610f\u8b58\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u8cac\u52d9\u304c\u81ea\u660e\u3068\u306a\u308a\u3001\u30c6\u30b9\u30c8\u81ea\u4f53\u7701\u7565\u3067\u304d\u308b\u30b1\u30fc\u30b9\u3082\u591a\u3044\u3067\u3059\u3002<\/p>\n \u305d\u3057\u3066\u3001\u3042\u308b\u7a0b\u5ea6\u6a5f\u80fd\u304c\u304b\u305f\u307e\u3063\u3066\u304d\u305f\u6bb5\u968e\u3067\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u52d5\u4f5c\u3092\u7d50\u5408\u3055\u305b\u308b\u3001\u3044\u308f\u3086\u308bE2E\u30c6\u30b9\u30c8\u3082\u52b9\u679c\u7684\u304b\u3068\u601d\u3044\u307e\u3059\u3002Nuxt.js\u3060\u3068\u3001Nuxt\b Class<\/a>\u3092\u4f7f\u7528\u3057\u3066\u7d50\u5408\u30c6\u30b9\u30c8\u3092\u884c\u3046<\/a>\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u304c\u3001\u30d6\u30e9\u30a6\u30b6\u3092\u901a\u3059\u306e\u3067\u3042\u308c\u3070TestCafe<\/a>\u306a\u3069\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n DOM\u69cb\u9020\u306b\u95a2\u3059\u308b\u30c6\u30b9\u30c8\u3067\u3001\u3053\u308c\u306f\u3044\u308f\u3086\u308bsnapshot\u30c6\u30b9\u30c8\u3068\u8a00\u3044\u63db\u3048\u3066\u3082\u554f\u984c\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002\u63cf\u753b\u30d1\u30bf\u30fc\u30f3\u306e\u4fdd\u8b77\u3068\u3001\u4fee\u6b63\u306b\u5bfe\u3059\u308b\u5f71\u97ff\u7bc4\u56f2\u3092\u628a\u63e1\u3059\u308b\u306e\u304c\u4e3b\u306a\u76ee\u7684\u3067\u3059\u3002<\/p>\n \u3053\u3061\u3089\u306fJest\u306esnapshot\u30c6\u30b9\u30c8<\/a>\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002\u7570\u5e38\u7cfb\u3082\u542b\u3081\u3066\u3001\u8868\u793a\u306e\u30c6\u30b9\u30c8\u306fsnapshot\u306e\u8cac\u52d9\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n Storybook\u3068\u540c\u6642\u306b\u30c6\u30b9\u30c8\u30b1\u30fc\u30b9\u3082\u78ba\u8a8d\u3067\u304d\u308c\u3070\u3001\u5c0f\u3055\u3044\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092TDD\u7684\u306b\u958b\u767a\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3060\u308d\u3046\u3001\u3068\u601d\u3044\u3001Specifications\u3068\u3044\u3046\u30a2\u30c9\u30aa\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u3001\u516c\u5f0f\u306eJest\u30a2\u30c9\u30aa\u30f3\u304cVue.js\u5bfe\u5fdc\u3055\u308c\u3066\u304b\u3089\u5c0e\u5165\u3057\u305f\u307b\u3046\u304c\u7dda\u304c\u826f\u3055\u305d\u3046\u3060\u3063\u305f\u305f\u3081\u3001\u4f7f\u7528\u3092\u3084\u3081\u307e\u3057\u305f\u3002\u8a73\u3057\u304f\u306f\u3053\u3061\u3089<\/a>\u2026\u3002<\/p>\n \u30c6\u30b9\u30c8\u3068\u306f\b\u307e\u305f\b\u5225\u306e\u8a71\u3067\u3059\u304c\u3001\b\u4e0a\u8a18\u306fTypeScript\u3067\u578b\u4ed8\u3051\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u524d\u63d0\u3068\u306a\u308a\u307e\u3059\u3002\u578b\u304c\u3042\u308b\u3053\u3068\u3067\u3001\u4fdd\u8b77\u30c6\u30b9\u30c8\u3092\u8584\u304f\u3057\u3066\u3082\u3001\u521d\u671f\u306e\u4ed5\u69d8\u5909\u66f4\u306b\u3088\u308b\u5f71\u97ff\u7bc4\u56f2\u3092\u62fe\u3044\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3057\u3001\u578b\u3092\u6c7a\u3081\u308c\u3070\u63a8\u8ad6\u304c\u3055\u308c\u308b\u306e\u3067\u3001\u4f55\u3082\u8003\u3048\u305a\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30e1\u30ea\u30c3\u30c8\u306f\u3044\u3046\u307e\u3067\u3082\u306a\u3044\u3068\u601d\u3046\u306e\u3067\u3053\u3053\u3067\u8a73\u3057\u304f\u306f\u66f8\u304d\u307e\u305b\u3093\u304c\u3001\u001b\u4f8b\u3048\u3070Vuex\u30b9\u30c6\u30fc\u30c8\u306e\u5b9f\u88c5\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n \u578b\u3092\u4f5c\u3063\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u4f8b\u3048\u3070 \u307e\u305f\u3001\u63a8\u8ad6\u3082\u3088\u304f\u3067\u304d\u3066\u3044\u3066\u3001 \u4ee5\u4e0b\u306e\u3088\u3046\u306b \u5b66\u7fd2\u30b3\u30b9\u30c8\u3084\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u9593\u306a\u3069\u001b\u306f\u3042\u308b\u306e\u3067\u3001\u9078\u5b9a\u306f\u5fc5\u305a\u3057\u3082\u001b\u63a8\u5968\u3059\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305f\u3060\u3001TypeScript\u306b\u305b\u3088Flow\u306b\u305b\u3088\u3001\u5c0e\u5165\u81ea\u4f53\u306f\u76f4\u3050\u306b\u3067\u304d\u308b<\/a>\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u5f8c\u306e\u30b3\u30fc\u30c9\u306b\u306f\u5f71\u97ff\u304c\u306a\u3044\u3001(\u30ad\u30ec\u30a4\u3067\u306f\u306a\u3044\u3051\u3069)\u52d5\u7684\u306b\u66f8\u3053\u3046\u3068\u601d\u3048\u3070\u66f8\u3051\u308b\u3001\u3068\u3044\u3046\u3053\u3068\u306a\u3069\u304b\u3089\u3001\u7a4d\u6975\u7684\u306b\u907f\u3051\u308b\u7406\u7531\u306f\u3042\u307e\u308a\u306a\u3044\u306e\u304b\u306a\u3068\u601d\u3044\u307e\u3059\u3002Vue.js 3.x\u3082\u30b3\u30fc\u30c9\u30d9\u30fc\u30b9\u306fTypeScript\u3067\u958b\u767a\u3055\u308c\u3066\u3044\u307e\u3059<\/a>\u3002<\/p>\n \u4ee5\u4e0a\u3001Nuxt.js\u306e\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306e\u30c6\u30b9\u30c8\u74b0\u5883\u3067\u3057\u305f\u3002\u304a\u6c17\u3065\u304d\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u3042\u3093\u307e\u308aNuxt.js\u3068\u304bVue\u3060\u3068\u304b\u306f\u95a2\u4fc2\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n \u3053\u308c\u304c\u6b63\u89e3\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u304f\u3001\u76ee\u7684\u306b\u3088\u3063\u3066\u3001\b\u30c6\u30b9\u30c8\u3092\u539a\u304f\u3057\u305f\u308a\u8584\u304f\u3057\u305f\u308a\u3001\u5225\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u3092\u3068\u3063\u305f\u308a\u3082\u8003\u3048\u3089\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u305f\u3060\u3001\u3069\u3093\u306a\u5834\u5408\u3067\u3082\u3001\u3069\u3046\u54c1\u8cea\u3092\u4fdd\u3063\u3066\u3086\u304f\u304b\u65b9\u91dd\u3092\u6c7a\u3081\u3066\u304a\u304f\u3053\u3068\u304c\u5927\u4e8b\u3060\u3068\u8003\u3048\u307e\u3059\u3002\u001b\u53c2\u8003\u306b\u306a\u308c\u3070\u5e78\u3044\u3067\u3059\u3002<\/p>\n <\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":" \u73fe\u5728\u3001\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u3001Nuxt.js+TypeScript\u3092\u4f7f\u3063\u305fSPA\u306e\u958b\u767a\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001\u305d\u3046\u3044\u3063\u305f\u30b1\u30fc\u30b9\u306b\u304a\u3044\u3066\u306e\u3001Nuxt.js\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306e\u30c6\u30b9\u30c8\u306b\u5bfe\u3059\u308b\u8003\u3048\u65b9\u3068\u3001\u305d\u306e\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002 TL;DR \u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\/\u7d50\u5408\u30c6\u30b9\u30c8=>Jest UI\u30c6\u30b9\u30c8=>Storybook\u3092\u30d9\u30fc\u30b9\u306b\u3001Jest\u3067\u8db3\u308a\u306a\u3044\u90e8\u5206\u3092\u88dc\u3046 \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u6280\u8853\u30b9\u30bf\u30c3\u30af Nuxt.j […]<\/p>\n","protected":false},"author":1,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/497"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=497"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/497\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media\/826"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n(\u5c0f\u898f\u6a21\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3084\u7d99\u7d9a\u7684\u306a\u958b\u767a\u304c\u306a\u3044\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306f\u9664\u304d\u307e\u3059)\u3002<\/p>\n\n
\u30c6\u30b9\u30c8\u65b9\u91dd<\/h2>\n
\n
\u57fa\u672c\u306e\u30c6\u30b9\u30c8<\/h2>\n
function sum(a, b) {\n return a + b;\n}\n\ntest('adds 1 + 2 to equal 3', () => {\n expect(sum(1, 2)).toBe(3);\n});<\/code><\/pre>\n
Vuex\u5b9f\u88c5\u306e\u30c6\u30b9\u30c8<\/h2>\n
\n
\/\/ action\u306e\u30c6\u30b9\u30c8\u4f8b\nit('\u30ea\u30bd\u30fc\u30b9\u4e00\u89a7\u3092\u53d6\u5f97\u3067\u304d\u308b\u3053\u3068', async () => {\n nock(apiServer())\n .get(SOME_ENDPOINT)\n .query(SOME_QUERY)\n .reply(200, {\n message: 'OK',\n resources: [...]\n });\n const success = await testAction(\n actions.getResources,\n null,\n STATE_MOCK,\n [\n { type: 'request' },\n {\n type: 'success',\n payload: {\n resources: [...]\n },\n },\n ],\n { rootState: ROOT_STATE_MOCK },\n );\n expect(success).toBe(true);\n}<\/code><\/pre>\n
commit<\/code>\u306e\u4ed6\u306b\u3001\u5225action\u306e
dispatch<\/code>\u3082\u30c6\u30b9\u30c8\u3067\u304d\u308b\u3088\u3046\u306b
testAction<\/code>\u95a2\u6570\u3092\u8abf\u6574\u3057\u3066\u3044\u307e\u3059<\/a>\u3002<\/p>\n
\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u30c6\u30b9\u30c8<\/h2>\n
\n
\u898b\u305f\u76ee\u306e\u30c6\u30b9\u30c8<\/h3>\n
import { noop } from 'lodash';\nimport { shallowMount } from '@vue\/test-utils';\nimport { usersStateMock } from '~\/test\/mock\/';\nimport C from '.\/users.vue';\n\nconst template = `<C :items=\"items\" :get-list=\"getList\" \/>`;\n\nexport const story = {\n components: { C },\n data() {\n return {\n items: usersStateMock(),\n getList: noop,\n };\n },\n template: template,\n};\n\nexport const storyError = {\n components: { C },\n data() {\n return {\n items: usersStateMock({\n errorMessage: '\u30e6\u30fc\u30b6\u30fc\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002',\n }),\n getList: noop,\n };\n },\n template: template,\n};\n\ndescribe('components\/users', function() {\n it('\u30e6\u30fc\u30b6\u30fc\u306e\u4e00\u89a7\u3092\u63cf\u753b\u3067\u304d\u308b', () => {\n const wrapper = shallowMount(C, {\n propsData: story.data(),\n });\n expect(wrapper.element).toMatchSnapshot();\n });\n it('\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u63cf\u753b\u3067\u304d\u308b', () => {\n const wrapper = shallowMount(C, {\n propsData: storyError.data(),\n });\n expect(wrapper.element).toMatchSnapshot();\n });\n});<\/code><\/pre>\n
import { storiesOf } from '@storybook\/vue';\nimport { story, storyError } from '~\/components\/users.spec.ts';\n\nstoriesOf('components\/users', module)\n .add('\u6b63\u5e38\u7cfb', () => {\n return story;\n })\n .add('\u7570\u5e38\u7cfb', () => {\n return storyError;\n });<\/code><\/pre>\n
\u632f\u308b\u821e\u3044\u306e\u30c6\u30b9\u30c8<\/h3>\n
it('\u30af\u30ea\u30c3\u30af\u306e\u4f8b', () => {\n expect(wrapper.vm.count).toBe(0)\n const button = wrapper.find('button')\n button.trigger('click')\n expect(wrapper.vm.count).toBe(1)\n})\n\nit('\u30ad\u30fc\u30a2\u30c3\u30d7\u306e\u4f8b', () => {\n const wrapper = mount(QuantityComponent)\n wrapper.trigger('keydown.up')\n expect(wrapper.vm.quantity).toBe(1)\n})\n\nit('\u30a4\u30d9\u30f3\u30c8\u767a\u884c\u306e\u4f8b', () => {\n expect(wrapper.vm.count).toBe(0)\n const button = wrapper.find('button')\n button.trigger('click')\n \/\/ \u30a4\u30d9\u30f3\u30c8\u306e\u767a\u884c\n expect(wrapper.emitted().foo).toBeTruthy()\n \/\/ \u30a4\u30d9\u30f3\u30c8\u306e\u6570\n expect(wrapper.emitted().foo.length).toBe(2)\n \/\/ \u30a4\u30d9\u30f3\u30c8\u306b\u6e21\u3055\u308c\u305f\u30c7\u30fc\u30bf\n expect(wrapper.emitted().foo[1]).toBe([123])\n})\n\nit('\u975e\u540c\u671f\u306a\u30c7\u30fc\u30bf\u53d6\u5f97\u306e\u4f8b', (done) => {\n const wrapper = shallowMount(Foo)\n wrapper.find('button').trigger('click')\n wrapper.vm.$nextTick(() => {\n expect(wrapper.vm.value).toBe('value')\n done()\n })\n})\n\ndescribe('Vuex\u306e\u4f8b', () => {\n let actions\n let store\n\n beforeEach(() => {\n actions = {\n actionClick: jest.fn(),\n actionInput: jest.fn()\n }\n store = new Vuex.Store({\n state: {},\n actions\n })\n })\n\n it('action\u306edispatch\u304c\u3067\u304d\u308b\u3053\u3068', () => {\n const wrapper = shallowMount(Actions, { store, localVue })\n const input = wrapper.find('input')\n input.element.value = 'input'\n input.trigger('input')\n expect(actions.actionInput).toHaveBeenCalled()\n })\n})<\/code><\/pre>\n
DOM\u69cb\u9020\u306e\u30c6\u30b9\u30c8<\/h3>\n
describe('components\/users', function() {\n it('\u30e6\u30fc\u30b6\u30fc\u306e\u4e00\u89a7\u3092\u63cf\u753b\u3067\u304d\u308b', () => {\n const wrapper = shallowMount(C, {\n propsData: story.data(),\n });\n expect(wrapper.element).toMatchSnapshot();\n });\n it('\u7ba1\u7406\u8005\u30e6\u30fc\u30b6\u30fc\u3092\u592a\u5b57\u3067\u63cf\u753b\u3067\u304d\u308b', () => {\n const wrapper = shallowMount(C, {\n propsData: storyAdmin.data(),\n });\n expect(wrapper.element).toMatchSnapshot();\n });\n it('\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u63cf\u753b\u3067\u304d\u308b', () => {\n const wrapper = shallowMount(C, {\n propsData: storyError.data(),\n });\n expect(wrapper.element).toMatchSnapshot();\n });\n});<\/code><\/pre>\n
\u305d\u306e\u4ed6<\/h3>\n
TypeScript\u306b\u3064\u3044\u3066<\/h2>\n
\/\/ \u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u306e\u4f8b\n\nexport interface RequestState {\n errorMessage: string;\n isFetching: boolean;\n}\nexport interface PaginationState<L, Q> {\n list: Array<L>;\n query: Q;\n currentPage: number;\n totalPage: number;\n totalCount: number;\n}\n\nenum UserRole {\n Admin,\n Editor,\n Subscriber,\n}\nexport interface User {\n id: number;\n name: string;\n role: UserRole;\n groups: Array<Group>;\n}\n\/\/ \u691c\u7d22\u7528\u306e\u30af\u30a8\u30ea\nexport interface UserQuery {\n name: string;\n role: UserRole;\n}\n\n\/\/ \u30e6\u30fc\u30b6\u30fc\u4e00\u89a7\u306eVuex\u30b9\u30c6\u30fc\u30c8\nexport interface UsersState extends RequestState, PaginationState<User, UserQuery> {}\n\n\/\/ \u30eb\u30fc\u30c8\u30b9\u30c6\u30fc\u30c8\nexport interface RootState {\n users: UsersState;\n}<\/code><\/pre>\n
User<\/code>\u306b\u65b0\u305f\u306b\u5c5e\u6027\u3092\u4ed8\u4e0e\u3059\u308b\u5834\u5408\u306a\u3069\u3001\u5f71\u97ff\u7bc4\u56f2\u304c\u898b\u3048\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n
ActionHandler<\/code>\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306b\u306f\u4ee5\u4e0b\u306e
ActionContext<\/code>\u306einterface\u304c\u5272\u308a\u5f53\u3066\u3089\u308c\u3066\u3044\u308b\u306e\u3067\u3001<\/p>\n
export interface ActionContext<S, R> {\n dispatch: Dispatch;\n commit: Commit;\n state: S;\n getters: any;\n rootState: R;\n rootGetters: any;\n}<\/code><\/pre>\n
ActionTree<UsersState, RootState><\/code>\u3092\u6307\u5b9a\u3059\u308b\u3060\u3051\u3067\u3001\u3042\u3068\u306f\u52d8\u3067\u66f8\u3044\u3066\u3044\u3063\u3066\u3082\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002<\/p>\n
import { ActionTree } from 'vuex';\n\nexport const actions: ActionTree<UsersState, RootState> = {\n async getList({ commit, state }) {\b \/\/ \u2190ActionContext\n try {\n commit('request');\n const result = await axios.get(ENDPOINT, { params: state.query });\n commit('success', {\n currentPage: result.data.current_page,\n totalPage: result.data.total_page,\n totalCount: result.data.total_count,\n list: result.data.users \n });\n } catch (e) {\n commit('failure', { errorMessage: e.response.data.errorMessage });\n }\n },\n};<\/code><\/pre>\n
\u307e\u3068\u3081<\/h2>\n
\u53c2\u8003<\/h2>\n
\n