{"id":248,"date":"2016-02-26T12:00:00","date_gmt":"2016-02-26T03:00:00","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2016\/02\/26\/add-unit-test-to-angular"},"modified":"2016-02-26T12:00:00","modified_gmt":"2016-02-26T03:00:00","slug":"add-unit-test-to-angular","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2016\/02\/26\/add-unit-test-to-angular\/","title":{"rendered":"AngularJS 1.x\u7cfb\u306e\u30b7\u30f3\u30b0\u30eb\u30da\u30fc\u30b8\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u5c0e\u5165\u3057\u305f\u8a71"},"content":{"rendered":"
\u6700\u8fd1 \u3055\u3066\u3001\u5148\u65e5\u5f0a\u793e\u516c\u5f0f\u30b5\u30a4\u30c8\u306e\u30a2\u30af\u30bb\u30b9\u30ed\u30b0\u3092\u898b\u3066\u3044\u305f\u6240\u3001 \u203b\u305d\u306e\u969b\u306b\u5f97\u305f\u77e5\u898b\u306f\u3001\u3053\u306e\u30d6\u30ed\u30b0\u3067\u3082\u968f\u6642\u516c\u958b\u3057\u3066\u3044\u307e\u3059<\/p>\n AngularJS\u30bf\u30b0\u306e\u30dd\u30b9\u30c8<\/a> \u73fe\u6642\u70b9\u304b\u3089\u65b0\u898f\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u69cb\u7bc9\u3059\u308b\u306a\u3089\u4eee\u60f3DOM\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u4e57\u3063\u304b\u3063\u3066\u304a\u304f\u306e\u304c\u6642\u6d41\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u304c\u3001\u307e\u3060\u307e\u3060\u4e16\u306e\u4e2d\u306b\u306f \u4eca\u56de\u306f\u3001\u305d\u3093\u306a\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u3057\u3065\u3089\u304f\u306a\u3063\u3066\u3044\u308b \u304c\u3093\u3070\u308a :muscle:<\/p>\n \u307e\u305a\u3069\u3093\u306a\u6a5f\u80fd\u306b\u3064\u3044\u3066\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u66f8\u304d\u305f\u3044\u306e\u304b\u3001\u3068\u3044\u3046\u524d\u63d0\u3092\u66f8\u3044\u3066\u304a\u304d\u307e\u3059\u3002 \u3053\u3093\u306a\u30b3\u30fc\u30c9\u66f8\u304f\u4eba\u3044\u308b...?\u3068\u3044\u3046\u611f\u3058\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c... \u4f8b\u3048\u3070\u6700\u521d\u306f \u6050\u308d\u3057\u3044\u3067\u3059\u306d\u3002<\/p>\n \u3061\u306a\u307f\u306b\u3001\u79c1\u306f\u3053\u3046\u3044\u3046\u30b3\u30fc\u30c9\u3092\u898b\u3066\u3057\u307e\u3063\u305f\u3089\u305d\u306e\u6642\u306b\u76f4\u3057\u3066\u3057\u307e\u3046\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u30bf\u30b9\u30af\u3068\u3057\u3066\u304d\u3063\u3061\u308a\u6642\u9593\u3092\u53d6\u3063\u3066\u6539\u5584\u3057\u3066\u3044\u304f\u3088\u3046\u306b\u3057\u305f\u307b\u3046\u304c\u3044\u3044\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u3002 \u307e\u305a\u3001\u30c6\u30b9\u30c8\u3092\u8ffd\u52a0\u3057\u305f\u3044\u6a5f\u80fd\u3092\u542b\u3080\u4e00\u756a\u5927\u304d\u306a\u5358\u4f4d\u306b\u5bfe\u3057\u3066\u30c6\u30b9\u30c8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002 \u3053\u3053\u306f\u307b\u3068\u3093\u3069 \u30c6\u30b9\u30c8\u304c\u5165\u3063\u3066\u3044\u306a\u3044\u5834\u5408\u3001\u5404\u6a5f\u80fd\u304c\u5bc6\u7d50\u5408\u3057\u3066\u3044\u3066\u5358\u6a5f\u80fd\u3060\u3051\u306e\u30c6\u30b9\u30c8\u3092\u66f8\u304d\u3065\u3089\u3044\u306e\u3067\u3001\u307e\u305a\u306f \u3053\u306e\u6642\u3001\u30c1\u30e3\u30c1\u30e3\u30c3\u3068\u76f4\u3057\u3066\u3057\u307e\u3044\u305f\u3044\u7b87\u6240\u304c\u76ee\u306b\u3064\u304f\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u30b0\u30c3\u3068\u582a\u3048\u307e\u3059\u3002 \u3053\u306e\u6642\u3001 \u305f\u3060\u3057\u5171\u901a\u5316\u3067\u304d\u308b\u51e6\u7406(\u30b9\u30b3\u30fc\u30d7\u30fb\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fb\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u751f\u6210\u306a\u3069)\u306f\u6975\u529b\u5171\u901a\u5316\u3057\u3066\u5c11\u3057\u3067\u3082\u697d\u3092\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u305f\u65b9\u304c\u826f\u3044\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u3002<\/p>\n \u524d\u6bb5\u3067\u4fdd\u8b77\u3057\u305f\u7bc4\u56f2\u306e\u6a5f\u80fd\u3092\u90e8\u54c1\u3068\u3057\u3066\u5207\u308a\u51fa\u3057\u307e\u3059\u3002 \u5207\u308a\u51fa\u3057\u305f\u90e8\u54c1\u3092\u3001\u5143\u306e \u3053\u306e\u6642\u70b9\u3067\u30c6\u30b9\u30c8\u304c\u5931\u6557\u3057\u3066\u3044\u305f\u3089\u3001\u5207\u308a\u51fa\u3057\u305f\u90e8\u54c1\u304c\u4ed5\u69d8\u3092\u6e80\u305f\u3057\u3066\u3044\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u306a\u306e\u3067\u3001\u76f4\u3057\u307e\u3059\u3002 \u6700\u521d\u306b \u305f\u3060\u3057\u3001\u3053\u306e\u5834\u5408 \u3053\u308c\u3067\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u4f5c\u696d\u306f\u5b8c\u4e86\u3067\u3059\uff01<\/p>\n \u5fc5\u9808\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u8ffd\u52a0\u3055\u308c\u305f\uff1f \u9577\u671f\u9593\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u3057\u3066\u3044\u304f\u4e0a\u3067\u3001\u91cd\u8907\u3057\u305f\u8a18\u8ff0\u3084\u975e\u52b9\u7387\u7684\u306a\u66f8\u304d\u65b9\u304c\u51fa\u3066\u304f\u308b\u306e\u306f\u4ed5\u65b9\u304c\u306a\u3044\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002 \u3067\u3059\u306e\u3067\u3001\u66f8\u3044\u305f\u6642\u70b9\u3067\u5b8c\u74a7\u306a\u66f8\u304d\u65b9\u3092\u76ee\u6307\u3059\u3088\u308a\u306f\u3001\u826f\u304f\u306a\u3044\u66f8\u304d\u65b9\u304c\u7d1b\u308c\u8fbc\u3093\u3060\u6642\u30fb\u898b\u3064\u3051\u3066\u3057\u307e\u3063\u305f\u6642\u306b\u6539\u5584\u3059\u308b\u4ed5\u7d44\u307f\u3092\u8d70\u3089\u305b\u3089\u308c\u308b\u304b\u304c\u5927\u4e8b\u306a\u3093\u3058\u3083\u306a\u3044\u304b\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/p>\n \u672c\u5f53\u306fDOM\u306e\u64cd\u4f5c\u3092\u542b\u3080\u6a5f\u80fd\u306e\u30c6\u30b9\u30c8\u306b\u3082\u89e6\u308c\u308b\u3064\u3082\u308a\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u3053\u307e\u3067\u3067\u9577\u304f\u306a\u308a\u3059\u304e\u3066\u5168\u304f\u89e6\u308c\u3089\u308c\u307e\u305b\u3093\u3067\u3057\u305f... \u4eca\u56de\u3054\u7d39\u4ecb\u3057\u305f\u30c6\u30b9\u30c8\u624b\u6cd5\u3092\u53d6\u308a\u5165\u308c\u3001\u54c1\u8cea\u306e\u898b\u3048\u308b\u5316\u3092\u5b9f\u73fe\u3057\u305f\u30b5\u30fc\u30d3\u30b9\u958b\u767a<\/a>\u3092\u3054\u691c\u8a0e\u306e\u4f01\u696d\u69d8\u306f\u3001\u662f\u975eMMM\u306b\u3054\u76f8\u8ac7\u4e0b\u3055\u3044\u307e\u305b\uff01<\/p>\n \u6700\u8fd1Haskell\u306b\u5165\u4fe1\u3057\u305f\u5c0f\u98fc\u3067\u3059\u3002\u5168\u7136\u308f\u304b\u3089\u306a\u304f\u3066\u6700\u9ad8\u3067\u3059\u3002 \u3055\u3066\u3001\u5148\u65e5\u5f0a\u793e\u516c\u5f0f\u30b5\u30a4\u30c8\u306e\u30a2\u30af\u30bb\u30b9\u30ed\u30b0\u3092\u898b\u3066\u3044\u305f\u6240\u3001angularjs \u8acb\u8ca0\u3068\u3044\u3046\u691c\u7d22\u30ef\u30fc\u30c9\u3067\u306e\u6d41\u5165\u304c\u3042\u308a\u307e\u3057\u305f\u3002 \u5f0a\u793e\u3067\u306f\u3001\u3053\u306e\u4e00\u5e74\u3067\u3059\u3063\u304b\u308a\u4e3b\u6d41\u3068\u306a\u3063\u305f\u89b3\u306e\u3042\u308b\u4eee\u60f3DOM\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3088\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u69cb\u7bc9\u306e\u4ed6\u306b\u3001AngularJS\/Vue.js\u306a\u3069\u306eMV*\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u3088\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u69cb\u7bc9\u3082\u624b\u639b\u3051\u3066\u3044\u307e\u3059\u3002 \u203b\u305d\u306e\u969b\u306b\u5f97 […]<\/p>\n","protected":false},"author":1,"featured_media":826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[30,77,166],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/248"}],"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=248"}],"version-history":[{"count":0,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/248\/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=248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}Haskell<\/code>\u306b\u5165\u4fe1\u3057\u305f\u5c0f\u98fc\u3067\u3059\u3002\u5168\u7136\u308f\u304b\u3089\u306a\u304f\u3066\u6700\u9ad8\u3067\u3059\u3002<\/p>\n
angularjs \u8acb\u8ca0<\/code>\u3068\u3044\u3046\u691c\u7d22\u30ef\u30fc\u30c9\u3067\u306e\u6d41\u5165\u304c\u3042\u308a\u307e\u3057\u305f\u3002
\n\u5f0a\u793e\u3067\u306f\u3001\u3053\u306e\u4e00\u5e74\u3067\u3059\u3063\u304b\u308a\u4e3b\u6d41\u3068\u306a\u3063\u305f\u89b3\u306e\u3042\u308b\u4eee\u60f3DOM\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u3088\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u69cb\u7bc9\u306e\u4ed6\u306b\u3001AngularJS<\/code>\/
Vue.js<\/code>\u306a\u3069\u306e
MV*\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af<\/code>\u306b\u3088\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u69cb\u7bc9\u3082\u624b\u639b\u3051\u3066\u3044\u307e\u3059\u3002<\/p>\n
\nVue.js\u30bf\u30b0\u306e\u30dd\u30b9\u30c8<\/a><\/p>\nAngularJS<\/code>\u88fd\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3082\u591a\u304f\u3042\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002
\n\u305d\u306e\u4e2d\u306b\u306f\u300c\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u7acb\u3061\u4e0a\u3052\u6642\u306b\u306f\u4e3b\u6d41\u3060\u3063\u305fAngularJS<\/code>\u304c\u3001\u3059\u3063\u304b\u308a\u6d41\u884c\u308a\u5ec3\u308a\u306e\u6ce2\u306b\u98f2\u307e\u308c\u3066\u3057\u307e\u3063\u3066\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u304c\u3057\u3065\u3089\u304f\u306a\u3063\u3066\u3057\u307e\u3063\u305f...\u300d\u3068\u3044\u3046\u3088\u3046\u306a\u4e8b\u304c\u3042\u308b\u306e\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u3002
\n(\u3082\u3057\u305d\u3046\u3044\u3063\u305f\u65b9\u304c\u3044\u308c\u3070\u305c\u3072\u5f0a\u793e\u306b\u3054\u9023\u7d61\u4e0b\u3055\u3044)<\/p>\nAngularJS<\/code>\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4eee\u5b9a\u3057\u3066\u3001\u7d99\u7d9a\u7684\u306b\u958b\u767a\u3092\u7d9a\u3051\u3066\u3044\u304f\u305f\u3081\u306b\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3092\u5c0e\u5165\u3057\u305f\u969b\u306e\u4e00\u4f8b\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002
\n\u60f3\u5b9a\u3057\u3066\u3044\u308b\u306e\u306f\u3053\u3093\u306a\u69cb\u6210\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n\n
AngularJS<\/code>\u3092\u7528\u3044\u305f\u30b7\u30f3\u30b0\u30eb\u30da\u30fc\u30b8\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3(SPA)<\/li>\n
AngularJS<\/code>\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u307f\u4f7f\u7528\u3057\u3066\u3044\u308b(!CommonJS)<\/li>\n
Controller<\/code>\u304c\u968f\u6240\u306b\u3042\u308b<\/li>\n<\/ul>\n
\u60f3\u5b9a\u3057\u3066\u3044\u308b\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u8981\u4ef6<\/h2>\n
\n\u4f8b\u3048\u3070\u3053\u3093\u306a\u611f\u3058\u3067\u3001\u3042\u308bAPI<\/code>\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u306b\u5bfe\u3057\u3066\u3001
Controller<\/code>\u304c\u5909\u308f\u308b\u6bce\u306b\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u9001\u308b\u6a5f\u80fd\u304c\u3042\u308b\u3068\u3057\u307e\u3059\u3002
\n(\u7701\u7565\u3055\u308c\u3066\u3044\u308b\u90e8\u5206\u306b$routeProvider<\/code>\u306b\u3088\u308b\u30eb\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u3057\u3066\u3044\u308b\u8a18\u8ff0\u304c\u3042\u308a\u3001\u5404\u30da\u30fc\u30b8\u6bce\u306b
Controller<\/code>\u304c\u3042\u308b\u3001\u3068\u3044\u3046\u8a2d\u5b9a\u3067\u3059)<\/p>\n
function sampleResourceWrapper($resource) {\n return $resource('\/api\/endpoint', {\n someParam: '@someParam',\n });\n}\n\nfunction sampleController1(sampleResourceWrapper) {\n const s = new sampleResourceWrapper({ someParam: 'someOwnParam' });\n s.someFixingParam1 = 'someFixingParam1';\n s.someFixingParam2 = 'someFixingParam2';\n s.someFixingParam3 = 'someFixingParam3';\n \/* \u4e2d\u7565 \u6ca2\u5c71\u306e\u56fa\u5b9a\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3057\u3066\u3044\u308b... *\/\n\n s.save().$promise\n .then((response)=> console.log(response));\n}\n\nfunction sampleController2(sampleResourceWrapper) {\n const s = new sampleResourceWrapper({ someParam: 'someOwnParam' });\n s.someFixingParam1 = 'someFixingParam1';\n s.someFixingParam2 = 'someFixingParam2';\n s.someFixingParam3 = 'someFixingParam3';\n \/* \u4e2d\u7565 \u6ca2\u5c71\u306e\u56fa\u5b9a\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3057\u3066\u3044\u308b... *\/\n\n s.save().$promise\n .then((response)=> console.log(response));\n}\n\nangular.module('sampleApp').controller('sampleController1', sampleController1);\nangular.module('sampleApp').controller('sampleController2', sampleController2);\nangular.module('sampleApp').factory('sampleResourceWrapper', sampleResourceWrapper);\n\n\/\/ \u4ee5\u4e0bRouting\u51e6\u7406\u3068\u304b...<\/code><\/pre>\n
\n\u9577\u3044\u958b\u767a\u671f\u9593\u306e\u9593\u306b\u3001\u5c11\u3057\u305a\u3064\u3053\u3046\u3044\u3046\u30b3\u30fc\u30c9\u304c\u6e9c\u307e\u3063\u3066\u3044\u3063\u305f\u3068\u3044\u3046\u3053\u3068\u306b\u3057\u3066\u4e0b\u3055\u3044\u3002<\/p>\nsampleController1<\/code>\u3060\u3051\u3092\u5b9f\u88c5\u3057\u3066\u3044\u305f\u3001\u3042\u308b\u6642\u671f\u306b\u8ffd\u52a0\u306e
sampleController2<\/code>\u304c\u4f5c\u3089\u308c\u305f\u3001\u305d\u306e\u6642\u306b\u6642\u9593\u304c\u7121\u304f\u3066
sampleController1<\/code>\u306e\u5b9f\u88c5\u3092\u30b3\u30d4\u30da\u3057\u305f...(\u4ee5\u4e0b\u7e70\u308a\u8fd4\u3057)
\n\u3068\u3044\u3046\u3088\u3046\u306a\u30b1\u30fc\u30b9\u306f\u5b9f\u969b\u306b\u3042\u308b\u306e\u3067\u306f\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002
\n\u3057\u304b\u3082\u5b9f\u958b\u767a\u74b0\u5883\u3067\u306f\u3001\u3053\u306e\u4ed6\u306b\u4f55\u5341\u3001\u4f55\u767e\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u306e\u3067\u3001\u6b21\u306b\u4e21\u65b9\u306e\u30b3\u30fc\u30c9\u306b\u30c1\u30a7\u30c3\u30af\u30a4\u30f3\u3059\u308b\u307e\u3067\u554f\u984c\u304c\u8868\u9762\u5316\u3057\u3065\u3089\u3044\u3088\u3046\u306b\u601d\u3044\u307e\u3059\u3002
\n\u3053\u306e\u8abf\u5b50\u3067sampleController10<\/code>\u307e\u3067\u5897\u3048\u305f\u5f8c\u306b\u3001\u5fc5\u9808\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3068\u3057\u305f\u3089\u3069\u3046\u306a\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n
\n(\u3053\u306e\u8fba\u306f\u30c1\u30fc\u30e0\u306e\u6027\u683c\u3068\u304b\u69cb\u6210\u306b\u3082\u3088\u308b\u3068\u601d\u3044\u307e\u3059)<\/p>\n\u30c6\u30b9\u30c8\u3067\u5168\u4f53\u306e\u6319\u52d5\u3092\u4fdd\u8b77<\/h2>\n
\n\u4eca\u56de\u60f3\u5b9a\u3057\u3066\u3044\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u3001\u5404\u30da\u30fc\u30b8\u6bce\u306b\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308bController<\/code>\u304c\u6700\u5927\u306e\u5358\u4f4d\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n
E2E<\/code>\u306e\u30c6\u30b9\u30c8\u3092\u66f8\u304f\u3088\u3046\u306a\u30a4\u30e1\u30fc\u30b8\u3067\u3001\u6700\u7d42\u7684\u306b\u3053\u306e\u30da\u30fc\u30b8\u304c\u8cac\u4efb\u3092\u6301\u305f\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u6a5f\u80fd\u306b\u5bfe\u3057\u3066\u30c6\u30b9\u30c8\u3092\u66f8\u304d\u307e\u3059\u3002
\n\u305f\u3060\u3057\u3001\u592a\u308a\u3059\u304e\u305fController<\/code>\u304c\u968f\u6240\u306b\u3042\u308b\u3068\u3044\u3046\u60f3\u5b9a\u3067\u3059\u306e\u3067\u3001\u5168\u3066\u306e\u6a5f\u80fd\u3092\u62c5\u4fdd\u3059\u308b\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u306e\u306f\u73fe\u5b9f\u7684\u3067\u306f\u7121\u3044\u3068\u601d\u3044\u307e\u3059\u3002
\n\u305d\u3053\u3067\u3001\u307e\u305a\u306f\u30e6\u30cb\u30c3\u30c8\u30c6\u30b9\u30c8\u3068\u3057\u3066\u5207\u308a\u51fa\u3057\u305f\u3044\u6a5f\u80fd\u306e\u307f\u306b\u6ce8\u76ee\u3057\u3066\u30c6\u30b9\u30c8\u3092\u66f8\u304d\u307e\u3059\u3002<\/p>\n\u3053\u306e\u6a5f\u80fd\u306f\u4f55\u3092\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u304b<\/code>\u3092
\u3053\u306e\u30da\u30fc\u30b8\u306f\u4f55\u3092\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u304b<\/code>\u306e\u4e2d\u306b\u542b\u3081\u3066\u3057\u307e\u3046\u3001\u3068\u3044\u3046\u30a4\u30e1\u30fc\u30b8\u3067\u3059\u3002<\/p>\n
\n\u307e\u305f\u3001\u4ed6\u306b\u3082\u4e8b\u524d\u306e\u901a\u4fe1\u51e6\u7406\u304c\u5fc5\u8981\u3060\u3063\u305f\u308a\u3001\u30b5\u30fc\u30c9\u30d1\u30fc\u30c6\u30a3\u88fd\u30e9\u30a4\u30d6\u30e9\u30ea(\u30a2\u30ca\u30ea\u30c6\u30a3\u30af\u30b9\u7cfb\u30c4\u30fc\u30eb\u3068\u304b)\u304c\u30ea\u30af\u30a8\u30b9\u30c8\u6295\u3052\u3066\u305f\u308a\u3057\u3066\u3044\u3066\u6ca2\u5c71\u306e\u30e2\u30c3\u30af\u3092\u4f5c\u308b\u5fc5\u8981\u304c\u51fa\u3066\u304f\u308b\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u304c\u3001\u9811\u5f35\u308a\u307e\u3059\u3002
\n(\u30c6\u30b9\u30c8\u3092\u66f8\u3051\u3070\u66f8\u304f\u307b\u3069\u3001\u65b0\u305f\u306b\u5fc5\u8981\u306a\u30e2\u30c3\u30af\u306f\u5c11\u306a\u304f\u306a\u3063\u3066\u3044\u304f\u306e\u3067\u3001\u305d\u306e\u65e5\u3092\u5922\u898b\u3066\u9811\u5f35\u308a\u307e\u3059)<\/p>\ndescribe('Controllers: sampleController1', ()=> {\n var scope, element, httpBackend;\n beforeEach(()=> module('sampleApp', 'httpBackendMock', 'controllerTemplate1.html'));\n beforeEach(()=> {\n inject(($rootScope)=> {\n \/\/ scope\u3092\u4f5c\u3063\u3066\n scope = $rootScope.$new();\n scope.$digest();\n });\n inject(($httpBackend)=> {\n \/\/ $httpBackend\u3078\u306e\u53c2\u7167\u3092\u53d6\u5f97\u3057\u3066\n httpBackend = $httpBackend;\n });\n inject(($compile, $templateCache)=> {\n \/\/ \u63cf\u753b\u3059\u308b\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u751f\u6210\u3057\u3066body\u306b\u9069\u7528\u3057\u3066\n const template = $templateCache.get('controllerTemplate1.html');\n element = $compile(template)(scope);\n document.querySelector('body').appendChild(element);\n });\n inject(($controller)=> {\n \/\/ controller\u3092\u30bb\u30c3\u30c8\u3059\u308b\n $controller('sampleController1', { $element: element });\n scope.$digest();\n });\n });\n\n it('\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u6295\u3052\u3066\u3044\u308b', ()=> {\n httpBackend.expectPOST(\/\/api\/endpoint\/).respond({});\n httpBackend.flush();\n });\n\n it('\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u6e21\u3063\u3066\u3044\u308b', ()=> {\n httpBackend.expectPOST(\/\/api\/endpoint\/, {\n someParam: 'someOwnParam',\n someFixingParam1: 'someFixingParam1',\n someFixingParam2: 'someFixingParam2',\n someFixingParam3: 'someFixingParam3',\n \/\/ ...\n }).respond({});\n httpBackend.flush();\n });\n});\n\ndescribe('Controllers: sampleController2', ()=> {\n var scope, element, httpBackend;\n beforeEach(()=> module('sampleApp', 'httpBackendMock', 'controllerTemplate2.html'));\n beforeEach(()=> {\n inject(($rootScope)=> {\n scope = $rootScope.$new();\n scope.$digest();\n });\n inject(($httpBackend)=> {\n httpBackend = $httpBackend;\n });\n inject(($compile, $templateCache)=> {\n const template = $templateCache.get('controllerTemplate2.html');\n element = $compile(template)(scope);\n document.querySelector('body').appendChild(element);\n });\n inject(($controller)=> {\n \/\/ controller\u3092\u30bb\u30c3\u30c8\u3059\u308b\n $controller('sampleController2', { $element: element });\n scope.$digest();\n });\n });\n\n it('\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u6295\u3052\u3066\u3044\u308b', ()=> {\n httpBackend.expectPOST(\/\/api\/endpoint\/).respond({});\n httpBackend.flush();\n });\n\n it('\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u6e21\u3063\u3066\u3044\u308b', ()=> {\n httpBackend.expectPOST(\/\/api\/endpoint\/, {\n someParam: 'someOwnParam',\n someFixingParam1: 'someFixingParam1',\n someFixingParam2: 'someFixingParam2',\n someFixingParam3: 'someFixingParam3',\n \/\/ ...\n }).respond({});\n httpBackend.flush();\n });\n});<\/code><\/pre>\n
AngularJS unit testing<\/code>\u306a\u3093\u304b\u3067\u691c\u7d22\u3059\u308b\u3068\u3001
whenPOST<\/code>\u3067\u64ec\u4f3c\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8a2d\u5b9a\u3059\u308b\u8a18\u4e8b\u306e\u65b9\u304c\u591a\u304f\u898b\u3064\u304b\u308b\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u3002
\nexpectPOST<\/code>\u306b\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u30011\u56de1\u56de\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u3001\u3069\u3093\u306a\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u767a\u884c\u3055\u308c\u305f\u304b\u304c\u30c6\u30b9\u30c8\u3057\u3084\u3059\u3044\u306e\u3067\u3001\u7279\u306b\u4e8b\u60c5\u304c\u306a\u3051\u308c\u3070
expectPOST<\/code>\u3092\u30aa\u30b9\u30b9\u30e1\u3057\u307e\u3059
\n(\u3082\u3061\u308d\u3093\u4ed6\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u3082\u540c\u69d8\u3067\u3059)<\/p>\nController<\/code>\u306e\u30c6\u30b9\u30c8\u304c\u592a\u308a\u306b\u592a\u3063\u3066\u5927\u5909\u306a\u611f\u3058\u306b\u306a\u308b\u304b\u3082\u77e5\u308c\u307e\u305b\u3093\u3002
\n\u3053\u308c\u306f\u4e00\u6642\u7684\u306a\u3053\u3068\u3067\u3001\u304d\u3061\u3093\u3068\u30c6\u30b9\u30c8\u304c\u6574\u5099\u3055\u308c\u3066\u3044\u304f\u306b\u3064\u308c\u3066\u3001Controller<\/code>\u306e\u30c6\u30b9\u30c8\u3082\u8efd\u304f\u306a\u3063\u3066\u3044\u304f(\u672c\u6765\u306e\u8cac\u52d9\u306b\u5fdc\u3058\u305f\u30b5\u30a4\u30ba\u306b\u306a\u3063\u3066\u3044\u304f)\u306e\u3067\u3001\u8010\u3048\u307e\u3059\u3002<\/p>\n
describe('Controllers: sampleController1', ()=> {\n var scope, element, httpBackend;\n \/\/ `testHelper`\u3068\u3044\u3046\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3001\u305d\u3053\u306b\u30c6\u30b9\u30c8\u7528\u306e\u30d8\u30eb\u30d1\u30fc\u95a2\u6570\u3092\u307e\u3068\u3081\u3066\u3044\u308b\n \/\/ AngularJS\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u307f\u3092\u4f7f\u3063\u3066\u3044\u308b\u60f3\u5b9a\u306a\u306e\u3067\u3001\u5f53\u7136`module.exports`\u3068\u304b\u306f\u3067\u304d\u306a\u3044\n beforeEach(()=> module('sampleApp', 'httpBackendMock', 'testHelper', 'controllerTemplate1.html'));\n beforeEach(()=> {\n inject((\n createScope, createElement, setController,\n $httpBackend\n )=> {\n scope = createScope();\n element = createElement();\n setController('sampleController1', element);\n\n httpBackend = $httpBackend;\n });\n });\n \/\/ ...\n});<\/code><\/pre>\n
\u5207\u308a\u5206\u3051\u308b<\/h2>\n
\n\u4eca\u56de\u306f\u901a\u4fe1\u6a5f\u80fd\u306e\u307f\u306a\u306e\u3067\u3001Factory<\/code>\u3068\u3057\u3066\u5207\u308a\u51fa\u3059\u306e\u304c\u826f\u3055\u305d\u3046\u3067\u3059\u304c\u3001
View<\/code>\u306b\u95a2\u308f\u308b\u90e8\u5206\u3067\u3057\u305f\u3089
Element Directives(Component)<\/code>\u3068\u3057\u3066\u5207\u308a\u51fa\u3059\u3053\u3068\u306b\u306a\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
function sampleResourceWrapper($resource) {\n const baseResource = $resource('\/api\/endpoint', { someParam: '@someParam' });\n\n return (someOwnParam)-> {\n const s = new baseResource({ someParam: someOwnParam });\n s.someFixingParam1 = 'someFixingParam1';\n s.someFixingParam2 = 'someFixingParam2';\n s.someFixingParam3 = 'someFixingParam3';\n \/* \u4e2d\u7565 \u6ca2\u5c71\u306e\u56fa\u5b9a\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u6e21\u3057\u3066\u3044\u308b... *\/\n\n return s.save().$promise;\n };\n}<\/code><\/pre>\n
Controller<\/code>\u306e\u8a72\u5f53\u7b87\u6240\u306b\u5dee\u3057\u66ff\u3048\u307e\u3059\u3002<\/p>\n
function sampleController1(sampleResourceWrapper) {\n sampleResourceWrapper()\n .then((response)=> console.log(response));\n}\n\nfunction sampleController2(sampleResourceWrapper) {\n sampleResourceWrapper()\n .then((response)=> console.log(response));\n}<\/code><\/pre>\n
\n\u30c6\u30b9\u30c8\u304c\u901a\u308c\u3070\u90e8\u54c1\u5316\u306e\u6210\u529f\u3067\u3059\uff01<\/p>\n\u30c6\u30b9\u30c8\u3092\u5207\u308a\u5206\u3051\u308b<\/h2>\n
Controller<\/code>\u306e\u30c6\u30b9\u30c8\u306b\u66f8\u3044\u305f\u30c6\u30b9\u30c8\u3092\u3001
Factory<\/code>\u306e\u30c6\u30b9\u30c8\u3068\u3057\u3066\u5207\u308a\u51fa\u3057\u307e\u3059\u3002<\/p>\n
describe('Factories: sampleResourceWrapper', ()=> {\n var _sampleResourceWrapper, httpBackend;\n beforeEach(()=> module('sampleApp', 'httpBackendMock'));\n beforeEach(()=> {\n inject(($httpBackend, sampleResourceWrapper)=> {\n httpBackend = $httpBackend;\n _sampleResourceWrapper = sampleResourceWrapper;\n });\n });\n\n it('\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u6e21\u3063\u3066\u3044\u308b', ()=> {\n _sampleResourceWrapper({ someParam: 'someOwnParam' });\n httpBackend.expectPOST(\/\/api\/endpoint\/, {\n someParam: 'someOwnParam',\n someFixingParam1: 'someFixingParam1',\n someFixingParam2: 'someFixingParam2',\n someFixingParam3: 'someFixingParam3',\n \/\/ ...\n }).respond({});\n httpBackend.flush();\n });\n});<\/code><\/pre>\n
\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u6295\u3052\u308b\u3053\u3068<\/code>\u305d\u306e\u3082\u306e\u306f
Controller<\/code>\u306e\u8cac\u52d9\u306a\u306e\u3067\u3001
Controller<\/code>\u306e\u30c6\u30b9\u30c8\u3068\u3057\u3066\u6b8b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n
describe('Controllers: sampleController1', ()=> {\n var scope, element, httpBackend;\n beforeEach(()=> module('sampleApp', 'httpBackendMock', 'testHelper', 'controllerTemplate1.html'));\n \/\/ ...\n\n it('\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u6295\u3052\u3066\u3044\u308b', ()=> {\n httpBackend.expectPOST(\/\/api\/endpoint\/).respond({});\n httpBackend.flush();\n });\n \/\/ ...\n});<\/code><\/pre>\n
\u5207\u308a\u51fa\u3057\u305fFactory<\/code>\u306b\u3061\u3087\u3063\u3068\u8ffd\u8a18\u3059\u308b\u3060\u3051\u3067\u826f\u3044\u306e\u3067\u3001\u697d\u52dd\u3067\u3059\u306d\uff01<\/p>\n
\u307e\u3068\u3081<\/h2>\n
\n\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3067\u30d5\u30a3\u30eb\u30bf\u3059\u308b\u4e8b\u304c\u3067\u304d\u308c\u3070\u7406\u60f3\u7684\u3067\u3059\u304c\u3001\u30ec\u30d3\u30e5\u30fc\u306e\u30b9\u30b3\u30fc\u30d7\u5916\u306e\u30b3\u30fc\u30c9\u3068\u91cd\u8907\u3057\u3066\u3044\u305f\u308a\u3057\u3066\u3001\u4e2d\u3005\u767a\u898b\u3057\u3065\u3089\u3044\u306e\u304c\u73fe\u5b9f\u3067\u3059\u3002
\n\u307e\u305f\u3001\u6642\u9593\u306e\u7d4c\u904e\u306b\u3088\u3063\u3066\u975e\u52b9\u7387\u7684\u306a\u66f8\u304d\u65b9\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u66f8\u304d\u65b9\u3068\u3044\u3046\u306e\u3082\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002
\n(\u30c8\u30ec\u30f3\u30c9\u306e\u5909\u5316\u304c\u6fc0\u3057\u3044JavaScript<\/code>\u754c\u9688\u3067\u306f\u306a\u304a\u3055\u3089\u3067\u3059)<\/p>\n
\nDOM\u306b\u307e\u3064\u308f\u308b\u30c6\u30b9\u30c8\u304c\u6574\u5099\u3055\u308c\u3066\u3044\u304f\u3068\u3001\u4f5c\u308a\u305f\u3044\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3060\u3051\u3092\u30c6\u30b9\u30c8\u74b0\u5883\u3067\u63cf\u753b\u3057\u3066\u4f5c\u3063\u3066\u3044\u304f\u3088\u3046\u306a\u3001TDD\u3063\u307d\u3044\u624b\u6cd5\u3067\u958b\u767a\u304c\u3067\u304d\u3066\u6700\u9ad8\u306a\u306e\u3067\u3001\u3044\u305a\u308c\u7d39\u4ecb\u3057\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\u53c2\u8003\u306b\u3057\u305f\u66f8\u7c4d\u3084\u30b3\u30f3\u30c6\u30f3\u30c4<\/h2>\n
\n