Skip to content

Instantly share code, notes, and snippets.

@rodyhaddad
Last active December 31, 2015 19:39
Show Gist options
  • Save rodyhaddad/8035190 to your computer and use it in GitHub Desktop.
Save rodyhaddad/8035190 to your computer and use it in GitHub Desktop.
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