Skip to content

Commit

Permalink
loop throws helpful error message if value is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
paldepind committed Aug 18, 2019
1 parent 5177ae4 commit 155fc84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,14 @@ class LoopComponent<O> extends Component<O, {}> {
parent,
destroyed
);
const returned: (keyof O)[] = <any>Object.keys(output);
for (const name of returned) {
const needed = Object.keys(placeholderObject);
for (const name of needed) {
if (name === "destroyed") {
continue;
}
if (output[name] === undefined) {
throw new Error(`The property ${name} is missing.`);
}
placeholderObject[name].replaceWith(output[name]);
}
return { available: output, output: {} };
Expand Down
10 changes: 10 additions & 0 deletions test/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ describe("component specs", () => {
expect(dom).to.have.length(0);
expect(toplevel).to.equal(true);
});
it("throws helpful error is a reactive is missing", () => {
const c = loop((props: { foo: H.Behavior<string> }) => {
// Access something that isn't there
(props as any).bar;
return div([dynamic(props.foo)]).output((_) => ({
foo: H.Behavior.of("foo")
}));
});
assert.throws(() => testComponent(c), /bar/);
});
});
});

Expand Down

0 comments on commit 155fc84

Please sign in to comment.