Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
describe('nulls in expressions', function() {
var props = ['b', 'c', 'd'];
var contexts = [
{ 'b': null },
{ 'b': { 'c': null } },
{ 'b': { 'c': { 'd': null } } }
];
forEach(props, function (prop, index) {
var expr = props.slice(0, index+1).join('.');
forEach(contexts, function (a, expectIndex) {
expectIndex = parseInt(expectIndex, 10);
if (index < expectIndex) { // will be an object
it('blabla', inject(function($rootScope) {
$rootScope.a = a;
expect(typeof $rootScope.$eval('a.' + expr)).toBe('object');
$rootScope.a = valueFn(a);
expect(typeof $rootScope.$eval('a().' + expr)).toBe('object');
}));
} else {
var result = (index == expectIndex ? null : undefined);
it('blabla', inject(function($rootScope) {
$rootScope.a = a;
expect($rootScope.$eval('a.' + expr)).toBe(result);
$rootScope.a = valueFn(a);
expect($rootScope.$eval('a().' + expr)).toBe(result);
}));
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.