T
tscircuit•11mo ago
<Dhairya/>

Error render phase

In my PR:https://github.com/tscircuit/core/pull/253 my tests are failing saying I cannot destructure db from this.root but w/o doing so how will I insert errors šŸ¤”
14 Replies
Seve
Seve•11mo ago
You can only access the db in a render phase, in this case you should insert it during doInitialPcbVomponentRender Youll need to indicate that the component has an error and store it on the component until that phase to insert the error You could introduce this._missingFootprintError Then insert that into the db during the doInitialPcbComponentRender
<Dhairya/>
<Dhairya/>OP•11mo ago
Thanks for help 🫔
Seve
Seve•11mo ago
no problem!!!
<Dhairya/>
<Dhairya/>OP•11mo ago
Tests are now passing : )
Seve
Seve•11mo ago
happy to review, just send me a link!
<Dhairya/>
<Dhairya/>OP•11mo ago
sure here it is https://github.com/tscircuit/core/pull/253 Thanks for the review, resolving them asap.
Seve
Seve•11mo ago
np!
<Dhairya/>
<Dhairya/>OP•11mo ago
Hi, While creating a flaky test case I need to use component.doInitialPcbComponentRender(); but while running the test I'm constantly getting these errors
tests/components/base-components/normal-component-footprint-error.test.tsx:
369 |
370 | this.schematic_component_id = schematic_component.schematic_component_id
371 | }
372 |
373 | doInitialPcbComponentRender() {
374 | const { db } = this.root!
^
TypeError: Right side of assignment cannot be destructured
at doInitialPcbComponentRender (/home/dhairya/Desktop/core/lib/components/base-components/NormalComponent.ts:374:20)
at /home/dhairya/Desktop/core/tests/components/base-components/normal-component-footprint-error.test.tsx:9:13
āœ— should insert missing footprint error when footprint is not found [0.56ms]
tests/components/base-components/normal-component-footprint-error.test.tsx:
369 |
370 | this.schematic_component_id = schematic_component.schematic_component_id
371 | }
372 |
373 | doInitialPcbComponentRender() {
374 | const { db } = this.root!
^
TypeError: Right side of assignment cannot be destructured
at doInitialPcbComponentRender (/home/dhairya/Desktop/core/lib/components/base-components/NormalComponent.ts:374:20)
at /home/dhairya/Desktop/core/tests/components/base-components/normal-component-footprint-error.test.tsx:9:13
āœ— should insert missing footprint error when footprint is not found [0.56ms]
here is my test case I've kept it very simple just to do testing:
import { expect, it } from "bun:test";
import { NormalComponent } from "lib/components";

it("should insert missing footprint error when footprint is not found", () => {
const component = new NormalComponent<any>({
componentName: "testing",
});

component.doInitialPcbComponentRender();

console.log("testing", component.root?.db);
});
import { expect, it } from "bun:test";
import { NormalComponent } from "lib/components";

it("should insert missing footprint error when footprint is not found", () => {
const component = new NormalComponent<any>({
componentName: "testing",
});

component.doInitialPcbComponentRender();

console.log("testing", component.root?.db);
});
Seve
Seve•11mo ago
can you use the normal testing pattern (the one in CREATING_TESTS.md) the issue with that unit test is the component isn't set up to render but you're calling a render method *WRITING_TESTS.md
<Dhairya/>
<Dhairya/>OP•11mo ago
Gotcha!! Will try this way
Seve
Seve•11mo ago
An ordinary <chip or <resistor /> is a type of NormalComponent, i would recommend just creating a simple resistor <resistor resistance="1k" footprint="0402" /> and logging to make sure the function is called
<Dhairya/>
<Dhairya/>OP•11mo ago
Added the tests : ) Now its working good
Seve
Seve•11mo ago
nice work!!!
<Dhairya/>
<Dhairya/>OP•11mo ago
Thank you so much, your review is needed in this one too https://github.com/tscircuit/easyeda-converter/pull/109

Did you find this page helpful?