Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b6a107

Browse files
derrickmarpetebacondarwin
authored andcommitted
docs(tutorial/step-10): add mock image data to spec
Closes angular#8468 Closes angular#8535
1 parent 8c98d6a commit 1b6a107

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/content/tutorial/step_10.ngdoc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,50 @@ __`test/e2e/scenarios.js`:__
102102
You can now rerun `npm run protractor` to see the tests run.
103103

104104

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+
105149
# Experiments
106150

107151
* Let's add a new controller method to `PhoneDetailCtrl`:

0 commit comments

Comments
 (0)