├── .gitignore ├── LICENSE ├── README.md ├── app ├── index.html ├── main.js └── styles │ └── main.css ├── bower.json ├── gulpfile.js ├── history.txt ├── karma.conf.js ├── package.json ├── server.js └── test ├── e2e └── app.spec.js ├── index.html ├── main.spec.js └── protractor.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bower_components 3 | test/coverage -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Tuts+ 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [AngularJS for Test-Driven Development][published url] 2 | ## Instructor: [Daniel Stern][instructor url] 3 | 4 | 5 | Angular.js is one of the most widely-used web frameworks today. Part of what makes Angular so amazing is that it is a framework written from the ground up with testing in mind. In this course, we'll take a practical, hands-on approach to using Angular.js to its full testing capabilities. 6 | 7 | You will how to build an app that's effectively tested, how to write effective tests, and we'll take a detailed look at running tests automatically. Automated tests allow us to write code that is more reliable, more effective and easier to maintain. 8 | 9 | In order to test Angular properly, you need to be familiar with a variety of libraries, many from the Angular team. This course will familiarize you with all the testing frameworks you need to know about to test Angular - Mocha, Chai, Protractor, Karma and more. 10 | 11 | ## Source Files Description 12 | 13 | This repository contains an example of an AngularJS app built with running tests in mind. Snapshots of the code as it exists before and after each lesson are also available in named repository branches. 14 | 15 | You can clone this repository and use it as a basis for your app, or use it to learn about Test-Driven Development with Angular. 16 | 17 | ## Usage 18 | 19 | 1. Clone or unzip the Git repository to your workstation. 20 | 2. Install dependencies with `npm install; bower install` 21 | 3. Install Karma dependencies globally with `npm install -g karma karma-cli protractor karma-coverage istanbul webdriver-manager mocha` 22 | 4. Run the application using the instructions in the Gulp section. 23 | 24 | ### Directory Structure 25 | 26 | ``` 27 | /app/ // where our app is 28 | --/scripts/ // location of our app logic 29 | --/index.html 30 | /test/ // tests files 31 | --/coverage/ // generated folder by istanbul 32 | --/e2e/ // end to end tests 33 | --/spec/ // unit tests for app 34 | --/protractor.config.js/ // set up for protractor 35 | --/server.spec.js/ // server unit tests 36 | /karma.conf.js // karma setup 37 | ``` 38 | 39 | ### Gulp Tasks Helper 40 | #### Run tests and serve 41 | To run tests and then serve if the tests pass, run `gulp` (default task) 42 | 43 | #### Generate and Serve Code Coverage Metrics 44 | To generate and then view your code coverage report, run `gulp coverage` 45 | 46 | #### To Serve and debug tests 47 | Tests can be debugged in the browser by serving them with `gulp serve-test` 48 | 49 | #### To run end-to-end tests with protractor 50 | To automatically run Selenium and run your e2e tests, run `gulp protractor` 51 | 52 | #### To run automated browser tests with Karma 53 | To run all unit tests in every configured browser, run `gulp test-browser` 54 | 55 | #### To run all tests one after the other 56 | To run each tests suite without them conflicting, run `gulp test` 57 | 58 | #### To test the Express server 59 | To test the express server, run `gulp test-server` 60 | 61 | #### To serve the app 62 | To serve the app, run `gulp serve` (also runs tests) 63 | 64 | 65 | ## Glossary 66 | 67 | ### Jasmine 68 | > DOM-less simple JavaScript testing framework 69 | 70 | A test runner/assertion/mocking utility combination. 71 | 72 | Use: Run tests, write assertions and mock functionality. 73 | Compare To: Mocha+Chai 74 | 75 | ### Mocha 76 | Just a test runner. Often used in combination with an assertion library (see Assert, Chai) 77 | Compare to: Jasmine 78 | 79 | ### Karma 80 | > The main goal for Karma is to bring a productive testing environment to developers. The environment being one where they don't have to set up loads of configurations, but rather a place where developers can just write the code and get instant feedback from their tests. 81 | 82 | Karma is a browser test runner. 83 | 84 | The idea is that browsers do not have natively a concept of loading tests files, running them, and reporting results. What Karma does is (roughly): 85 | 86 | - Start a small web server to serve "client-side" JavaScript files to be tested (1) 87 | - Also serve the "client-side" JavaScript files with the tests (or Specs, as they're often called) (2) 88 | -serve a custom web page that will run JavaScript code for the tests (3) 89 | - Start a browser to load this page (4) 90 | - Report the results of the test to the server (5) 91 | 92 | Karma can then report the results to text files, the console or anything your CI server likes. 93 | 94 | Use: Karma can be used to run your tests in browsers. If your tests are simple JavaScript that would run the same in Node as in Chrome, this is not necessary, but if you wish to support Firefox, Chrome, IE, et al, in your tests, Karma lets you do it, via a configuration file. 95 | 96 | ### Gulp 97 | Use: Automate tasks. 98 | Environment: Command Line / JavaScript 99 | Compare to: Grunt, Broccoli 100 | 101 | ### gulp-karma 102 | Use: Simplify automation of running Karma in Gulp 103 | Environment: `require` this library in a gulpfile 104 | Compare to: gulp-jasmine 105 | 106 | ### Supertest 107 | A framework specifically for running tests on servers created by Express or similar APIs. 108 | Use: Require supertest in your test script and have it run tests on your Server script 109 | Compare to: Request.js 110 | 111 | ### Istanbul 112 | A tool for measuring how much of your code has tests covering it. 113 | 114 | 115 | ### angular 116 | MVC Framework. 117 | Use: Build single-page apps or augment static apps 118 | Compare to: Ember, React 119 | 120 | ### angular-mocks 121 | A library necessary to run tests on your angular app. Has an e2e version that can only be run on the backend. 122 | Use: Include the script on your page to gain access to `inject` and `module` 123 | 124 | ### protractor 125 | A library for running end-to-end tests on angular apps. protractor uses selenium/webdriver, which are two big words. 126 | Use: Test high level functionality like database interaction and navigation 127 | 128 | ### Chai 129 | Assertion framework. Allows assertions to be written in `expect.to.be` form. Adds additional assertions to `assert` library. 130 | Use: Write assertions in a descriptive way 131 | Compare to: assert 132 | 133 | ### assert 134 | A library built in to Node that can run certain assertions. 135 | Use: Use to write tests that can throw errors if code returns unexpected results. 136 | Compare to: Chai 137 | 138 | ------ 139 | 140 | These are source files for the Tuts+ course: [AngularJS for Test-Driven Development][published url] 141 | 142 | Available on [Tuts+](https://tutsplus.com). Teaching skills to millions worldwide. 143 | 144 | [published url]: https://code.tutsplus.com/courses/angularjs-for-test-driven-development 145 | [instructor url]: https://tutsplus.com/authors/daniel-stern 146 | -------------------------------------------------------------------------------- /app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | The Ironclad Address Book 7 | 8 | 9 | 10 |
11 |

