Skip to content

Commit 043eb29

Browse files
chore: remove overkill shadow test
1 parent 8edc472 commit 043eb29

File tree

5 files changed

+23
-57
lines changed

5 files changed

+23
-57
lines changed

packages/@lwc/integration-karma/test-hydration/context/index.spec.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,32 @@ function assertCorrectContext(snapshot) {
6161
}
6262

6363
function assertContextShadowed(snapshot) {
64-
// Change the parents context value and then check to make sure the grandparents value has been shadowed
65-
snapshot.components.firstParent.context.value.value = 'shadow value';
64+
const grandparentContext = snapshot.components.grandparent.context;
65+
const firstParentContext = snapshot.components.firstParent.context;
66+
const childOfFirstParentContext = snapshot.components.childOfFirstParent.context;
6667

67-
Object.entries(snapshot.components).forEach(([key, component]) => {
68-
if (key === 'firstParent' || key === 'childOfFirstParent') {
69-
expect(component.context.value.value)
70-
.withContext(`${component.tagName} should have the correct context after shadowing`)
71-
.toBe('shadow value');
72-
} else {
73-
expect(component.context.value.value)
74-
.withContext(`${component.tagName} should have the initial context after shadowing`)
75-
.toBe('grandparent provided value');
76-
}
77-
});
68+
expect(childOfFirstParentContext.providedContextSignal)
69+
.withContext(
70+
`${snapshot.components.childOfFirstParent.tagName} should have been provided with the parent's context and not that of the grandparent`
71+
)
72+
.toBe(firstParentContext);
73+
74+
expect(firstParentContext.providedContextSignal)
75+
.withContext(
76+
`${snapshot.components.firstParent.tagName} should have been provided with the parent's context and not that of the grandparent`
77+
)
78+
.toBe(grandparentContext);
7879
}
7980

8081
function assertContextDisconnected(target, snapshot) {
8182
Object.values(snapshot.components).forEach(
8283
(component) =>
8384
(component.disconnect = () => {
84-
expect(component.context.disconnectContextCalled)
85-
.withContext(`${component.tagName} should have disconnected the context`)
86-
.toBeTrue();
87-
88-
expect(component.context.disconnectProvidedComponent)
85+
expect(component.context.disconnectProvidedComponent.hostElement)
8986
.withContext(
9087
`The context of ${component.tagName} should have been disconnected with the correct component`
9188
)
92-
.toBe(component.context.connectProvidedComponent);
89+
.toBe(component);
9390
})
9491
);
9592
target.showTree = false;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<template>
2-
<div>{context.value.value}, {anotherContext.value.value}</div>
2+
<div>{context.value}, {anotherContext.value}</div>
33
</template>

packages/@lwc/integration-karma/test-hydration/context/x/contextManager/contextManager.js

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,13 @@ const trustedContext = new WeakSet();
77
setTrustedContextSet(trustedContext);
88
setContextKeys({ connectContext, disconnectContext });
99

10-
class MockSignal {
11-
subscribers = new Set();
12-
13-
constructor(initialValue) {
14-
this._value = initialValue;
15-
}
16-
17-
set value(newValue) {
18-
this._value = newValue;
19-
this.notify();
20-
}
21-
22-
get value() {
23-
return this._value;
24-
}
25-
26-
subscribe(onUpdate) {
27-
this.subscribers.add(onUpdate);
28-
}
29-
30-
notify() {
31-
for (const subscriber of this.subscribers) {
32-
subscriber(this.value);
33-
}
34-
}
35-
}
36-
3710
class MockContextSignal {
38-
disconnectContextCalled = false;
3911
connectProvidedComponent;
4012
disconnectProvidedComponent;
13+
providedContextSignal;
4114

4215
constructor(initialValue, contextDefinition, fromContext) {
43-
this.value = new MockSignal(initialValue);
16+
this.value = initialValue;
4417
this.contextDefinition = contextDefinition;
4518
this.fromContext = fromContext;
4619
trustedContext.add(this);
@@ -52,17 +25,13 @@ class MockContextSignal {
5225

5326
if (this.fromContext) {
5427
runtimeAdapter.consumeContext(this.fromContext, (providedContextSignal) => {
55-
this.value.value = providedContextSignal.value.value;
56-
// Simple subscription is required to validate shadowed context
57-
providedContextSignal.value.subscribe(
58-
(updatedValue) => (this.value.value = updatedValue)
59-
);
28+
this.providedContextSignal = providedContextSignal;
29+
this.value = providedContextSignal.value;
6030
});
6131
}
6232
}
6333
[disconnectContext](component) {
6434
this.disconnectProvidedComponent = component;
65-
this.disconnectContextCalled = true;
6635
}
6736
}
6837

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>{context.value.value}, {anotherContext.value.value}</div>
2+
<div>{context.value}, {anotherContext.value}</div>
33
<x-parent></x-parent>
44
<x-parent></x-parent>
55
</template>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<template>
2-
<div>{context.value.value}, {anotherContext.value.value}</div>
2+
<div>{context.value}, {anotherContext.value}</div>
33
<x-child></x-child>
44
</template>

0 commit comments

Comments
 (0)