Files
test-repo/tests/unit/is-empty-doc.js
T
Seiyaandfisker Cheung 97d8115d18 Resolve rule of fill violation in JSX and add assertion. (#16700)
* add stricter assertion into fill()

* resolve rule of fill issue. some comments and naming can be problematic.

* cleanup

* update comments

* rename printWhitespace -> printStringOrLine

* refine isValidSeparator() a bit

* remove FIXME comment for fixed issue

* fix idempotency problem in MDX

* add changelog

* rename assertDocFill() -> assertDocFillParts()

* add test for assertDocFillParts()

* replace cleanDoc(doc) === "" by isEmptyDoc(doc)

* Update src/document/utils/assert-doc.js

Co-authored-by: fisker Cheung <lionkay@gmail.com>

---------

Co-authored-by: fisker Cheung <lionkay@gmail.com>
2025-01-21 13:09:32 +09:00

31 lines
1.0 KiB
JavaScript

import {
breakParent,
fill,
group,
line,
lineSuffix,
} from "../../src/document/builders.js";
import { cleanDoc, isEmptyDoc } from "../../src/document/utils.js";
it.each([
{ name: "empty string", doc: "" },
{ name: "non-empty string", doc: "a" },
{ name: "empty array", doc: [] },
{ name: "nested empty array", doc: [[[]]] },
{ name: "array with empty string", doc: [""] },
{ name: "non-empty array", doc: ["", "a", ""] },
{ name: "empty group", doc: group([]) },
{ name: "nested empty group", doc: group([group([])]) },
{ name: "group with empty string", doc: group([""]) },
{ name: "non-empty group", doc: group(["a"]) },
{ name: "empty fill", doc: fill([]) },
{ name: "fill with empty content", doc: fill([["", ""]]) },
{ name: "non-empty fill", doc: fill(["", line]) },
{ name: "empty line", doc: line },
{ name: "empty lineSuffix", doc: lineSuffix([]) },
{ name: "breakParent", doc: breakParent },
])("isEmptyDoc: $name", ({ doc }) => {
const expected = cleanDoc(doc) === "";
expect(isEmptyDoc(doc)).toBe(expected);
});