/** * @jest-environment jsdom */ import { Application } from "stimulus"; import variant_controller from "controllers/variant_controller"; describe("VariantController", () => { beforeAll(() => { // Requires global var from page global.ofn_available_units_sorted = { weight: { "1.0": { name: "g", system: "metric" }, "1000.0": { name: "kg", system: "metric" }, "1000000.0": { name: "T", system: "metric" }, }, volume: { 0.001: { name: "mL", system: "metric" }, "1.0": { name: "L", system: "metric" }, 4.54609: { name: "gal", system: "imperial" }, "1000.0": { name: "kL", system: "metric" }, }, }; const mockedT = jest.fn(); mockedT.mockImplementation((string, opts) => string + ", " + JSON.stringify(opts)); global.I18n = { t: mockedT }; const application = Application.start(); application.register("variant", variant_controller); }); afterAll(() => { delete global.I18n; }); describe("variant_unit_with_scale", () => { beforeEach(() => { document.body.innerHTML = `