From 724819e3cfd8aeda1f724fb527db2b57494be9b7 Mon Sep 17 00:00:00 2001 From: Ben Ripkens Date: Mon, 20 May 2013 19:10:04 +0200 Subject: fix(angular.equals): add support for regular expressions Regular expression objects didn't used to be considered to be equal when using 'angular.equals'. Dirty checking therefore failed to recognize a property modification. Closes #2685 --- test/AngularSpec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/AngularSpec.js') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index da70aef7..151aac0a 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -278,6 +278,17 @@ describe('angular', function() { expect(equals({}, {hasOwnProperty: 1})).toBe(false); expect(equals({}, {toString: null})).toBe(false); }); + + it('should compare regular expressions', function() { + expect(equals(/abc/, /abc/)).toBe(true); + expect(equals(/abc/i, new RegExp('abc', 'i'))).toBe(true); + expect(equals(new RegExp('abc', 'i'), new RegExp('abc', 'i'))).toBe(true); + expect(equals(new RegExp('abc', 'i'), new RegExp('abc'))).toBe(false); + expect(equals(/abc/i, /abc/)).toBe(false); + expect(equals(/abc/, /def/)).toBe(false); + expect(equals(/^abc/, /abc/)).toBe(false); + expect(equals(/^abc/, '/^abc/')).toBe(false); + }); }); describe('size', function() { @@ -654,6 +665,23 @@ describe('angular', function() { }); }); + + describe('isRegExp', function() { + it('should return true for RegExp object', function() { + expect(isRegExp(/^foobar$/)).toBe(true); + expect(isRegExp(new RegExp('^foobar$/'))).toBe(true); + }); + + it('should return false for non RegExp objects', function() { + expect(isRegExp([])).toBe(false); + expect(isRegExp('')).toBe(false); + expect(isRegExp(23)).toBe(false); + expect(isRegExp({})).toBe(false); + expect(isRegExp(new Date())).toBe(false); + }); + }); + + describe('compile', function() { it('should link to existing node and create scope', inject(function($rootScope, $compile) { var template = angular.element('