diff options
| author | Igor Minar | 2010-11-11 16:21:51 -0800 |
|---|---|---|
| committer | Igor Minar | 2010-11-11 16:39:01 -0800 |
| commit | 0a8b3161b19c115ac3854217801e56ae766ab399 (patch) | |
| tree | 3a64c0530098dc16a0164c9502134accfed3cbcd /test | |
| parent | ba554eeb1bb6a6fc12307d33a5becd8b8ecd6cd7 (diff) | |
| download | angular.js-0a8b3161b19c115ac3854217801e56ae766ab399.tar.bz2 | |
$watch should optionally skip listener exec
- if initRun param is set to false, listener doesn't execute
- the oldValue should equal newValue during the initial execution
- added docs
- added specs
Diffstat (limited to 'test')
| -rw-r--r-- | test/ScopeSpec.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 4a207bf0..8b4ada5a 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -96,6 +96,40 @@ describe('scope/model', function(){ model.$eval(); expect(count).toEqual(1); }); + + it('should run listener upon registration by default', function() { + var model = createScope(); + var count = 0, + nameNewVal = 'crazy val 1', + nameOldVal = 'crazy val 2'; + + model.$watch('name', function(newVal, oldVal){ + count ++; + nameNewVal = newVal; + nameOldVal = oldVal + }); + + expect(count).toBe(1); + expect(nameNewVal).not.toBeDefined(); + expect(nameOldVal).not.toBeDefined(); + }); + + it('should not run listener upon registration if flag is passed in', function() { + var model = createScope(); + var count = 0, + nameNewVal = 'crazy val 1', + nameOldVal = 'crazy val 2'; + + model.$watch('name', function(newVal, oldVal){ + count ++; + nameNewVal = newVal; + nameOldVal = oldVal + }, undefined, false); + + expect(count).toBe(0); + expect(nameNewVal).toBe('crazy val 1'); + expect(nameOldVal).toBe('crazy val 2') + }); }); describe('$bind', function(){ |
