Skip to content

Commit 451179c

Browse files
feat: api + wire test
1 parent ab43d99 commit 451179c

File tree

9 files changed

+68
-30
lines changed

9 files changed

+68
-30
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"entry": "x/wire"
2+
"entry": "x/parent",
3+
"ssrFiles": {
4+
"error": "error-v2.txt",
5+
"expected": "expected-v2.html"
6+
}
37
}

packages/@lwc/engine-server/src/__tests__/fixtures/wire/invocation-sequence/method/error-v2.txt

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<fixture-test>
2+
<template shadowrootmode="open">
3+
<x-wire>
4+
<template shadowrootmode="open">
5+
<div>
6+
Invocation sequence:
7+
1. adapter: connect()
8+
2. component: getApiValue(undefined)
9+
3. adapter: update()
10+
4. component: wiredMethod(wire provided value)
11+
5. component: setApiValue(wire provided value)
12+
6. component: setApiValue(parent provided (initial) value)
13+
</div>
14+
<div>
15+
Api Value: parent provided (initial) value
16+
</div>
17+
</template>
18+
</x-wire>
19+
</template>
20+
</fixture-test>
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<fixture-test>
22
<template shadowrootmode="open">
3-
<div>
4-
Invocation sequence:
5-
1. adapter connect()
6-
2. adapter update()
7-
3. component wiredMethod()
8-
</div>
9-
<div>
10-
Wired prop: {
11-
key1: foo,
12-
}
13-
</div>
3+
<x-wire>
4+
<template shadowrootmode="open">
5+
<div>
6+
Invocation sequence:
7+
1. component: setApiValue(parent provided value)
8+
2. adapter: connect()
9+
3. component: getApiValue(parent provided value)
10+
4. adapter: update()
11+
5. component: wiredMethod(wire provided value)
12+
6. component: setApiValue(wire provided value)
13+
</div>
14+
<div>
15+
Api Value: wire provided value
16+
</div>
17+
</template>
18+
</x-wire>
1419
</template>
1520
</fixture-test>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<x-wire api-value={apiValue}></x-wire>
3+
</template>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { LightningElement } from 'lwc';
2+
3+
export default class Parent extends LightningElement {
4+
apiValue = 'parent provided (initial) value';
5+
}

packages/@lwc/engine-server/src/__tests__/fixtures/wire/invocation-sequence/method/modules/x/wire/adapter.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,12 @@ export class adapter {
66
}
77

88
connect() {
9-
invocationSequence.push('adapter connect()');
9+
invocationSequence.push('adapter: connect()');
1010
}
1111

12-
update(config) {
13-
invocationSequence.push('adapter update()');
14-
// JSON.stringify serializes differently for engine-server/ssr-compiler, so we do it manually
15-
const output = Object.entries(config)
16-
.sort(([a], [b]) => a.localeCompare(b))
17-
.map(([key, value]) => ` ${key}: ${JSON.stringify(value)},`)
18-
.join('\n')
19-
// Quotes are encoded as &quot; in the output, which makes it harder to read...
20-
.replace(/"/g, '');
21-
22-
this.dc(`{\n${output}\n}`);
12+
update() {
13+
invocationSequence.push('adapter: update()');
14+
this.dc('wire provided value');
2315
}
2416

2517
disconnect() {}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<template>
22
<div>Invocation sequence: {invocationSequence}</div>
3-
<div>Wired prop: {externalProp}</div>
3+
<div>Api Value: {apiValue}</div>
44
</template>

packages/@lwc/engine-server/src/__tests__/fixtures/wire/invocation-sequence/method/modules/x/wire/wire.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
import { LightningElement, wire } from 'lwc';
1+
import { LightningElement, wire, api } from 'lwc';
22

33
import { adapter, invocationSequence } from './adapter';
44

55
export default class Wire extends LightningElement {
6-
prop = 'foo';
6+
@api
7+
set apiValue(value) {
8+
invocationSequence.push(`component: setApiValue(${value})`);
9+
this._apiValue = value;
10+
}
11+
12+
get apiValue() {
13+
invocationSequence.push(`component: getApiValue(${this._apiValue})`);
14+
return this._apiValue;
15+
}
716

8-
@wire(adapter, { key1: '$prop' })
17+
@wire(adapter, { apiValue: '$apiValue' })
918
wiredMethod(value) {
10-
invocationSequence.push('component wiredMethod()');
11-
this.externalProp = value;
19+
invocationSequence.push(`component: wiredMethod(${value})`);
20+
this.apiValue = value;
1221
}
1322

1423
get invocationSequence() {

0 commit comments

Comments
 (0)