From b07e834997a4cae8f95afd1f54bc0f04bd047310 Mon Sep 17 00:00:00 2001 From: delfino Date: Fri, 14 Feb 2025 14:01:04 +0000 Subject: [PATCH] fixing forceAppendix null check & adding test --- d2js/d2wasm/functions.go | 2 +- d2js/js/test/unit/basic.test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/d2js/d2wasm/functions.go b/d2js/d2wasm/functions.go index 0823f04fa..149685592 100644 --- a/d2js/d2wasm/functions.go +++ b/d2js/d2wasm/functions.go @@ -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) } diff --git a/d2js/js/test/unit/basic.test.js b/d2js/js/test/unit/basic.test.js index 7f4b5a936..985855988 100644 --- a/d2js/js/test/unit/basic.test.js +++ b/d2js/js/test/unit/basic.test.js @@ -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(""); + 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} |");