Repository: excalidraw/excalidraw
File: src/tests/packages/utils.test.ts (TypeScript)

Code before:
  version: 120,
  versionNonce: 1188004276,
  isDeleted: false,
  boundElementIds: null,
  ...overrides,
});
const diagramFactory = ({ overrides = {}, elementOverrides = {} } = {}) => ({
  type: "excalidraw",
  version: 2,
  source: "https://excalidraw.com",
  elements: [
    elementFactory({ type: "rectangle", ...elementOverrides }),
    elementFactory({ type: "diamond", ...elementOverrides }),
    elementFactory({ type: "ellipse", ...elementOverrides }),
  ],
  appState: {
    viewBackgroundColor: "#ffffff",
    gridSize: null,
  },
  ...overrides,
});

describe("exportToCanvas", () => {
  const EXPORT_PADDING = 10;
  test("with default arguments", () => {
    const canvas = utils.exportToCanvas({
      ...diagramFactory({ elementOverrides: { width: 100, height: 100 } }),
      getDimensions: (width, height) => ({ width, height, scale: 1 }),
    });

    expect(canvas.width).toBe(100 + 2 * EXPORT_PADDING);
    expect(canvas.height).toBe(100 + 2 * EXPORT_PADDING);
  });
  test("when custom width and height", () => {
    const canvas = utils.exportToCanvas({
      ...diagramFactory({ elementOverrides: { width: 100, height: 100 } }),
      getDimensions: () => ({ width: 200, height: 200, scale: 1 }),
    });

    expect(canvas.width).toBe(200);
    expect(canvas.height).toBe(200);
  });
});
describe("exportToBlob", () => {
  describe("mime type", () => {
    afterEach(jest.restoreAllMocks);

    it("should change image/jpg to image/jpeg", async () => {
      const blob = await utils.exportToBlob({
        ...diagramFactory(),
        getDimensions: (width, height) => ({ width, height, scale: 1 }),

Review comment (suggestion):
```suggestion
    
    it("should default to image/png", async () => {
```
lets add new line between individual specs for better readability

Code after:

  it("when custom width and height", () => {
    const canvas = utils.exportToCanvas({
      ...diagramFactory({ elementOverrides: { width: 100, height: 100 } }),
      getDimensions: () => ({ width: 200, height: 200, scale: 1 }),
    });

    expect(canvas.width).toBe(200);
    expect(canvas.height).toBe(200);
  });
});

describe("exportToBlob", () => {
  describe("mime type", () => {
    afterEach(jest.restoreAllMocks);

    it("should change image/jpg to image/jpeg", async () => {
      const blob = await utils.exportToBlob({
        ...diagramFactory(),
        getDimensions: (width, height) => ({ width, height, scale: 1 }),
        mimeType: "image/jpg",
      });
      expect(blob?.type).toBe("image/jpeg");
    });

    it("should default to image/png", async () => {
      const blob = await utils.exportToBlob({
        ...diagramFactory(),
      });
      expect(blob?.type).toBe("image/png");
    });

    it("should warn when using quality with image/png", async () => {
      const consoleSpy = jest
        .spyOn(console, "warn")
        .mockImplementationOnce(() => void 0);

      await utils.exportToBlob({
        ...diagramFactory(),
        mimeType: "image/png",
        quality: 1,
      });

      expect(consoleSpy).toHaveBeenCalledWith(
        '"quality" will be ignored for "image/png" mimeType',
      );
    });
  });
});

describe("exportToSvg", () => {