Skip to content

Commit

Permalink
Fixes #43
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Sep 8, 2016
1 parent d536ea4 commit ecdd4c9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 53 deletions.
1 change: 1 addition & 0 deletions src/elements/element.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
disconnectedCallback() {}

ready() {
super.ready();
if (!this.root) {
if (this._template) {
if (this.attachShadow) {
Expand Down
2 changes: 1 addition & 1 deletion src/elements/legacy-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

constructor() {
super();
this._applyConfigMetaData();
this.created();
}

Expand All @@ -65,6 +64,7 @@
}

ready() {
this._applyConfigMetaData();
super.ready();
}

Expand Down
5 changes: 3 additions & 2 deletions src/properties/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,6 @@

_flushProperties(fromAbove) {
if (!this.__dataInitialized) {
this.__dataInitialized = true;
this.ready();
}
if (this.__dataPending || this.__dataPendingClients) {
Expand All @@ -716,7 +715,9 @@
}
}

ready() {}
ready() {
this.__dataInitialized = true;
}

_stampTemplate(template) {
let dom = super._stampTemplate(template);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/attributes-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@
},

properties: {
attr1: String,
prop2: String
},

created: function() {
ready: function() {
this.setAttribute('prop2', 'hi');
}
});
Expand Down
88 changes: 39 additions & 49 deletions test/unit/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,60 +260,50 @@
configuredObject = {foo: 'bar', nested: {'meaning': 42}, arr: [0, 'foo', true]};
});

test('hostAttributes set correctly', function(done) {
test('hostAttributes set correctly', function() {
var element = fixture('basic');
assert.strictEqual(element.getAttribute('attr1'), 'this is attr 1');
assert.strictEqual(element.getAttribute('attr2'), '42');
assert.strictEqual(element.getAttribute('attr3'), 'instance', 'host attribute overrode instance attribute and should not');
assert.strictEqual(element.getAttribute('aria-role'), 'button');
assert.strictEqual(element.getAttribute('title'), 'awesome');
assert.strictEqual(element.title, 'awesome');
assert.equal(element.getAttribute('attr-object'), JSON.stringify(configuredObject));
assert.equal(element.hasAttribute('attr-stupid'), false);
// class *is* serialized
// TODO: reenable the next lines when https://github.com/PolymerLabs/alacarte/issues/41 is fixed
// BREAKME(sorvell): document breaking change.
assert.ok(element.classList.contains('foo'));
assert.ok(element.classList.contains('bar'));
assert.ok(element.classList.contains('baz'));

Polymer.RenderStatus.afterNextRender(element, function() {
assert.strictEqual(this.getAttribute('attr1'), 'this is attr 1');
assert.strictEqual(this.getAttribute('attr2'), '42');
assert.strictEqual(this.getAttribute('attr3'), 'instance', 'host attribute overrode instance attribute and should not');
assert.strictEqual(this.getAttribute('aria-role'), 'button');
assert.strictEqual(this.getAttribute('title'), 'awesome');
assert.strictEqual(this.title, 'awesome');
assert.equal(this.getAttribute('attr-object'), JSON.stringify(configuredObject));
assert.equal(this.hasAttribute('attr-stupid'), false);

// class is not serialized
// TODO: reenable the next lines when https://github.com/PolymerLabs/alacarte/issues/41 is fixed
//assert.notOk(this.classList.contains('foo'));
//assert.notOk(this.classList.contains('bar'));
//assert.notOk(this.classList.contains('baz'));

done();
});
});

test('hostAttributes set correctly in composed element', function(done) {
test('hostAttributes set correctly in composed element', function() {
var element = fixture('compose');

Polymer.RenderStatus.afterNextRender(element, function() {
// TODO: reenable the next line when https://github.com/PolymerLabs/alacarte/issues/43 is fixed
//assert.strictEqual(this.$.basic.getAttribute('attr1'), 'compose');
assert.strictEqual(this.$.basic.getAttribute('attr2'), '42');
assert.strictEqual(this.$.basic.getAttribute('aria-role'), 'button');
assert.strictEqual(this.$.basic.getAttribute('title'), 'awesome');
assert.strictEqual(this.$.basic.title, 'awesome');

assert.equal(this.$.basic.getAttribute('attr-object'), JSON.stringify(configuredObject));
assert.equal(this.$.basic.hasAttribute('attr-stupid'), false);

// class is not serialized
// TODO: reenable the next lines when https://github.com/PolymerLabs/alacarte/issues/41 is fixed
//assert.notOk(this.$.basic.classList.contains('foo'));
//assert.notOk(this.$.basic.classList.contains('bar'));
//assert.notOk(this.$.basic.classList.contains('baz'));

assert(this.$.basic.classList.contains('should-not-override'));

// applied to property with effect
// TODO: reenable the next lines when https://github.com/PolymerLabs/alacarte/issues/43 is fixed
//assert.strictEqual(this.$.basic.prop, 'compose');
//assert.equal(this.$.basic.propChangedCount, 1);
//assert.equal(this.$.basic.attr1ChangedCount, 1);
assert.equal(this.prop2, 'hi');

done();
});
// TODO: reenable the next line when https://github.com/PolymerLabs/alacarte/issues/43 is fixed
//assert.strictEqual(this.$.basic.getAttribute('attr1'), 'compose');
assert.strictEqual(element.$.basic.getAttribute('attr2'), '42');
assert.strictEqual(element.$.basic.getAttribute('aria-role'), 'button');
assert.strictEqual(element.$.basic.getAttribute('title'), 'awesome');
assert.strictEqual(element.$.basic.title, 'awesome');

assert.equal(element.$.basic.getAttribute('attr-object'), JSON.stringify(configuredObject));
assert.equal(element.$.basic.hasAttribute('attr-stupid'), false);

// class does not overwrite user setting
assert.notOk(element.$.basic.classList.contains('foo'));
assert.notOk(element.$.basic.classList.contains('bar'));
assert.notOk(element.$.basic.classList.contains('baz'));

assert(element.$.basic.classList.contains('should-not-override'));

// applied to property with effect
// TODO: reenable the next lines when https://github.com/PolymerLabs/alacarte/issues/43 is fixed
//assert.strictEqual(element.$.basic.prop, 'compose');
assert.equal(element.$.basic.propChangedCount, 1);
assert.equal(element.$.basic.attr1ChangedCount, 1);
assert.equal(element.prop2, 'hi');
});

});
Expand Down

0 comments on commit ecdd4c9

Please sign in to comment.