Thierry Chatel
<div ng-app="googleMap"> <map id="map_canvas1" zoom="12" center="{lat:-26.0833,lon:28.2500}" maptype="roadmap" scrollwheel="false"></map> <map id="map_canvas2" zoom="8" center="{lat:-26.0833,lon:28.2500}" maptype="satellite" scrollwheel="true"></map> </div>
angular.module('MyServiceModuleDI', []) .factory('notify', function($window) { var msgs = []; return function(msg) { msgs.push(msg); if (msgs.length == 3) { $window.alert(msgs.join("\n")); msgs = []; } }; }); function myController($scope, notify) { $scope.callNotify = function(msg) { notify(msg); }; }
describe('PhoneCat controllers', function() { describe('PhoneListCtrl', function() { var scope, ctrl, httpMock; beforeEach(inject(function($httpBackend, $rootScope, $controller) { httpMock = $httpBackend; httpMock.expectGET('phones/phones.json'). respond([{name: 'Nexus S'}, {name: 'Motorola DROID'}]); scope = $rootScope.$new(); ctrl = $controller(PhoneListCtrl, {$scope: scope}); })); it('should create "phones" model with 2 phones fetched from xhr', function() { expect(scope.phones).toBeUndefined(); httpMock.flush(); expect(scope.phones).toEqual([{name: 'Nexus S'}, {name: 'Motorola DROID'}]); }); it('should set the default value of orderProp model', function() { expect(scope.orderProp).toBe('age'); }); }); });
describe('PhoneCat App', function() { describe('Phone list view', function() { beforeEach(function() { browser().navigateTo('../../app/index.html'); }); it('should filter the phone list as user types into the search box', function() { expect(repeater('.phones li').count()).toBe(20); input('query').enter('nexus'); expect(repeater('.phones li').count()).toBe(1); input('query').enter('motorola'); expect(repeater('.phones li').count()).toBe(8); }); it('should be possible to control phone order via the drop down select box', function() { input('query').enter('tablet'); //let's narrow the dataset to make the test assertions shorter expect(repeater('.phones li', 'Phone List').column('phone.name')). toEqual(["Motorola XOOM\u2122 with Wi-Fi", "MOTOROLA XOOM\u2122"]); select('orderProp').option('Alphabetical'); expect(repeater('.phones li', 'Phone List').column('phone.name')). toEqual(["MOTOROLA XOOM\u2122", "Motorola XOOM\u2122 with Wi-Fi"]); }); }); });
function PhoneListCtrl($scope, $http) { $http.get('phones/phones.json').success(function(data) { $scope.phones = data; }); }
var User = $resource('/user/:userId', {userId:'@id'}); var user = User.get({userId:123}, function() { user.abc = true; user.$save(); });