Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export function registerDecorators(
validateMethodDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
}
if (isUndefined(descriptor)) {
throw new Error();
throw new Error(`Missing descriptor for wired method "${fieldOrMethodName}".`);
}
wiredMethods[fieldOrMethodName] = descriptor;
storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
An empty error occurred?!
Missing descriptor for wired method "sym".
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"entry": "x/wire"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<fixture-test>
<template shadowrootmode="open">
wired field value: {
key1: foo,
key2: [fixed,array],
}
</template>
</fixture-test>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default class adapter {
constructor(dataCallback) {
this.dc = dataCallback;
}

connect() {}

update(config) {
// JSON.stringify serializes differently for engine-server/ssr-compiler, so we do it manually
const output = Object.entries(config)
.sort(([a], [b]) => a.localeCompare(b))
.map(([key, value]) => ` ${key}: ${JSON.stringify(value)},`)
.join('\n')
// Quotes are encoded as &quot; in the output, which makes it harder to read...
.replace(/"/g, '');

this.dc(`{\n${output}\n}`);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
wired field value: {wiredProp}
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { wire, LightningElement } from 'lwc';
import WireAdapter from 'x/adapter';
export default class Test extends LightningElement {
@wire(WireAdapter, { key1: '$prop1', key2: ['fixed', 'array'] })
// Accidentally marking a wired prop as static doesn't matter
static wiredProp;

prop1 = 'foo';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"entry": "x/wire",
"ssrFiles": {
"error": "error-ssr.txt"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
instance.wiredMethod is not a function
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Missing descriptor for wired method "wiredMethod".
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default class adapter {
constructor(dataCallback) {
this.dc = dataCallback;
}

connect() {}

update(config) {
// JSON.stringify serializes differently for engine-server/ssr-compiler, so we do it manually
const output = Object.entries(config)
.sort(([a], [b]) => a.localeCompare(b))
.map(([key, value]) => ` ${key}: ${JSON.stringify(value)},`)
.join('\n')
// Quotes are encoded as &quot; in the output, which makes it harder to read...
.replace(/"/g, '');

this.dc(`{\n${output}\n}`);
}

disconnect() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
wired field value: {externalProp}
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { wire, LightningElement } from 'lwc';
import WireAdapter from 'x/adapter';
export default class Test extends LightningElement {
@wire(WireAdapter, { key1: '$prop1', key2: ['fixed', 'array'] })
// Accidentally static 💣
static wiredMethod(value) {
this.externalProp = value;
}

prop1 = 'foo';
externalProp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Methods from 'x/methods';
import Inheritance from 'x/inheritance';
import NullInitialValue from 'x/nullInitialValue';
import ExtendsMixin from 'x/extendsMixin';

import StaticProperty from 'x/staticProperty';
import duplicatePropertyTemplate from 'x/duplicatePropertyTemplate';
import NoSetter from 'x/noSetter';

Expand Down Expand Up @@ -61,6 +61,15 @@ describe('properties', () => {
});
}).toThrowError();
});

it("probably shouldn't work on a static prop, but it does", () => {
const elm = createElement('x-static-property', { is: StaticProperty });
expect(StaticProperty.staticProperty).toBe('wot');
expect(elm.staticProperty).toBe(undefined);
elm.staticProperty = 'weird';
expect(StaticProperty.staticProperty).toBe('wot');
expect(elm.staticProperty).toBe('weird');
});
});

describe('getter/setter', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { LightningElement, api } from 'lwc';

export default class StaticProperty extends LightningElement {
// People probably shouldn't do this, but they can...
@api static staticProperty = 'wot';
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Properties from 'x/properties';
import SideEffect from 'x/sideEffect';
import NonObservable from 'x/nonObservable';
import SetTrackedValueToNull from 'x/setTrackedValueToNull';

import StaticProperty from 'x/staticProperty';
import duplicatePropertyTemplate from 'x/duplicatePropertyTemplate';

it('rerenders the component when a track property is updated - literal', () => {
Expand All @@ -31,6 +31,11 @@ it('rerenders the component when a track property is updated - object', () => {
});
});

it("doesn't work for decorated static props", () => {
const elm = createElement('x-static-property', { is: StaticProperty });
expect(() => elm.increment()).toThrowError(/undefined/);
});

describe('restrictions', () => {
it('logs an error when updating a track property during render', () => {
const elm = createElement('x-side-effect', { is: SideEffect });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { LightningElement, api, track } from 'lwc';

export default class Properties extends LightningElement {
@track static obj = { value: 0 };
@api increment() {
this.obj.value += 1;
}
}