12 | Contactical 13 |

14 |

15 | The Ironclad Address Book 16 |

17 |
18 |
19 |
20 |

21 | 22 | {{contact.name | proper}} 23 | 24 | 25 |

26 |

27 | {{contact.occupation}} 28 |

29 |

30 | 31 | {{contact.email}} 32 | 33 |

34 |
35 |
36 |
37 |
38 |

Add A New Contact

39 | 43 | 47 | 51 | 55 | 59 |
Please check the information and try again.
60 |
61 |
62 | 63 | 64 | -------------------------------------------------------------------------------- /app/main.js: -------------------------------------------------------------------------------- 1 | angular.module("AddressBook",[]) 2 | .service("contactService",function($http){ 3 | this.contacts = []; 4 | var contactService = this; 5 | console.log("contacts init."); 6 | $http.get("http://localhost:9001/contacts") 7 | .then(function(res){ 8 | console.log(res); 9 | while (res.data[0]){ 10 | contactService.contacts.push(res.data.pop()); 11 | } 12 | }); 13 | 14 | this.addContact =function(contact){ 15 | contactService.contacts.push(contact); 16 | } 17 | }) 18 | .controller("ContactController",function(contactService,$scope){ 19 | $scope.contacts = contactService.contacts; 20 | }) 21 | .filter("proper",function(){ 22 | return function(name){ 23 | var type = typeof name; 24 | if (type !== 'number' && type !== 'string') throw new Error(); 25 | return name.toString().split(" ").map(function(word){ 26 | return word[0].toUpperCase().concat(word.slice(1)); 27 | }).join(" "); 28 | } 29 | }) 30 | .directive("avatar",function(){ 31 | return { 32 | restrict:"AE", 33 | scope:{ 34 | name:"=", 35 | }, 36 | template:"{{name[0] | proper}}" 37 | } 38 | }) 39 | .controller('AddContact',function($scope,contactService){ 40 | $scope.addContact = function(){ 41 | contactService.addContact($scope.contact); 42 | }; 43 | }) -------------------------------------------------------------------------------- /app/styles/main.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-family: roboto, monospace, sans-serif; 3 | } 4 | 5 | body { 6 | margin: 64px; 7 | background-color: #346656; 8 | } 9 | 10 | h1 { 11 | font-size: 50px; 12 | margin-bottom: 0px; 13 | } 14 | 15 | h1,h2 { 16 | color: #f3f3f3; 17 | } 18 | 19 | h3 { 20 | margin-bottom: 40px; 21 | } 22 | 23 | a { 24 | color: #346656; 25 | } 26 | 27 | .inline-module { 28 | background-color: #f9f9f9; 29 | min-height:520px; 30 | width:300px; 31 | float: left; 32 | margin: px 24px; 33 | border: 1px solid #ccc; 34 | border-bottom: 2px solid #999; 35 | padding: 12px 36px; 36 | border-radius: 4px; 37 | } 38 | 39 | .inline-module:nth-child(1) { 40 | margin-left:0px; 41 | } 42 | 43 | input { 44 | padding: 6px; 45 | border: 1px solid #ccc; 46 | border-bottom: 2px solid #ccc; 47 | border-radius:3px; 48 | margin-top: -5px; 49 | float: right; 50 | } 51 | 52 | 53 | label { 54 | display: block; 55 | margin: 25px 0px; 56 | } 57 | 58 | input { 59 | 60 | } 61 | 62 | avatar span { 63 | padding: 4px 5px; 64 | margin: 0px 12px; 65 | border: 1px solid #999; 66 | border-bottom: 2px solid #999; 67 | color: white; 68 | background-color: #de1283; 69 | } 70 | 71 | .warning { 72 | border: 1px solid #aaa; 73 | border-bottom: 2px solid #ccc; 74 | padding: 12px; 75 | text-align: center; 76 | background-color: #ffeeee; 77 | } -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-tdd-demo", 3 | "version": "0.0.0", 4 | "homepage": "https://github.com/danielstern/angular-tdd-exemplar", 5 | "authors": [ 6 | "Daniel Stern " 7 | ], 8 | "license": "MIT", 9 | "ignore": [ 10 | "**/.*", 11 | "node_modules", 12 | "bower_components", 13 | "test", 14 | "tests" 15 | ], 16 | "dependencies": { 17 | "angular": "~1.4.0", 18 | "mocha": "~2.2.5", 19 | "chai": "~2.3.0", 20 | "angular-mocks": "~1.4.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var browserSync = require('browser-sync'); 3 | var karma = require('karma').server; 4 | var server = require('gulp-live-server'); 5 | var protractor = require('gulp-protractor').protractor; 6 | 7 | gulp.task('server',function(){ 8 | var live = new server('server.js'); 9 | live.start(); 10 | }) 11 | 12 | gulp.task('serve',['server'],function(){ 13 | return browserSync.init({ 14 | notify:false, 15 | port:8080, 16 | server:{ 17 | baseDir:["app"], 18 | routes:{ 19 | '/bower_components':'bower_components' 20 | } 21 | } 22 | }) 23 | 24 | gulp.watch(['app/**/*.*']) 25 | .on('change',browserSync.reload); 26 | }); 27 | 28 | gulp.task('test-browser',function(done){ 29 | karma.start({ 30 | configFile: __dirname + '/karma.conf.js', 31 | singleRun: true, 32 | reporters:['mocha','coverage'] 33 | },function(){ 34 | done(); 35 | }) 36 | }) 37 | 38 | gulp.task('serve-coverage',['test-browser'],function(){ 39 | browserSync.init({ 40 | notify:false, 41 | port:7777, 42 | server:{ 43 | baseDir:["test/coverage"] 44 | } 45 | }) 46 | 47 | gulp.watch(['app/**/*.*']) 48 | .on('change',browserSync.reload); 49 | }) 50 | 51 | gulp.task('serve-test',function(){ 52 | browserSync.init({ 53 | notify:false, 54 | port:8081, 55 | server:{ 56 | baseDir:["test","app"], 57 | routes:{ 58 | '/bower_components':'bower_components' 59 | } 60 | } 61 | }) 62 | 63 | gulp.watch(['app/**/*.*']) 64 | .on('change',browserSync.reload); 65 | }) 66 | 67 | gulp.task("protractor",['serve'],function(done){ 68 | gulp.src(['test/e2e/*.js']) 69 | .pipe(protractor({ 70 | configFile: "test/protractor.config.js", 71 | args:['--baseUrl','http://localhost:8000'] 72 | })) 73 | .on('end',done); 74 | }) -------------------------------------------------------------------------------- /history.txt: -------------------------------------------------------------------------------- 1 | commit 648d6bd5da86fe96117d7e8a5fd65ce07edcda53 2 | Author: Daniel Stern 3 | Date: Fri Jun 5 08:04:50 2015 -0400 4 | 5 | course complete 6 | 7 | commit 1c1655c4e80122817220b7aa59293923d49c13dd 8 | Author: Daniel Stern 9 | Date: Thu Jun 4 13:43:45 2015 -0400 10 | 11 | end of code coverage chapter 12 | 13 | commit ef2ef17b60d5b491b2b1b0ea193c2c02ac90f560 14 | Author: Daniel Stern 15 | Date: Thu Jun 4 08:35:59 2015 -0400 16 | 17 | end implement istanbul text server 18 | 19 | commit d4e62fed1b1c7f24528e4071b27502b564110616 20 | Author: Daniel Stern 21 | Date: Thu Jun 4 08:02:48 2015 -0400 22 | 23 | end test directive 24 | 25 | commit 1c68d6bfdbf8a6326e17eb1d651f866fea3f184e 26 | Author: Daniel Stern 27 | Date: Wed Jun 3 08:20:05 2015 -0400 28 | 29 | end test filters 30 | 31 | commit 7db45acfa4481c1158cba5849fc142e4d0d66b1b 32 | Author: Daniel Stern 33 | Date: Wed Jun 3 08:02:16 2015 -0400 34 | 35 | finish testing contollers 36 | 37 | commit 2cf51b58365f6eeb27eaf189375aa20662927c6c 38 | Author: Daniel Stern 39 | Date: Wed Jun 3 07:43:56 2015 -0400 40 | 41 | end lesson on httpbackend 42 | 43 | commit a3ba11d6d96fcf227ce041677022b2081dddd931 44 | Author: Daniel Stern 45 | Date: Wed Jun 3 07:34:20 2015 -0400 46 | 47 | end lesson on module on inject 48 | 49 | commit f4cc1a7a20a53fffd3dd91c02909ffd809bd566e 50 | Author: Daniel Stern 51 | Date: Tue Jun 2 07:29:11 2015 -0400 52 | 53 | end-lesson-4 54 | 55 | commit 0189cecd06b3f5498b11387668a70ff5fc72c27f 56 | Author: Daniel Stern 57 | Date: Tue Jun 2 07:17:40 2015 -0400 58 | 59 | end lesson 3 60 | 61 | commit d915e96efa7bc7bf4939e6693cfdca2efc15cb4e 62 | Author: Daniel Stern 63 | Date: Tue Jun 2 06:44:50 2015 -0400 64 | 65 | end lesson 2 66 | 67 | commit 47647593b0fa369a0198374b93e663572d47fe75 68 | Author: Daniel Stern 69 | Date: Tue Jun 2 06:17:11 2015 -0400 70 | 71 | finish lesson one 72 | 73 | commit c4eebd63d04de7d2f3e14a30a01f77939811d728 74 | Author: Daniel Stern 75 | Date: Wed Apr 1 05:55:41 2015 -0400 76 | 77 | removed all finished files 78 | 79 | commit 5d0dc8077ec637d682e289ca6c769d8ae36c2f0c 80 | Author: Daniel Stern 81 | Date: Tue May 19 10:17:19 2015 -0400 82 | 83 | Fixed bug in contact controller. Added additional styles. styles are very good now. 84 | 85 | commit 84f9886affb160af4b16774443fe1d27566547cc 86 | Author: Daniel Stern 87 | Date: Tue May 19 10:09:08 2015 -0400 88 | 89 | styles comin along. fixed bug in gulpfile. 90 | 91 | commit aeba1405f1e6552272461d81390767673ba709c8 92 | Author: Daniel Stern 93 | Date: Tue May 19 09:51:35 2015 -0400 94 | 95 | Added additional styles. Lookin good :facepunch: 96 | 97 | commit 9f0c400ec04fff13c122b4002c32bf8b9c01b2d8 98 | Author: Daniel Stern 99 | Date: Tue May 19 09:12:07 2015 -0400 100 | 101 | Fixed a few more dependencies that could cause tests to fail. 102 | 103 | commit b352b913828ad83dd5f54ff5ef1fbf259d2c8283 104 | Author: Daniel Stern 105 | Date: Tue May 19 09:08:33 2015 -0400 106 | 107 | Fixed test over. The listener on 3000 was not being closed. 108 | 109 | commit d8866dd1de850f6603b8c02b06e61fb0031facbb 110 | Author: Daniel Stern 111 | Date: Mon May 18 20:33:06 2015 -0400 112 | 113 | Add protractor to test task. Renamed coverage to serve-coverage. 114 | 115 | commit 5f224222544633820057efbfd5bc32855ec3e5d4 116 | Author: Daniel Stern 117 | Date: Mon May 18 20:30:40 2015 -0400 118 | 119 | got protractor to exit with process exit 120 | 121 | commit 654193de13dac66046c3716422423205635f4b3d 122 | Author: Daniel Stern 123 | Date: Mon May 18 20:28:15 2015 -0400 124 | 125 | tests work. doesnt auto close but oh well. 126 | 127 | commit a586801f14b03933e6708cf8ee39138dbf7ca619 128 | Author: Daniel Stern 129 | Date: Mon May 18 20:14:51 2015 -0400 130 | 131 | Fixed bug in code revealed thanks to E2E tests. :100:. cleaned up gulp file. currently trying to get gulp to exit correctly. selenium server is not closing. 132 | 133 | commit cbd0f00c2d491485872a38802e3b63367d0148ff 134 | Author: Daniel Stern 135 | Date: Mon May 18 20:07:00 2015 -0400 136 | 137 | protractor tests working. adding refinements. 138 | 139 | commit 35d2079e4bda014140c46227ba918778e364c2ad 140 | Author: Daniel Stern 141 | Date: Mon May 18 19:58:50 2015 -0400 142 | 143 | adding protractor tests. working on it but its slow stuff. 144 | 145 | commit fbb6e69cd53891b43c359256e6089923fbd84e75 146 | Author: Daniel Stern 147 | Date: Mon May 18 19:32:47 2015 -0400 148 | 149 | developing end to end tests. cleaned up cruft from addcontact. tests let us do this! 150 | 151 | commit 61f670325758166a0b5cc4e8d130fa65cbda8418 152 | Author: Daniel Stern 153 | Date: Mon May 18 19:11:49 2015 -0400 154 | 155 | Added various dependencies. Installed protractor. Also installed selenium with manual command line input detailed in new snippets file. include copied spec from example. created working config file. 156 | 157 | commit c314e61af212dc538502fae56ab7ca3b97cf54d8 158 | Author: Daniel Stern 159 | Date: Mon May 18 18:16:40 2015 -0400 160 | 161 | Added gulp coverage for displaying code coverage with Istanbul! 162 | 163 | commit 4204fabf309dbeadca26496afdc53a786626458b 164 | Author: Daniel Stern 165 | Date: Mon May 18 18:14:37 2015 -0400 166 | 167 | not workin 168 | 169 | commit b55f4f41703636076306a4e860f6af19f9d34cff 170 | Author: Daniel Stern 171 | Date: Mon May 18 17:42:27 2015 -0400 172 | 173 | Fix subdirectory for coverage to allow for serve-test. Cleaner coverage directory. 174 | 175 | commit 887871f982d31729e1ad8d58487121992177cce7 176 | Author: Daniel Stern 177 | Date: Mon May 18 17:40:44 2015 -0400 178 | 179 | Add coverage to Gitignore. It is not nececessary to commit it to the directory. 180 | 181 | commit 7e5c320c5f7d8086acad94fbcdcda9686d06231e 182 | Author: Daniel Stern 183 | Date: Mon May 18 17:39:15 2015 -0400 184 | 185 | remove cvrg folder 186 | 187 | commit 58086d60383b7bbb306f0de1bd0eabecd501cdb4 188 | Author: Daniel Stern 189 | Date: Mon May 18 17:38:14 2015 -0400 190 | 191 | Made two coverage reporters. 192 | 193 | commit aed789c08a3bfb76d01e52689fd7767614173473 194 | Author: Daniel Stern 195 | Date: Mon May 18 17:32:04 2015 -0400 196 | 197 | created coverage directory. coverage works. 198 | 199 | commit 28bbb416bf50fb0d8f7342efceccd9949906aa1a 200 | Author: Daniel Stern 201 | Date: Mon May 18 17:25:38 2015 -0400 202 | 203 | CODE COVERAGE!!! ... has been implemented using Istanbul. It is important to set the settings for karma in gulpfile as they override karmafile 204 | 205 | commit 5e8c7c98b8b90a42435263cc735eb33644844f1f 206 | Author: Daniel Stern 207 | Date: Mon May 18 17:13:24 2015 -0400 208 | 209 | gulp throwing format error 210 | 211 | commit b0bbf19d9447a20284419755debe39e26a3eeee2 212 | Author: Daniel Stern 213 | Date: Mon May 18 16:58:55 2015 -0400 214 | 215 | simplify control test 216 | 217 | commit 85dce088b44b940df4ea8c7d58cdaab456949015 218 | Author: Daniel Stern 219 | Date: Mon May 18 16:57:46 2015 -0400 220 | 221 | broke tests into smaller files. 222 | 223 | commit 7e83eaf1e44b41e5b0c06f9b1eaaa3b49452f9d5 224 | Author: Daniel Stern 225 | Date: Mon May 18 14:26:15 2015 -0400 226 | 227 | cleaning up contact service 228 | 229 | commit 0979322bca6fd8777ab21c7888cd518e5856056a 230 | Author: Daniel Stern 231 | Date: Mon May 18 14:19:43 2015 -0400 232 | 233 | tests working. 234 | 235 | commit 4e1bd6f5ffec327eb88e1542ef32ab73a174ebf6 236 | Author: Daniel Stern 237 | Date: Mon May 18 14:10:02 2015 -0400 238 | 239 | broke up some code! 240 | 241 | commit ba5d0b827bd5bed7684db2ae80b65162327348c0 242 | Author: Daniel Stern 243 | Date: Mon May 18 14:04:42 2015 -0400 244 | 245 | wip 246 | 247 | commit 0269f4339c1cb7e8e5d3640f06e3bff782d4570a 248 | Author: Daniel Stern 249 | Date: Mon May 18 14:04:31 2015 -0400 250 | 251 | wip 252 | 253 | commit d1bb0075449233fbea9d77e325ef0f3631e38d60 254 | Author: Daniel Stern 255 | Date: Mon May 18 11:37:04 2015 -0400 256 | 257 | update test spec 258 | 259 | commit c0661ce731408b88e86e18b758b060942983f138 260 | Author: Daniel Stern 261 | Date: Mon May 18 11:32:25 2015 -0400 262 | 263 | Added second unit test and cleaned up directive. Directive is well tested!! 264 | 265 | commit 26c6be207533cb0bb6588f581267c05f345868cf 266 | Author: Daniel Stern 267 | Date: Mon May 18 11:29:17 2015 -0400 268 | 269 | WIP: Got the directive test working! 270 | 271 | commit 4062e2c3facd9440b73f8c24dcf19b9faa5834fa 272 | Author: Daniel Stern 273 | Date: Mon May 18 10:56:37 2015 -0400 274 | 275 | Added additional tests for an ironclad filter. 276 | 277 | commit 08489f2cf9b56d0249fd0354f61e3d53ac53e898 278 | Author: Daniel Stern 279 | Date: Mon May 18 10:37:50 2015 -0400 280 | 281 | Added an implemented a simple filter. 282 | 283 | commit b4070b0df97a7d7ef7b81a0fd40210d34f47194d 284 | Author: Daniel Stern 285 | Date: Mon May 18 10:31:08 2015 -0400 286 | 287 | Added simple Avatar directive. Now this project has directives, services, modules and controllers. Not bad! 288 | 289 | commit b1e84cf93cac19c7fa0e2a77b78f0a9f46d93d24 290 | Author: Daniel Stern 291 | Date: Mon May 18 10:21:59 2015 -0400 292 | 293 | Correct some tests. 294 | 295 | commit ac0f956f4a2a89e590c8441cd877340729a12adf 296 | Author: Daniel Stern 297 | Date: Mon May 18 09:57:30 2015 -0400 298 | 299 | cleaned up some things 300 | 301 | commit 79733d95305c525fc7313a3ef3216c1673a1feb4 302 | Author: Daniel Stern 303 | Date: Mon May 18 09:49:31 2015 -0400 304 | 305 | update contact list logic to prevent bug. 306 | 307 | commit 4b97fdb0b8a6438552b502483324f931f3075944 308 | Author: Daniel Stern 309 | Date: Mon May 18 09:44:01 2015 -0400 310 | 311 | Added additional test. Fix bug in app. 312 | 313 | commit 5796ac81dd91f261bbd33a9826eef2a19c664896 314 | Author: Daniel Stern 315 | Date: Sun May 17 19:51:12 2015 -0400 316 | 317 | added additional test for add contact 318 | 319 | commit 615c8b41788d0a035136fdc4b0490a1f28e471f3 320 | Author: Daniel Stern 321 | Date: Sun May 17 19:37:03 2015 -0400 322 | 323 | added error handling for add contact 324 | 325 | commit 1895187724050854ffc6a4d2a030ed7bc80a9616 326 | Author: Daniel Stern 327 | Date: Sun May 17 15:59:26 2015 -0400 328 | 329 | Completed tests and test spec for adding contacts. Works nicely. Tests are cool. 330 | 331 | commit 32109071b5a6b94ae7bbce8daa9022277fa1401e 332 | Author: Daniel Stern 333 | Date: Sun May 17 15:46:51 2015 -0400 334 | 335 | Added a get single contact route and tests. Tests really help you develop backend code since it is harder to debug than front end code. 336 | 337 | commit a15d0f294f532464eb7b05bd1ab208c21f0c7bd8 338 | Author: Daniel Stern 339 | Date: Sun May 17 15:36:22 2015 -0400 340 | 341 | Added second express test. Look at me! I'm writing Express tests! Yeehaw! :facepunch: 342 | 343 | commit e8d6f5313af8a04806a996e04387281fcac95678 344 | Author: Daniel Stern 345 | Date: Sun May 17 15:21:30 2015 -0400 346 | 347 | Added a test for Post using Cors and Supertest. 348 | 349 | commit c1bfaa614377b304740055847d26289ae53542fc 350 | Author: Daniel Stern 351 | Date: Sun May 17 14:28:13 2015 -0400 352 | 353 | i am fairly optimistic at this point. 354 | 355 | commit fb8959a4e32dbd91df31da903f30197473a84a82 356 | Author: Daniel Stern 357 | Date: Sun May 17 14:15:09 2015 -0400 358 | 359 | cleanup 360 | 361 | commit 41af20594397b35762a402e7975c3785a738d716 362 | Author: Daniel Stern 363 | Date: Sun May 17 14:12:28 2015 -0400 364 | 365 | moved validation to another file and spec 366 | 367 | commit c357277634ae7556cd2cf1b191e820c589e46358 368 | Author: Daniel Stern 369 | Date: Sun May 17 12:04:57 2015 -0400 370 | 371 | Converted validation into isomorphic module. 372 | 373 | commit 519a6b499e62576d89b47e7ccda9508ff01f9103 374 | Author: Daniel Stern 375 | Date: Sun May 17 12:01:50 2015 -0400 376 | 377 | externalized validation for isomorphism 378 | 379 | commit 1c0d7d6bcf39ac042caf657bd9ace504258144ca 380 | Author: Daniel Stern 381 | Date: Sun May 17 11:39:54 2015 -0400 382 | 383 | Wrote some tests FIRST! This is an example of very practical TDD, where the server has complex requirements that you do not want to mix up. 384 | 385 | commit 9def1b30dcc4705bf57aa6a16ad949ee7117fa6d 386 | Author: Daniel Stern 387 | Date: Sun May 17 11:29:02 2015 -0400 388 | 389 | Transplanted a test from app spec to server spec. 390 | 391 | commit 74a903b09add427d52685741b36e4d8bb3f850b6 392 | Author: Daniel Stern 393 | Date: Sun May 17 11:19:14 2015 -0400 394 | 395 | clean up gulpfile 396 | 397 | commit 679eef64d4b8a7b3d366c74de7bdbfd9117d501f 398 | Author: Daniel Stern 399 | Date: Sun May 17 11:16:05 2015 -0400 400 | 401 | add some smaple test questions 402 | 403 | commit 80b7728e3e86933d17c4b1f095fc5740b80ae99c 404 | Author: Daniel Stern 405 | Date: Sun May 17 11:14:47 2015 -0400 406 | 407 | gulp test spec complete. all tests exit properly and are nicely formatted. quite some good stuff here! 408 | 409 | commit 095c1eb97bea97bd2e909eb499e68426ae63c204 410 | Author: Daniel Stern 411 | Date: Sun May 17 10:55:03 2015 -0400 412 | 413 | updated gulp file to use better reporters. added extra dependencies. 414 | 415 | commit bc976e43003707072d1fec39187f594f0e4458ad 416 | Author: Daniel Stern 417 | Date: Sun May 17 10:34:47 2015 -0400 418 | 419 | implemented first test using supertest and node modules 420 | 421 | commit 889241e14386f1f9954a7f04fc47736f2c815606 422 | Author: Daniel Stern 423 | Date: Sun May 17 09:55:11 2015 -0400 424 | 425 | Added additional gulp tasks to facilitate server testing. 426 | 427 | commit 8c864652c940baf0a45f5c4d5c34999dfb701016 428 | Author: Daniel Stern 429 | Date: Sun May 17 09:15:15 2015 -0400 430 | 431 | Change test style to not use backend. Add some more scaffolding for adding contacts. Could using a real DB make sense here, or maybe omit the DB altogether, front end testing providing a very rich grounds for tutorial material as it is? 432 | 433 | commit 0e83d2576c59aca613565cb0f8a291acfa40f2b2 434 | Author: Daniel Stern 435 | Date: Sun May 17 08:49:35 2015 -0400 436 | 437 | Added interface to add a new contact. 438 | 439 | commit 69ad2f0e1d51b8debbb5bc2a7af31b02a2baa4d9 440 | Author: Daniel Stern 441 | Date: Sun May 17 08:41:24 2015 -0400 442 | 443 | update readme 444 | 445 | commit eae4a6da2a7aaa57ac585468a68d05bf85269c63 446 | Author: Daniel Stern 447 | Date: Sun May 17 08:38:58 2015 -0400 448 | 449 | added email validators, and temporary removed code that validates db data 450 | 451 | commit d940d717ddacd74cc272fbce15c7ddde18529f29 452 | Author: Daniel Stern 453 | Date: Sun May 17 08:32:31 2015 -0400 454 | 455 | wrote age tests 456 | 457 | commit af5cb22a1a22b5659ba926972f534a356ff4be7f 458 | Author: Daniel Stern 459 | Date: Sun May 17 08:18:24 2015 -0400 460 | 461 | add rest of validation functions 462 | 463 | commit b06e3d68c15d2132a63c854c68df8f7afa59a4d7 464 | Author: Daniel Stern 465 | Date: Sat May 16 22:52:33 2015 -0400 466 | 467 | update readme 468 | 469 | commit 159b6c01a0debb70d4dfc41adbb79d8f965da77a 470 | Author: Daniel Stern 471 | Date: Sat May 16 22:50:54 2015 -0400 472 | 473 | refactored validation logic and validation testing logic. 474 | 475 | commit 280364fb64935dd3fbeb00eaf5f08ae7bd5cd745 476 | Author: Daniel Stern 477 | Date: Sat May 16 22:43:41 2015 -0400 478 | 479 | add 1.5 testing with jquery! yeah 480 | 481 | commit 35522ad016ae2e4439c7d898d2c5f66e8c5c52ea 482 | Author: Daniel Stern 483 | Date: Sat May 16 22:30:16 2015 -0400 484 | 485 | fix all tests by going with non e2e mocks. e2e mocks are for backend use. 486 | 487 | commit a622960d6186dbc7d2a1fc926149f3a2c08850b4 488 | Author: Daniel Stern 489 | Date: Sat May 16 22:09:24 2015 -0400 490 | 491 | sigh 492 | 493 | commit e2cbce21178ce63c97d6387691a9703c4dfe2c4d 494 | Author: Daniel Stern 495 | Date: Sat May 16 21:49:41 2015 -0400 496 | 497 | add tests for the name validator with not ok, false and ok 498 | 499 | commit 978cce746534a4399957260a3fef20f3f7c79b50 500 | Author: Daniel Stern 501 | Date: Sat May 16 21:41:50 2015 -0400 502 | 503 | add some scaffolding for validation. 504 | 505 | commit 98909a3500bb6e61c5dcc3964b7bd4c092f4d11c 506 | Author: Daniel Stern 507 | Date: Sat May 16 20:36:06 2015 -0400 508 | 509 | Add tests for validation helper. 510 | 511 | commit de9ffe9c066e6382651ae54cf92766f715371bec 512 | Author: Daniel Stern 513 | Date: Sat May 16 20:29:34 2015 -0400 514 | 515 | added another test for the validation helper. commented out the controller test since it was actually failing, and i am not sure how to get it to pass just quite yet. 516 | 517 | commit 4524967f4399f8b5093cda744517523b7f699de0 518 | Author: Daniel Stern 519 | Date: Sat May 16 20:22:47 2015 -0400 520 | 521 | more scaffold thar 522 | 523 | commit cd1e40966ce144d72caeeb1612aa7e37d8fb965e 524 | Author: Daniel Stern 525 | Date: Sat May 16 20:19:34 2015 -0400 526 | 527 | Scaffold adding a new contact. 528 | 529 | commit 53e39998376e89c64407919541573c3625164252 530 | Author: Daniel Stern 531 | Date: Sat May 16 19:44:17 2015 -0400 532 | 533 | Replaced mocks with e2e. works for some inexplicable reason. best not to call flush with e2e? I really do not know. 534 | 535 | commit fda0db8f944ffcf5019672d3164558ae41c6d03d 536 | Author: Daniel Stern 537 | Date: Sat May 16 19:41:17 2015 -0400 538 | 539 | interesting 540 | 541 | commit b54441a3b33026a45f0d411d0488898d095eb336 542 | Author: Daniel Stern 543 | Date: Sat May 16 19:35:40 2015 -0400 544 | 545 | Implemented asynchroncity using httpBackened and ngMocks. 546 | 547 | commit 5b5c146b63009f7cdface9a0f3894e5fb5039719 548 | Author: Daniel Stern 549 | Date: Sat May 16 19:02:24 2015 -0400 550 | 551 | Work through difficulties with angular-mock e2e being buggy.' 552 | 553 | commit e1f9817258c86fb86cf0ca6a649140744560c1f2 554 | Author: Daniel Stern 555 | Date: Sat May 16 18:41:14 2015 -0400 556 | 557 | workin on it 558 | 559 | commit 4728e7105865c4d9a338884aa98a08f2c40dbe05 560 | Author: Daniel Stern 561 | Date: Sat May 16 12:10:47 2015 -0400 562 | 563 | using serve-test to troubleshoot my tests 564 | 565 | commit 0615760d1254a6a8936a53412e5e54d55abdf30a 566 | Author: Daniel Stern 567 | Date: Sat May 16 11:29:53 2015 -0400 568 | 569 | Go asynchronous and notice our tests fail. 570 | 571 | commit c924badfe54ab58fc51024430147a1854950f1a4 572 | Author: Daniel Stern 573 | Date: Sat May 16 11:24:17 2015 -0400 574 | 575 | Create DB file with Data for async demonstration purposes. Modified gulpfile to refresh on server reload (retroactive). Modify server.js to do simple synchronous file read. 576 | 577 | commit fd1f7285df0c185be8596c8a4634dc69663222eb 578 | Author: Daniel Stern 579 | Date: Sat May 16 11:00:04 2015 -0400 580 | 581 | Add Gulp Live Server. Update Gulp Serve to run http server at the same time. 582 | 583 | commit 5e48ed8ace743de1c540b878421263fdf71c5a48 584 | Author: Daniel Stern 585 | Date: Sat May 16 09:14:30 2015 -0400 586 | 587 | Add tests for contacts. Add a nested test suite. Use to have property expectation. 588 | 589 | commit e8ff3066869a51e94e2c6dc77ca606ed2853a2fc 590 | Author: Daniel Stern 591 | Date: Sat May 16 09:02:00 2015 -0400 592 | 593 | Add new default contacts to contact service as Placeholder for backend. Updated view to display contacts. 594 | 595 | commit d7cff2e2613ecec9ec71d8f8e0edd767b0cf361e 596 | Author: Daniel Stern 597 | Date: Sat May 16 08:53:46 2015 -0400 598 | 599 | Add scaffold for server.js to be backend. 600 | 601 | commit ba8ebf2a0a918e64f80dbde8a205f7e02e9d7791 602 | Author: Daniel Stern 603 | Date: Sat May 16 08:51:13 2015 -0400 604 | 605 | Update Gulp to run Test every time a change occurs while serving. 606 | 607 | commit 84c146fa38139d4e0d9b72e7297f6d5581803b1a 608 | Author: Daniel Stern 609 | Date: Sat May 16 08:44:04 2015 -0400 610 | 611 | Update Gulp Test to run automatically before Gulp Serve runs. If tests fail, Gulp Serve will not run. 612 | 613 | commit 275e45a212aed177826c85913ba8233dc35c5188 614 | Author: Daniel Stern 615 | Date: Sat May 16 08:39:26 2015 -0400 616 | 617 | Update serve test to run tests automagically. 618 | 619 | commit 37c129e16f4a51380f82fd5b260f9dfd2c9ef25a 620 | Author: Daniel Stern 621 | Date: Sat May 16 08:37:10 2015 -0400 622 | 623 | add test for controller 624 | 625 | commit 4f3527e09705d1339ba53879be7aca58f1a8c4be 626 | Author: Daniel Stern 627 | Date: Sat May 16 08:25:10 2015 -0400 628 | 629 | Add contact list controller. Add basic contact view. 630 | 631 | commit 6b047f9d64fa3e067a9c76e84952ac9963d9b946 632 | Author: Daniel Stern 633 | Date: Sat May 16 08:18:52 2015 -0400 634 | 635 | Add terminal tests. Add karma. Add karma-mocha. Restructure tests slightly to allow both karma and mocha to work. 636 | 637 | commit 7a0544786d4c1f48cc5197d765f18b832581bc6e 638 | Author: Daniel Stern 639 | Date: Fri May 15 22:34:59 2015 -0400 640 | 641 | Test first service. Use angular inject and angular module. Use non trivial assertion isArray 642 | 643 | commit 6749215d9ffaba2afb319ba219d44ac794e56752 644 | Author: Daniel Stern 645 | Date: Fri May 15 22:13:15 2015 -0400 646 | 647 | gulp serve-test working!!! 648 | 649 | commit beb1227b6cddbf072510ba0ae7392c0637db8867 650 | Author: Daniel Stern 651 | Date: Fri May 15 22:12:10 2015 -0400 652 | 653 | update gulpfile, add dependencies 654 | 655 | commit 796669526ed8de4738ed4dee75cab10ffbf61720 656 | Author: Daniel Stern 657 | Date: Fri May 15 22:04:31 2015 -0400 658 | 659 | scaffold first test 660 | 661 | commit 22f9a7ed55607924c2ca9433504e96305b63bc4e 662 | Author: Daniel Stern 663 | Date: Fri May 15 21:49:43 2015 -0400 664 | 665 | add to glossary 666 | 667 | commit a0ae151c51120bfee35aba14c2b21b27701c7d57 668 | Author: Daniel Stern 669 | Date: Fri May 15 21:29:59 2015 -0400 670 | 671 | add first service 672 | 673 | commit f127d8641c59cdc6a4b99601ba698c9596c310d8 674 | Author: Daniel Stern 675 | Date: Fri May 15 21:23:32 2015 -0400 676 | 677 | Add app.js and create angular module. 678 | 679 | commit 8364bf985434aeb0e57ce8aa079388774c1e58a5 680 | Author: Daniel Stern 681 | Date: Fri May 15 21:20:13 2015 -0400 682 | 683 | scaffold browser sync and index file 684 | 685 | commit 84a08674c4e006f117f44c6937479b246c84b752 686 | Author: Daniel Stern 687 | Date: Fri May 15 21:02:39 2015 -0400 688 | 689 | scaffold gulpfile, install dependency 690 | 691 | commit 0654c291efb798e5eacdafc277e77a645851647f 692 | Author: Daniel Stern 693 | Date: Fri May 15 20:53:46 2015 -0400 694 | 695 | set up initial files 696 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function(config){ 2 | config.set({ 3 | //plugins:['karma-mocha','karma-phantomjs-launcher'], 4 | browsers:['PhantomJS'], 5 | frameworks:['mocha'], 6 | preprocessors:{ 7 | 'app/**/*.js':['coverage'] 8 | }, 9 | coverageReporter:{ 10 | includeAllSources:true, 11 | reporters:[{ 12 | type:'html', 13 | dir:'test/coverage', 14 | subdir:'.' 15 | },{ 16 | type:'text' 17 | }] 18 | }, 19 | files:[ 20 | "bower_components/angular/angular.js", 21 | "bower_components/angular-mocks/angular-mocks.js", 22 | "bower_components/chai/chai.js", 23 | 24 | "app/**/*.js", 25 | 26 | "test/*.js" 27 | ], 28 | }) 29 | } 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-tdd-demo", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/danielstern/angular-tdd-exemplar.git" 12 | }, 13 | "author": "", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/danielstern/angular-tdd-exemplar/issues" 17 | }, 18 | "homepage": "https://github.com/danielstern/angular-tdd-exemplar#readme", 19 | "dependencies": { 20 | "browser-sync": "^2.7.6", 21 | "cors": "^2.7.1", 22 | "express": "^4.12.4", 23 | "gulp": "^3.8.11", 24 | "gulp-karma": "0.0.4", 25 | "gulp-live-server": "0.0.17", 26 | "gulp-protractor": "^1.0.0", 27 | "istanbul": "^0.3.14", 28 | "karma": "^0.12.35", 29 | "karma-coverage": "^0.3.1", 30 | "karma-mocha": "^0.1.10", 31 | "mocha": "^2.2.5" 32 | }, 33 | "devDependencies": { 34 | "karma-mocha": "^0.1.10", 35 | "karma-mocha-reporter": "^1.0.2", 36 | "karma-phantomjs-launcher": "^0.2.0", 37 | "mocha": "^2.2.5", 38 | "phantomjs": "^1.9.17" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var cors = require('cors'); 3 | 4 | var app = express(); 5 | app.use(cors()); 6 | 7 | var contacts = [{ 8 | "name":"Shotaro Kaneda", 9 | "age":16, 10 | "occupation":"Futuristic Biker Gang Captain", 11 | "email":"kaneda@capsules.co.jp" 12 | },{ 13 | "name":"Jon Snow", 14 | "age":15, 15 | "occupation":"Lord Commander of the Wall", 16 | "email":"jon@nightswatch.wl" 17 | },{ 18 | "name":"Lara Croft", 19 | "age":22, 20 | "occupation":"Tomb Raider", 21 | "email":"lara@croft.co.uk" 22 | }]; 23 | 24 | app.get('/contacts',function(req,res){ 25 | res.status(200).json(contacts); 26 | }) 27 | 28 | app.listen(9001); 29 | -------------------------------------------------------------------------------- /test/e2e/app.spec.js: -------------------------------------------------------------------------------- 1 | describe('end to end address tests',function(){ 2 | it ("should have contacts",function(done){ 3 | browser.get('http://localhost:8080'); 4 | element.all(by.repeater('contact in contacts')) 5 | .then(function(contacts){ 6 | var first = contacts[0]; 7 | var text = first.getText(); 8 | expect(text).toEqual('Robert R'); 9 | done(); 10 | }) 11 | }) 12 | }) -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mocha Spec Runner 5 | 6 | 7 | 8 |
9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | -------------------------------------------------------------------------------- /test/main.spec.js: -------------------------------------------------------------------------------- 1 | var assert = chai.assert; 2 | var expect = chai.expect; 3 | 4 | describe("The Address Book App",function(){ 5 | describe("the contact service",function(){ 6 | beforeEach(function(){ 7 | module('AddressBook'); 8 | inject(function($injector){ 9 | contactService = $injector.get("contactService"); 10 | $httpBackend = $injector.get("$httpBackend"); 11 | }); 12 | }) 13 | 14 | it("should have a property contacts, an array",function(){ 15 | expect(contactService.contacts).to.be.an('array'); 16 | }); 17 | 18 | it ("should call the backend",function(){ 19 | $httpBackend.expectGET("http://localhost:9001/contacts") 20 | .respond(200,[]); 21 | $httpBackend.flush(); 22 | }) 23 | }) 24 | 25 | describe("the contact controller",function(){ 26 | beforeEach(function(){ 27 | module('AddressBook'); 28 | inject(function($injector,$rootScope){ 29 | $scope = $rootScope.$new(); 30 | contactService = $injector.get("contactService"); 31 | $httpBackend = $injector.get("$httpBackend"); 32 | $controller = $injector.get("$controller"); 33 | }) 34 | }) 35 | 36 | it ("should store an array of contacts in scope",function(){ 37 | $controller("ContactController",{$scope:$scope,contactService:contactService}); 38 | assert.isArray($scope.contacts); 39 | }) 40 | }) 41 | 42 | describe("the proper filter",function(){ 43 | beforeEach(function(){ 44 | module("AddressBook"); 45 | inject(function($injector){ 46 | proper = $injector.get("$filter")("proper"); 47 | }); 48 | }) 49 | 50 | it ("should proper case a string",function(){ 51 | expect(proper("ned stark")).to.equal("Ned Stark"); 52 | expect(proper("cersei lannister")).to.equal("Cersei Lannister"); 53 | }); 54 | 55 | it ("should take a number and return that as a string",function(){ 56 | expect(proper(42)).to.equal("42"); 57 | }) 58 | 59 | it ("should throw an error on an incompatible type",function(){ 60 | assert.throws(function(){ 61 | proper(undefined) 62 | }); 63 | }) 64 | }) 65 | 66 | describe("avatar",function(){ 67 | beforeEach(function(){ 68 | module("AddressBook"); 69 | }) 70 | 71 | it ("should display the capitalized first letter of a name",function(){ 72 | inject(function($rootScope,$compile){ 73 | $rootScope.contact = {name:'jon arryn'}; 74 | var element = $compile('')($rootScope); 75 | $rootScope.$digest(); 76 | var dirText = element.text(); 77 | expect(dirText).to.equal("J"); 78 | }) 79 | }) 80 | }) 81 | }) 82 | -------------------------------------------------------------------------------- /test/protractor.config.js: -------------------------------------------------------------------------------- 1 | exports.config = { 2 | seleniumAddress: 'http://localhost:4444/wd/hub', 3 | capabilities: { 4 | 'browserName':'chrome' 5 | }, 6 | specs:['e2e/*.js'], 7 | jasmineNodeOpts: { 8 | showColors: true 9 | } 10 | } --------------------------------------------------------------------------------