This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Replace `$http` with `$resource`. - Create a custom `Phone` service that represents the RESTful client. - Use a custom Jasmine equality tester in unit tests to ignore irrelevant properties.
- Loading branch information
1 parent
9307517
commit bfed542
Showing
13 changed files
with
88 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
'use strict'; | ||
|
||
// Define the `core` module | ||
angular.module('core', []); | ||
angular.module('core', ['core.phone']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
// Define the `core.phone` module | ||
angular.module('core.phone', ['ngResource']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
angular. | ||
module('core.phone'). | ||
factory('Phone', ['$resource', | ||
function($resource) { | ||
return $resource('phones/:phoneId.json', {}, { | ||
query: { | ||
method: 'GET', | ||
params: {phoneId: 'phones'}, | ||
isArray: true | ||
} | ||
}); | ||
} | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
describe('Phone', function() { | ||
var $httpBackend; | ||
var Phone; | ||
var phonesData = [ | ||
{name: 'Phone X'}, | ||
{name: 'Phone Y'}, | ||
{name: 'Phone Z'} | ||
]; | ||
|
||
// Add a custom equality tester before each test | ||
beforeEach(function() { | ||
jasmine.addCustomEqualityTester(angular.equals); | ||
}); | ||
|
||
// Load the module that contains the `Phone` service before each test | ||
beforeEach(module('core.phone')); | ||
|
||
// Instantiate the service and "train" `$httpBackend` before each test | ||
beforeEach(inject(function(_$httpBackend_, _Phone_) { | ||
$httpBackend = _$httpBackend_; | ||
$httpBackend.expectGET('phones/phones.json').respond(phonesData); | ||
|
||
Phone = _Phone_; | ||
})); | ||
|
||
// Verify that there are no outstanding expectations or requests after each test | ||
afterEach(function () { | ||
$httpBackend.verifyNoOutstandingExpectation(); | ||
$httpBackend.verifyNoOutstandingRequest(); | ||
}); | ||
|
||
it('should fetch the phones data from `/phones/phones.json`', function() { | ||
var phones = Phone.query(); | ||
|
||
expect(phones).toEqual([]); | ||
|
||
$httpBackend.flush(); | ||
expect(phones).toEqual(phonesData); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
// Define the `phoneDetail` module | ||
angular.module('phoneDetail', [ | ||
'ngRoute' | ||
'ngRoute', | ||
'core.phone' | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
'use strict'; | ||
|
||
// Define the `phoneList` module | ||
angular.module('phoneList', []); | ||
angular.module('phoneList', ['core.phone']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters