fixing forceAppendix null check & adding test

This commit is contained in:
delfino 2025-02-14 14:01:04 +00:00
parent 0963cafeda
commit b07e834997
No known key found for this signature in database
GPG key ID: CFE0DD6A770BF48C
2 changed files with 11 additions and 1 deletions

View file

@ -282,7 +282,7 @@ func Render(args []js.Value) (interface{}, error) {
if err != nil {
return nil, &WASMError{Message: fmt.Sprintf("render failed: %s", err.Error()), Code: 500}
}
if input.Opts != nil && *input.Opts.ForceAppendix {
if input.Opts != nil && *&input.Opts.ForceAppendix != nil && *input.Opts.ForceAppendix {
out = appendix.Append(input.Diagram, renderOpts, ruler, out)
}

View file

@ -45,6 +45,16 @@ describe("D2 Unit Tests", () => {
await d2.worker.terminate();
}, 20000);
test("force appendix works", async () => {
const d2 = new D2();
const result = await d2.compile("x: {tooltip: x appendix}", { forceAppendix: true });
const svg = await d2.render(result.diagram, { forceAppendix: true });
expect(svg).toContain("<svg");
expect(svg).toContain("</svg>");
expect(svg).toContain('class="appendix"');
await d2.worker.terminate();
}, 20000);
test("latex works", async () => {
const d2 = new D2();
const result = await d2.compile("x: |latex \\frac{f(x+h)-f(x)}{h} |");