From f5d08963b0c836b10133a94d03a81254242661eb Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 25 Jan 2011 20:44:44 -0800 Subject: split mocks and create $log and $exceptionHandler mocks - split mocks between angular-mocks.js and mocks.js - src/angular-mocks.js now contains only mocks that we want to ship - test/mocks.js contains mocks that we use internally for testing angular - created angular.mock namespace - created public $exceptionHandler mock rethrows errors - created public $log mock stores all logs messages in an array that can be accessed to make assertions - internally we now have factory to create $exceptionHandler that we can assert on - internally we also keep track of all messages logged and fail tests if messages were not expected and cleaned up (checked via global beforeEach and afterEach) - updated RakeFile and docs reader.js to point to the new angular-mocks.js location - made real $exceptionHandler and $log factories accessible from tests and simplified their specs - fixed typos in several spec descriptions - added log assertions throughout the test suite --- test/widgetsSpec.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'test/widgetsSpec.js') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 2812614f..ee339e89 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -546,12 +546,16 @@ describe("widget", function(){ it('should report error on assignment error', function(){ compile(''); expect(element.hasClass('ng-exception')).toBeTruthy(); + expect(scope.$service('$log').error.logs.shift()[0]). + toMatchError(/Parse Error: Token '''' is extra token not part of expression/); }); it('should report error on ng:change exception', function(){ compile(''); browserTrigger(element); expect(element.hasClass('ng-exception')).toBeTruthy(); + expect(scope.$service('$log').error.logs.shift()[0]). + toMatchError(/Parse Error: Token '=' implies assignment but \[a-2\] can not be assigned to/); }); }); @@ -750,10 +754,15 @@ describe("widget", function(){ it('should error on wrong parsing of ng:repeat', function(){ var scope = compile(''); - var log = ""; - log += element.attr('ng-exception') + ';'; - log += element.hasClass('ng-exception') + ';'; - expect(log).toMatch(/Expected ng:repeat in form of 'item in collection' but got 'i dont parse'./); + + expect(scope.$service('$log').error.logs.shift()[0]). + toEqualError("Expected ng:repeat in form of 'item in collection' but got 'i dont parse'."); + + expect(scope.$element.attr('ng-exception')). + toMatch(/Expected ng:repeat in form of 'item in collection' but got 'i dont parse'/); + expect(scope.$element).toHaveClass('ng-exception'); + + dealoc(scope); }); it('should expose iterator offset as $index when iterating over arrays', function() { -- cgit v1.2.3