Skip to content

Commit

Permalink
patch: improve error message (#609)
Browse files Browse the repository at this point in the history
* improve error message that occurs when you put something that is not a react component inside the jsx

* add test

* Update PrimitiveComponent.ts
  • Loading branch information
ArnavK-09 authored Feb 9, 2025
1 parent 9a0c62c commit 925be9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/components/base-components/PrimitiveComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ export abstract class PrimitiveComponent<
}

add(component: PrimitiveComponent) {
if (!component.onAddToParent) {
throw new Error(
`Invalid JSX Element: Expected a React component but received "${JSON.stringify(component)}"`,
)
}
component.onAddToParent(this)
component.parent = this
this.children.push(component)
Expand Down
14 changes: 14 additions & 0 deletions tests/components/primitive-components/invalid-jsx.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test, expect } from "bun:test"
import { Circuit } from "lib"

test("snippet-import1-contribution-board", async () => {
const circuit = new Circuit()

expect(() => {
circuit.add(
<board width="10mm" height="10mm">
{1}
</board>,
)
}).toThrowError("Invalid JSX Element")
})

0 comments on commit 925be9e

Please sign in to comment.