This repository has been archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(element binder): Bind to Web Component properties
Closes #1277
- Loading branch information
Showing
3 changed files
with
76 additions
and
3 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
library angular.dom.web_components_spec; | ||
|
||
import '../_specs.dart'; | ||
import 'dart:js' as js; | ||
|
||
registerElement(String name, prototype) { | ||
return (new js.JsObject.fromBrowserObject(document)).callMethod('registerElement', | ||
[name, new js.JsObject.jsify({"prototype": prototype })]); | ||
} | ||
|
||
|
||
|
||
main() { | ||
describe('WebComponent support', () { | ||
TestBed _; | ||
|
||
customProp(String prop, [elt]) { | ||
if (elt == null) elt = _.rootElement; | ||
return (new js.JsObject.fromBrowserObject(elt))[prop]; | ||
} | ||
|
||
beforeEach((TestBed tb) { | ||
_ = tb; | ||
}); | ||
|
||
it('should create custom elements', () { | ||
registerElement('tests-basic', {'prop-x': 6}); | ||
|
||
// Create a web component | ||
_.compile('<tests-basic></tests-basic>'); | ||
expect(customProp('prop-x')).toEqual(6); | ||
}); | ||
|
||
|
||
it('should bind to Custom Element properties', () { | ||
registerElement('tests-bound', {'prop-y': 10}); | ||
_.compile('<tests-bound bind-prop-y=27></tests-bound>'); | ||
|
||
// Scope has not been digested yet | ||
expect(customProp('prop-y')).toEqual(10); | ||
|
||
_.rootScope.apply(); | ||
expect(customProp('prop-y')).toEqual(27); | ||
}); | ||
|
||
|
||
it('should bind to a non-existent property', () { | ||
registerElement('tests-empty', {}); | ||
_.compile('<tests-empty bind-new-prop=27></tests-empty>'); | ||
_.rootScope.apply(); | ||
expect(customProp('new-prop')).toEqual(27); | ||
}); | ||
|
||
it('should bind to both directives and properties', () { | ||
registerElement('tests-double', {}); | ||
_.compile('<tests-double ng-bind bind-ng-bind="\'hello\'"></tests-double>'); | ||
_.rootScope.apply(); | ||
expect(customProp('ng-bind')).toEqual("hello"); | ||
expect(_.rootElement).toHaveText('hello'); | ||
}); | ||
}); | ||
} |