chore(expressions): add explicit test for map vs property access

This commit is contained in:
yjbanov 2015-05-21 13:09:27 -07:00
parent 00c3693daa
commit c5996529c3
1 changed files with 53 additions and 0 deletions

View File

@ -74,6 +74,36 @@ main() {
});
}));
});
describe('Property access', () {
it('should distinguish between map and property access',
inject([TestBed, AsyncTestCompleter], (tb, async) {
tb.overrideView(Dummy, new View(
template: '<property-access></property-access>',
directives: [PropertyAccess]
));
tb.createView(Dummy).then((view) {
view.detectChanges();
expect(view.rootNodes).toHaveText('prop:foo-prop;map:foo-map');
async.done();
});
}));
it('should not fallback on map access if property missing',
inject([TestBed, AsyncTestCompleter], (tb, async) {
tb.overrideView(Dummy, new View(
template: '<no-property-access></no-property-access>',
directives: [NoPropertyAccess]
));
tb.createView(Dummy).then((view) {
expect(() => view.detectChanges())
.toThrowError(new RegExp('property not found'));
async.done();
});
}));
});
}
@Component(selector: 'dummy')
@ -115,3 +145,26 @@ class ThrowingComponent2 {
functionThatThrowsNonError();
}
}
@proxy
class PropModel implements Map {
final String foo = 'foo-prop';
operator[](_) => 'foo-map';
noSuchMethod(_) {
throw 'property not found';
}
}
@Component(selector: 'property-access')
@View(template: '''prop:{{model.foo}};map:{{model['foo']}}''')
class PropertyAccess {
final model = new PropModel();
}
@Component(selector: 'no-property-access')
@View(template: '''{{model.doesNotExist}}''')
class NoPropertyAccess {
final model = new PropModel();
}