Skip to content

Commit 40e87e6

Browse files
committed
Switch to more comprehensive tests of setting attributes sharing names with unwriteable properties
1 parent 262fd1c commit 40e87e6

16 files changed

+128
-46
lines changed

libraries/__shared__/webcomponents/src/ce-with-methods.js libraries/__shared__/webcomponents/src/ce-without-properties.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,25 @@
1515
* limitations under the License.
1616
*/
1717

18-
class CEWithMethods extends HTMLElement {
18+
class CEWithoutProperties extends HTMLElement {
1919

20-
test() {
21-
this.innerText = 'Success';
20+
amethod() {
21+
return 'method';
22+
}
23+
24+
get agetter() {
25+
return 'getter';
2226
}
2327

2428
connectedCallback() {
25-
this.test();
29+
this.amethod();
2630
}
2731

2832
}
2933

30-
customElements.define('ce-with-methods', CEWithMethods);
34+
Object.defineProperty(CEWithoutProperties.prototype, 'areadonly', {
35+
value: 'readonly',
36+
writable: false
37+
});
38+
39+
customElements.define('ce-without-properties', CEWithoutProperties);

libraries/angular/src/basic-tests.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
ComponentWithUnregistered,
2929
ComponentWithImperativeEvent,
3030
ComponentWithDeclarativeEvent,
31-
ComponentWithMethods
31+
ComponentWithoutProperties
3232
} from "./components";
3333

3434
beforeEach(function() {
@@ -42,7 +42,7 @@ beforeEach(function() {
4242
ComponentWithUnregistered,
4343
ComponentWithImperativeEvent,
4444
ComponentWithDeclarativeEvent,
45-
ComponentWithMethods
45+
ComponentWithoutProperties
4646
],
4747
schemas: [CUSTOM_ELEMENTS_SCHEMA]
4848
});
@@ -149,11 +149,14 @@ describe("basic support", function() {
149149
expect(data).to.eql("Angular");
150150
});
151151

152-
it('will not overwrite methods', function () {
153-
let fixture = TestBed.createComponent(ComponentWithMethods);
152+
it('will not overwrite unwriteable properties', function () {
153+
let fixture = TestBed.createComponent(ComponentWithoutProperties);
154154
fixture.detectChanges();
155155
let root = fixture.debugElement.nativeElement;
156-
expect(root.innerText).to.eql('Success')
156+
let wc = root.querySelector("#wc");
157+
expect(wc.getAttribute('amethod')).to.eql('method');
158+
expect(wc.getAttribute('agetter')).to.eql('getter');
159+
expect(wc.getAttribute('areadonly')).to.eql('readonly');
157160
});
158161
});
159162

libraries/angular/src/components.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import 'ce-without-children';
2727
import 'ce-with-children';
2828
import 'ce-with-properties';
2929
import 'ce-with-event';
30-
import 'ce-with-methods';
30+
import 'ce-without-properties';
3131

3232
@Component({
3333
template: `
@@ -109,11 +109,11 @@ export class ComponentWithProperties {
109109
@Component({
110110
template: `
111111
<div>
112-
<ce-with-methods [test]="true"></ce-with-methods>
112+
<ce-without-properties amethod="method" agetter="getter" areadonly="readonly" id="wc"></ce-without-properties>
113113
</div>
114114
`
115115
})
116-
export class ComponentWithMethods {}
116+
export class ComponentWithoutProperties {}
117117

118118
@Component({
119119
template: `

libraries/angularjs/src/app.module.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ComponentWithChildrenRerender,
77
ComponentWithDifferentViews,
88
ComponentWithProps,
9+
ComponentWithoutProps,
910
ComponentWithImperativeEvent,
1011
ComponentWithDeclarativeEvent
1112
} from './components';
@@ -16,6 +17,7 @@ export default angular.module('ce-tests', [])
1617
.component('compWithChildrenRerender', ComponentWithChildrenRerender)
1718
.component('compWithDifferentViews', ComponentWithDifferentViews)
1819
.component('compWithProps', ComponentWithProps)
20+
.component('compWithoutProps', ComponentWithoutProps)
1921
.component('compWithImperativeEvent', ComponentWithImperativeEvent)
2022
.component('compWithDeclarativeEvent', ComponentWithDeclarativeEvent)
2123
.name;

libraries/angularjs/src/basic-tests.js

+12
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ describe("basic support", () => {
113113
});
114114
});
115115

116+
describe("without properties", () => {
117+
it('will not overwrite unwriteable properties', function () {
118+
this.weight = 3;
119+
const comp = compile("<comp-without-props>")(scope);
120+
scope.$digest();
121+
const wc = comp[0].querySelector("#wc");
122+
expect(wc.getAttribute('amethod')).to.eql('method');
123+
expect(wc.getAttribute('agetter')).to.eql('getter');
124+
expect(wc.getAttribute('areadonly')).to.eql('readonly');
125+
});
126+
});
127+
116128
describe("events", () => {
117129
it("can imperatively listen to a DOM event dispatched by a Custom Element", function() {
118130
this.weight = 3;

libraries/angularjs/src/components.js

+23
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,28 @@ const ComponentWithProps = {
8181
}
8282
};
8383

84+
const ComponentWithoutProps = {
85+
template: `
86+
<div>
87+
<ce-without-properties id="wc"
88+
ng-attr-amethod="{{ $ctrl.method }}"
89+
ng-attr-agetter="{{ $ctrl.getter }}"
90+
ng-attr-areadonly="{{ $ctrl.readonly }}"
91+
></ce-without-properties>
92+
</div>
93+
`,
94+
controller: class {
95+
constructor() {}
96+
$onInit() {
97+
angular.extend(this, {
98+
method: 'method',
99+
getter: 'getter',
100+
readonly: 'readonly'
101+
})
102+
}
103+
}
104+
}
105+
84106
const ComponentWithImperativeEvent = {
85107
template: `
86108
<div>
@@ -154,6 +176,7 @@ export {
154176
ComponentWithChildrenRerender,
155177
ComponentWithDifferentViews,
156178
ComponentWithProps,
179+
ComponentWithoutProps,
157180
ComponentWithImperativeEvent,
158181
ComponentWithDeclarativeEvent
159182
}

libraries/dio/src/basic-tests.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
ComponentWithProperties,
2626
ComponentWithUnregistered,
2727
ComponentWithImperativeEvent,
28-
ComponentWithDeclarativeEvent
28+
ComponentWithDeclarativeEvent,
29+
ComponentWithoutProperties
2930
} from "./components";
3031

3132
// Setup the test harness. This will get cleaned out with every test.
@@ -128,6 +129,15 @@ describe("basic support", function() {
128129
let data = wc.str || wc.getAttribute("str");
129130
expect(data).to.eql("DIO");
130131
});
132+
133+
it('will not overwrite unwriteable properties', function () {
134+
render(<ComponentWithoutProperties />, scratch);
135+
console.log(scratch);
136+
let wc = scratch.querySelector("#wc");
137+
expect(wc.getAttribute('amethod')).to.eql('method');
138+
expect(wc.getAttribute('agetter')).to.eql('getter');
139+
expect(wc.getAttribute('areadonly')).to.eql('readonly');
140+
})
131141
});
132142

133143
describe("events", function() {

libraries/dio/src/components.js

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'ce-without-children';
2020
import 'ce-with-children';
2121
import 'ce-with-properties';
2222
import 'ce-with-event';
23+
import 'ce-without-properties';
2324

2425
export class ComponentWithoutChildren extends Component {
2526
render() {
@@ -109,6 +110,16 @@ export class ComponentWithProperties extends Component {
109110
}
110111
}
111112

113+
export class ComponentWithoutProperties extends Component {
114+
render () {
115+
return (
116+
<div>
117+
<ce-without-properties id="wc" amethod="method" agetter="getter" areadonly="readonly" />
118+
</div>
119+
)
120+
}
121+
}
122+
112123
export class ComponentWithUnregistered extends Component {
113124
render () {
114125
const data = {

libraries/react/src/basic-tests.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
ComponentWithUnregistered,
3030
ComponentWithImperativeEvent,
3131
ComponentWithDeclarativeEvent,
32-
ComponentWithMethods,
32+
ComponentWithoutProperties,
3333
} from "./components";
3434

3535
// Setup the test harness. This will get cleaned out with every test.
@@ -199,18 +199,19 @@ describe("basic support", function () {
199199
expect(data).to.eql("React");
200200
});
201201

202-
it('will not overwrite methods', function () {
203-
let root;
202+
it('will not overwrite unwriteable properties', function () {
203+
let wc;
204204
render(
205-
<ComponentWithMethods
205+
<ComponentWithoutProperties
206206
ref={(current) => {
207-
root = current;
207+
wc = current;
208208
}}
209209
/>
210210
)
211-
let wc = root.wc;
212-
expect(wc.innerText).to.eql('Success');
213-
})
211+
expect(wc.getAttribute('amethod')).to.eql('method');
212+
expect(wc.getAttribute('agetter')).to.eql('getter');
213+
expect(wc.getAttribute('areadonly')).to.eql('readonly');
214+
});
214215

215216
// TODO: Is it the framework's responsibility to check if the underlying
216217
// property is defined? Or should it just always assume it is and do its

libraries/react/src/components.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import 'ce-without-children';
2020
import 'ce-with-children';
2121
import 'ce-with-properties';
2222
import 'ce-with-event';
23-
import 'ce-with-methods';
23+
import 'ce-without-properties';
2424

2525
export class ComponentWithoutChildren extends Component {
2626
render() {
@@ -111,13 +111,11 @@ export class ComponentWithProperties extends Component {
111111
}
112112
}
113113

114-
export class ComponentWithMethods extends Component {
115-
render() {
116-
return <div>
117-
<ce-with-methods test ref={(el) => this.wc = el}></ce-with-methods>
118-
</div>
119-
}
120-
}
114+
export const ComponentWithoutProperties = React.forwardRef(({}, ref) => {
115+
return <div>
116+
<ce-without-properties amethod="method" agetter="getter" areadonly="readonly" ref={ref}></ce-without-properties>
117+
</div>
118+
});
121119

122120
export class ComponentWithUnregistered extends Component {
123121
render () {

libraries/svelte/src/basic-tests.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
ComponentWithProperties,
2525
ComponentWithUnregistered,
2626
ComponentWithImperativeEvent,
27-
ComponentWithMethods,
27+
ComponentWithoutProperties,
2828
} from "./components";
2929
import { tick } from "svelte";
3030

@@ -127,9 +127,11 @@ describe("basic support", function() {
127127
});
128128

129129
it('will not overwrite methods', function () {
130-
new ComponentWithMethods({ target: scratch });
130+
new ComponentWithoutProperties({ target: scratch });
131131
const wc = scratch.querySelector('#wc');
132-
expect(wc.innerText).to.eql('Success');
132+
expect(wc.getAttribute('amethod')).to.eql('method');
133+
expect(wc.getAttribute('agetter')).to.eql('getter');
134+
expect(wc.getAttribute('areadonly')).to.eql('readonly');
133135
})
134136

135137
// it('will set boolean attributes on a Custom Element that has not already been defined and upgraded', function() {

libraries/svelte/src/components.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import 'ce-without-children';
1919
import 'ce-with-children';
2020
import 'ce-with-properties';
2121
import 'ce-with-event';
22-
import 'ce-with-methods';
22+
import 'ce-without-properties';
2323

2424
export { default as ComponentWithoutChildren } from './components/ComponentWithoutChildren.svelte';
2525
export { default as ComponentWithChildren } from './components/ComponentWithChildren.svelte';
@@ -29,4 +29,4 @@ export { default as ComponentWithProperties } from './components/ComponentWithPr
2929
export { default as ComponentWithUnregistered } from './components/ComponentWithUnregistered.svelte';
3030
export { default as ComponentWithImperativeEvent } from './components/ComponentWithImperativeEvent.svelte';
3131
export { default as ComponentWithDeclarativeEvent } from './components/ComponentWithDeclarativeEvent.svelte';
32-
export { default as ComponentWithMethods } from './components/ComponentWithMethods.svelte';
32+
export { default as ComponentWithoutProperties } from './components/ComponentWithoutProperties.svelte';

libraries/svelte/src/components/ComponentWithMethods.svelte

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ce-with-methods id="wc" method="method" getter="getter" readonly="readonly"></ce-with-methods>

libraries/vue/src/basic-tests.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
ComponentWithUnregistered,
2626
ComponentWithImperativeEvent,
2727
ComponentWithDeclarativeEvent,
28-
ComponentWithMethods
28+
ComponentWithoutProperties
2929
} from "./components";
3030
import { expect } from "chai";
3131

@@ -148,11 +148,13 @@ describe("basic support", function() {
148148
expect(data).to.eql("Vue");
149149
});
150150

151-
it('will not overwrite methods', function () {
152-
const app = createApp(ComponentWithMethods);
151+
it('will not overwrite unwriteable properties', function () {
152+
const app = createApp(ComponentWithoutProperties);
153153
app.mount(scratch);
154154
const wc = scratch.querySelector('#wc');
155-
expect(wc.innerText).to.eql('Success');
155+
expect(wc.getAttribute('amethod')).to.eql('method');
156+
expect(wc.getAttribute('agetter')).to.eql('getter');
157+
expect(wc.getAttribute('areadonly')).to.eql('readonly');
156158
})
157159

158160
// it('will set boolean attributes on a Custom Element that has not already been defined and upgraded', function() {

libraries/vue/src/components.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import 'ce-without-children';
2020
import 'ce-with-children';
2121
import 'ce-with-properties';
2222
import 'ce-with-event';
23-
import 'ce-with-methods';
23+
import 'ce-without-properties';
2424

2525
export const ComponentWithoutChildren = defineComponent({
2626
template: `
@@ -101,14 +101,23 @@ export const ComponentWithProperties = defineComponent({
101101
}
102102
});
103103

104-
export const ComponentWithMethods = defineComponent({
104+
export const ComponentWithoutProperties = defineComponent({
105105
template: `
106106
<div>
107-
<ce-with-methods id="wc"
108-
:test.attr="true"
109-
></ce-with-methods>
107+
<ce-without-properties id="wc"
108+
:amethod.attr="method"
109+
:agetter.attr="getter"
110+
:areadonly.attr="readonly"
111+
></ce-without-properties>
110112
</div>
111-
`
113+
`,
114+
data: function () {
115+
return {
116+
method: 'method',
117+
getter: 'getter',
118+
readonly: 'readonly',
119+
}
120+
}
112121
})
113122

114123
export const ComponentWithUnregistered = defineComponent({

0 commit comments

Comments
 (0)