Skip to content

Commit dbfc970

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

File tree

11 files changed

+69
-45
lines changed

11 files changed

+69
-45
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+
method() {
21+
return 'method';
22+
}
23+
24+
get getter() {
25+
return 'getter';
2226
}
2327

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

2832
}
2933

30-
customElements.define('ce-with-methods', CEWithMethods);
34+
Object.defineProperty(CEWithoutProperties.prototype, 'readonly', {
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('method')).to.eql('method');
158+
expect(wc.getAttribute('getter')).to.eql('getter');
159+
expect(wc.getAttribute('readonly')).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 method="method" getter="getter" readonly="readonly" id="wc"></ce-without-properties>
113113
</div>
114114
`
115115
})
116-
export class ComponentWithMethods {}
116+
export class ComponentWithoutProperties {}
117117

118118
@Component({
119119
template: `

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('method')).to.eql('method');
212+
expect(wc.getAttribute('getter')).to.eql('getter');
213+
expect(wc.getAttribute('readonly')).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 method="method" getter="getter" readonly="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('method')).to.eql('method');
133+
expect(wc.getAttribute('getter')).to.eql('getter');
134+
expect(wc.getAttribute('readonly')).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('method')).to.eql('method');
156+
expect(wc.getAttribute('getter')).to.eql('getter');
157+
expect(wc.getAttribute('readonly')).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+
:method.attr="method"
109+
:getter.attr="getter"
110+
:readonly.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)