@@ -102,6 +102,50 @@ __`test/e2e/scenarios.js`:__
102
102
You can now rerun `npm run protractor` to see the tests run.
103
103
104
104
105
+ You also have to refactor one of your unit tests because of the addition of the `mainImageUrl`
106
+ model property to the `PhoneDetailCtrl` controller. Below, we create the function `xyzPhoneData`
107
+ which returns the appropriate json with the `images` attribute in order to get the test to pass.
108
+
109
+ __`test/unit/controllersSpec.js`:__
110
+
111
+ ```js
112
+ ...
113
+ beforeEach(module('phonecatApp'));
114
+
115
+ ...
116
+
117
+ describe('PhoneDetailCtrl', function(){
118
+ var scope, $httpBackend, ctrl,
119
+ xyzPhoneData = function() {
120
+ return {
121
+ name: 'phone xyz',
122
+ images: ['image/url1.png', 'image/url2.png']
123
+ }
124
+ };
125
+
126
+
127
+ beforeEach(inject(function(_$httpBackend_, $rootScope, $routeParams, $controller) {
128
+ $httpBackend = _$httpBackend_;
129
+ $httpBackend.expectGET('phones/xyz.json').respond(xyzPhoneData());
130
+
131
+ $routeParams.phoneId = 'xyz';
132
+ scope = $rootScope.$new();
133
+ ctrl = $controller('PhoneDetailCtrl', {$scope: scope});
134
+ }));
135
+
136
+
137
+ it('should fetch phone detail', function() {
138
+ expect(scope.phone).toBeUndefined();
139
+ $httpBackend.flush();
140
+
141
+ expect(scope.phone).toEqual(xyzPhoneData());
142
+ });
143
+ });
144
+ ```
145
+
146
+ Your unit tests should now be passing.
147
+
148
+
105
149
# Experiments
106
150
107
151
* Let's add a new controller method to `PhoneDetailCtrl`:
0 commit comments