Forum Discussion

jubinsoni's avatar
jubinsoni
Icon for Solution Sage rankSolution Sage
18 hours ago

Unit testing a custom visual: how do you test update() and formatting settings?

Hi everyone,

I would like to hear how others structure automated tests for a custom visual built with the pbiviz tools. My current idea is to keep the rendering logic in plain functions that take a view model, so they can be tested without the Power BI host, and to test the update() path with a mocked data view.

// viewModel.ts - pure function, easy to test
export function toViewModel(categories: string[], values: number[]) {
  return categories.map((c, i) => ({ category: c, value: values[i] ?? 0 }));
}

// viewModel.spec.ts (Jest)
import { toViewModel } from "./viewModel";

test("pads missing values with zero", () => {
  expect(toViewModel(["a", "b"], [1])).toEqual([
    { category: "a", value: 1 },
    { category: "b", value: 0 },
  ]);
});

Questions:

  • Which test setup do you use for the visual itself (Jest with jsdom, Karma, the powerbi-visuals-utils-testutils helpers), and what has been painful?
  • How do you build realistic data views for tests, including empty data, many categories and null values?
  • Do you test the formatting settings model (cards and slices) separately, and how do you check that the format pane maps to the capabilities file?

Thanks in advance.

No RepliesBe the first to reply