Skip to content

Commit 9981e5f

Browse files
committed
fix(web components): Support Polymer quirks
Closes dart-archive#1292
1 parent 4633451 commit 9981e5f

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

karma.conf.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = function(config) {
1010
files: [
1111
'packages/web_components/platform.js',
1212
'packages/web_components/dart_support.js',
13+
'test/core_dom/web_components_support.js',
1314
'test/*.dart',
1415
'test/**/*_spec.dart',
1516
'test/config/init_guinness.dart',

test/core_dom/web_components_spec.dart

+16-8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import '../_specs.dart';
44
import 'dart:js' as js;
55

66
registerElement(String name, prototype) {
7-
return (new js.JsObject.fromBrowserObject(document)).callMethod('registerElement',
8-
[name, new js.JsObject.jsify({"prototype": prototype })]);
7+
js.context['angularTestsRegisterElement'].apply(
8+
[name, new js.JsObject.jsify(prototype)]);
99
}
1010

1111

@@ -32,22 +32,30 @@ main() {
3232
(new js.JsObject.fromBrowserObject(_.rootElement))[prop] = value;
3333
}
3434

35+
compileAndUpgrade(String html) {
36+
_.compile(html);
37+
var CustomElements = js.context['CustomElements'];
38+
if (CustomElements != null) {
39+
CustomElements['upgradeAll'].apply([new js.JsObject.fromBrowserObject(_.rootElement)]);
40+
}
41+
}
42+
3543
beforeEach((TestBed tb) {
3644
_ = tb;
3745
});
3846

39-
it('should create custom elements', () {
47+
iit('should create custom elements', () {
4048
registerElement('tests-basic', {'prop-x': 6});
4149

4250
// Create a web component
43-
_.compile('<tests-basic></tests-basic>');
51+
compileAndUpgrade('<tests-basic></tests-basic>');
4452
expect(customProp('prop-x')).toEqual(6);
4553
});
4654

4755

4856
it('should bind to Custom Element properties', () {
4957
registerElement('tests-bound', {'prop-y': 10});
50-
_.compile('<tests-bound bind-prop-y=27></tests-bound>');
58+
compileAndUpgrade('<tests-bound bind-prop-y=27></tests-bound>');
5159

5260
// Scope has not been digested yet
5361
expect(customProp('prop-y')).toEqual(10);
@@ -59,22 +67,22 @@ main() {
5967

6068
it('should bind to a non-existent property', () {
6169
registerElement('tests-empty', {});
62-
_.compile('<tests-empty bind-new-prop=27></tests-empty>');
70+
compileAndUpgrade('<tests-empty bind-new-prop=27></tests-empty>');
6371
_.rootScope.apply();
6472
expect(customProp('new-prop')).toEqual(27);
6573
});
6674

6775
it('should bind to both directives and properties', () {
6876
registerElement('tests-double', {});
69-
_.compile('<tests-double ng-bind bind-ng-bind="\'hello\'"></tests-double>');
77+
compileAndUpgrade('<tests-double ng-bind bind-ng-bind="\'hello\'"></tests-double>');
7078
_.rootScope.apply();
7179
expect(customProp('ng-bind')).toEqual("hello");
7280
expect(_.rootElement).toHaveText('hello');
7381
});
7482

7583
it('should support two-way bindings for components that trigger a change event', () {
7684
registerElement('tests-twoway', {});
77-
_.compile('<tests-twoway bind-prop="x"></tests-twoway>');
85+
compileAndUpgrade('<tests-twoway bind-prop="x"></tests-twoway>');
7886

7987
setCustomProp('prop', 6);
8088
_.rootElement.dispatchEvent(new Event.eventType('CustomEvent', 'change'));
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Used to create Javascript Web Components from Dart tests
3+
*/
4+
function angularTestsRegisterElement(name, prototype) {
5+
// Polymer requires that all prototypes are chained to HTMLElement
6+
// https://github.com/Polymer/CustomElements/issues/121
7+
prototype.__proto__ = HTMLElement.prototype;
8+
prototype.createdCallback = function() {};
9+
document.registerElement(name, {prototype: prototype});
10+
}

0 commit comments

Comments
 (0)