I watched Angular Play by Play testing on PluralSight by John Pap and Ward Bell.
I am currently getting the following error when starting my specs.
AssertionError: expected { Object ($$state) } to have a property 'length' at Assertion.assertLength (bower_components/chai/chai.js:1331:37) at Assertion.assert (bower_components/chai/chai.js:4121:49) at Context.<anonymous> (scripts/home/homeController.Specs.js:48:49)
Please note that I only included the code, which, in my opinion, matters, so I do not overload this question with irrelevant information. If you need to see more code, this is not a problem.
My code is as follows:
homeController.js:
window.app.controller('homeController', ['$scope', 'sidebarService', function ($scope, sidebarService) { $scope.title = 'Slapdash'; $scope.sidebar = { "items": sidebarService.getSidebarItems() }; }])
sidebarService.js:
(function () { window.app .service('sidebarService',['$http', function ($http) { this.getSidebarItems = function () { $http.get("http://wwww.something.com/getSidebarItems") .then(function (response) { return response.data; }); }; }]); }());
homeController.Specs.js:
beforeEach:
beforeEach(function () { bard.appModule('slapdash'); bard.inject(this, '$controller', '$q', '$rootScope') var mockSidebarService = { getSidebarItems : function(){ return $q.when(mockSidebarMenuItems); } }; controller = $controller('homeController', { $scope: scope, sidebarService: mockSidebarService }); });
specification error:
it('Should have items', function () { $rootScope.$apply(); expect(scope.sidebar.items).to.have.length(mockSidebarMenuItems.length);
javascript angularjs bardjs
Prime by design
source share