Skip to content

Commit a7d3873

Browse files
johnjenkinsJohn Jenkins
and
John Jenkins
authoredJan 21, 2025
fix(test): stop re-running prototype augment in spec tests. (#6105)
Co-authored-by: John Jenkins <john.jenkins@nanoporetech.com>
1 parent 07dcfa8 commit a7d3873

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed
 

‎src/runtime/proxy-component.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export const proxyComponent = (
2929
): d.ComponentConstructor => {
3030
const prototype = (Cstr as any).prototype;
3131

32+
if (BUILD.isTesting) {
33+
if (prototype.done) {
34+
// @ts-expect-error - we don't want to re-augment the prototype. This happens during spec tests.
35+
return;
36+
}
37+
prototype.done = true;
38+
}
39+
3240
/**
3341
* proxy form associated custom element lifecycle callbacks
3442
* @ref https://web.dev/articles/more-capable-form-controls#lifecycle_callbacks
@@ -113,9 +121,9 @@ export const proxyComponent = (
113121
// the element is not constructing
114122
(ref && ref.$flags$ & HOST_FLAGS.isConstructingInstance) === 0 &&
115123
// the member is a prop
116-
(cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Prop) !== 0 &&
124+
(memberFlags & MEMBER_FLAGS.Prop) !== 0 &&
117125
// the member is not mutable
118-
(cmpMeta.$members$[memberName][0] & MEMBER_FLAGS.Mutable) === 0
126+
(memberFlags & MEMBER_FLAGS.Mutable) === 0
119127
) {
120128
consoleDevWarn(
121129
`@Prop() "${memberName}" on <${cmpMeta.$tagName$}> is immutable but was modified from within the component.\nMore information: https://stenciljs.com/docs/properties#prop-mutability`,

‎src/runtime/test/prop-warnings.spec.tsx

+36
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { Component, h, Method, Prop } from '@stencil/core';
22
import { newSpecPage } from '@stencil/core/testing';
33

4+
@Component({
5+
tag: 'shared-cmp',
6+
shadow: true,
7+
})
8+
class SharedCmp {
9+
@Prop() a = 'Boom!';
10+
11+
render() {
12+
return `${this.a}`;
13+
}
14+
}
15+
416
describe('prop', () => {
517
const spy = jest.spyOn(console, 'warn').mockImplementation();
618

@@ -89,4 +101,28 @@ describe('prop', () => {
89101
expect(root).toEqualHtml('<cmp-a>2</cmp-a>');
90102
expect(spy).not.toHaveBeenCalled();
91103
});
104+
105+
it('should not show warning when component is used across multiple tests - first time', async () => {
106+
const { root, waitForChanges } = await newSpecPage({
107+
components: [SharedCmp],
108+
html: `<shared-cmp></shared-cmp>`,
109+
});
110+
111+
root.a = 'Bam!';
112+
await waitForChanges();
113+
114+
expect(spy).not.toHaveBeenCalled();
115+
});
116+
117+
it('should not show warning when component is used across multiple tests - second time', async () => {
118+
const { root, waitForChanges } = await newSpecPage({
119+
components: [SharedCmp],
120+
html: `<shared-cmp></shared-cmp>`,
121+
});
122+
123+
root.a = 'Boom!';
124+
await waitForChanges();
125+
126+
expect(spy).not.toHaveBeenCalled();
127+
});
92128
});

0 commit comments

Comments
 (0)