Skip to content

Commit dc11f9e

Browse files
authored
test(decorators): add tests for decorated static props (#5314)
* test(wire): add tests for wired static prop/method Also add more helpful error message. * test(api): add karma test for static api prop * test(api): add karma test for static tracked prop * test(karma): loosen regex for error message
1 parent 5487335 commit dc11f9e

File tree

19 files changed

+120
-4
lines changed

19 files changed

+120
-4
lines changed

packages/@lwc/engine-core/src/framework/decorators/register.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export function registerDecorators(
254254
validateMethodDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
255255
}
256256
if (isUndefined(descriptor)) {
257-
throw new Error();
257+
throw new Error(`Missing descriptor for wired method "${fieldOrMethodName}".`);
258258
}
259259
wiredMethods[fieldOrMethodName] = descriptor;
260260
storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
An empty error occurred?!
1+
Missing descriptor for wired method "sym".
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"entry": "x/wire"
3+
}

packages/@lwc/engine-server/src/__tests__/fixtures/wire/static-field/error.txt

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<fixture-test>
2+
<template shadowrootmode="open">
3+
wired field value: {
4+
key1: foo,
5+
key2: [fixed,array],
6+
}
7+
</template>
8+
</fixture-test>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default class adapter {
2+
constructor(dataCallback) {
3+
this.dc = dataCallback;
4+
}
5+
6+
connect() {}
7+
8+
update(config) {
9+
// JSON.stringify serializes differently for engine-server/ssr-compiler, so we do it manually
10+
const output = Object.entries(config)
11+
.sort(([a], [b]) => a.localeCompare(b))
12+
.map(([key, value]) => ` ${key}: ${JSON.stringify(value)},`)
13+
.join('\n')
14+
// Quotes are encoded as &quot; in the output, which makes it harder to read...
15+
.replace(/"/g, '');
16+
17+
this.dc(`{\n${output}\n}`);
18+
}
19+
20+
disconnect() {}
21+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
wired field value: {wiredProp}
3+
</template>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { wire, LightningElement } from 'lwc';
2+
import WireAdapter from 'x/adapter';
3+
export default class Test extends LightningElement {
4+
@wire(WireAdapter, { key1: '$prop1', key2: ['fixed', 'array'] })
5+
// Accidentally marking a wired prop as static doesn't matter
6+
static wiredProp;
7+
8+
prop1 = 'foo';
9+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"entry": "x/wire",
3+
"ssrFiles": {
4+
"error": "error-ssr.txt"
5+
}
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance.wiredMethod is not a function

0 commit comments

Comments
 (0)