-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Pr 14656 #14811
Pr 14656 #14811
Changes from all commits
8f63c5a
5096e34
b409bed
69be7a9
2dcbc4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3828,6 +3828,96 @@ describe('$compile', function() { | |
}); | ||
}); | ||
|
||
describe('$doCheck', function() { | ||
it('should call `$doCheck`, if provided, for each digest cycle, after $onChanges and $onInit', function() { | ||
var log = []; | ||
|
||
function TestController() { } | ||
TestController.prototype.$doCheck = function() { log.push('$doCheck'); }; | ||
TestController.prototype.$onChanges = function() { log.push('$onChanges'); }; | ||
TestController.prototype.$onInit = function() { log.push('$onInit'); }; | ||
|
||
angular.module('my', []) | ||
.component('dcc', { | ||
controller: TestController, | ||
bindings: { 'prop1': '<' } | ||
}); | ||
|
||
module('my'); | ||
inject(function($compile, $rootScope) { | ||
element = $compile('<dcc prop1="val"></dcc>')($rootScope); | ||
expect(log).toEqual([ | ||
'$onChanges', | ||
'$onInit', | ||
'$doCheck' | ||
]); | ||
|
||
// Clear log | ||
log = []; | ||
|
||
$rootScope.$apply(); | ||
expect(log).toEqual([ | ||
'$doCheck', | ||
'$doCheck' | ||
]); | ||
|
||
// Clear log | ||
log = []; | ||
|
||
$rootScope.$apply('val = 2'); | ||
expect(log).toEqual([ | ||
'$doCheck', | ||
'$onChanges', | ||
'$doCheck' | ||
]); | ||
}); | ||
}); | ||
|
||
it('should work if $doCheck is provided in the constructor', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that we have a test that verifies our incompatibility wiht ng2 😛 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More ribbing? :-P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No ribbing intended 😃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test looks identical to the one I added above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test above assigns the methods on the prototype. This test defines them on the instance from inside the constructor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha okay, thanks for explaining :) |
||
var log = []; | ||
|
||
function TestController() { | ||
this.$doCheck = function() { log.push('$doCheck'); }; | ||
this.$onChanges = function() { log.push('$onChanges'); }; | ||
this.$onInit = function() { log.push('$onInit'); }; | ||
} | ||
|
||
angular.module('my', []) | ||
.component('dcc', { | ||
controller: TestController, | ||
bindings: { 'prop1': '<' } | ||
}); | ||
|
||
module('my'); | ||
inject(function($compile, $rootScope) { | ||
element = $compile('<dcc prop1="val"></dcc>')($rootScope); | ||
expect(log).toEqual([ | ||
'$onChanges', | ||
'$onInit', | ||
'$doCheck' | ||
]); | ||
|
||
// Clear log | ||
log = []; | ||
|
||
$rootScope.$apply(); | ||
expect(log).toEqual([ | ||
'$doCheck', | ||
'$doCheck' | ||
]); | ||
|
||
// Clear log | ||
log = []; | ||
|
||
$rootScope.$apply('val = 2'); | ||
expect(log).toEqual([ | ||
'$doCheck', | ||
'$onChanges', | ||
'$doCheck' | ||
]); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('$onChanges', function() { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to manually track the remove watch function because we are after the point when we might swap out the controller for another instance. This watch will naturally be removed when the controller scope is destroyed.