This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
fix($compile): fix ng-prop-* with undefined values #16798
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,48 @@ describe('ngProp*', function() { | |
expect(element.prop('asdf')).toBe(true); | ||
})); | ||
|
||
// https://github.com/angular/angular.js/issues/16797 | ||
it('should support falsy property values', inject(function($rootScope, $compile) { | ||
var element = $compile('<span ng-prop-text="myText" />')($rootScope); | ||
// Initialize to truthy value | ||
$rootScope.myText = 'abc'; | ||
$rootScope.$digest(); | ||
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. As I like to say, you can make these shorter with: |
||
expect(element.prop('text')).toBe('abc'); | ||
|
||
// Assert various falsey values get assigned to the property | ||
$rootScope.myText = ''; | ||
$rootScope.$digest(); | ||
expect(element.prop('text')).toBe(''); | ||
$rootScope.myText = 0; | ||
$rootScope.$digest(); | ||
expect(element.prop('text')).toBe(0); | ||
$rootScope.myText = false; | ||
$rootScope.$digest(); | ||
expect(element.prop('text')).toBe(false); | ||
$rootScope.myText = undefined; | ||
$rootScope.$digest(); | ||
expect(element.prop('text')).toBeUndefined(); | ||
$rootScope.myText = null; | ||
$rootScope.$digest(); | ||
expect(element.prop('text')).toBe(null); | ||
})); | ||
|
||
it('should directly map special properties (class)', inject(function($rootScope, $compile) { | ||
var element = $compile('<span ng-prop-class="myText" />')($rootScope); | ||
$rootScope.myText = 'abc'; | ||
$rootScope.$digest(); | ||
expect(element[0].class).toBe('abc'); | ||
expect(element).not.toHaveClass('abc'); | ||
})); | ||
|
||
it('should not use jQuery .prop() to avoid jQuery propFix/hooks', inject(function($rootScope, $compile) { | ||
var element = $compile('<span ng-prop-class="myText" />')($rootScope); | ||
spyOn(jqLite.prototype, 'prop'); | ||
$rootScope.myText = 'abc'; | ||
$rootScope.$digest(); | ||
expect(jqLite.prototype.prop).not.toHaveBeenCalled(); | ||
})); | ||
|
||
it('should support mixed case using underscore-separated names', inject(function($rootScope, $compile) { | ||
var element = $compile('<span ng-prop-a_bcd_e="value" />')($rootScope); | ||
$rootScope.value = 123; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
$element
can only ever have 1 element at this point, right? 😟