有没有一种方法可以用Jest测试Tailwind的修剪,而不必编写自定义postcss配置,只实现CRA 5创建的默认webpack配置(也实现了here)。
Tailwind似乎忽略了. test.tsx文件中的所有类,并且没有将它们包含在输出中。
以下是相关文件:
tailwind.config.js
module.exports = {
content: ["./src/**/*.{html,js,jsx,ts,tsx,test.jsx,test.tsx}"],
theme: {
extend: {},
},
plugins: [],
};
字符串
index.tsx
import React from "react";
import ReactDOM from "react-dom/client";
import "./styles/index.scss";
import App from "./Views/App/App";
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
型
index.scss
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
body {
...
}
型
App.test.tsx:
import { render, screen } from "@testing-library/react";
describe("Tailwind Pruning", () => {
test("Should include style", () => {
const expected = "rgb(220, 38, 38)";
render(<span className="text-red-600" data-testid="tailwind-test"></span>);
const dom = screen.getByTestId("tailwind-test");
const actual = getComputedStyle(dom).color;
expect(actual).toBe(expected);
});
// tailwind should fail to include the style for this test
test("Should not include style", () => {
const expected = "";
render(<span className={`${"text"}-${"red"}-${600}`} data-testid="tailwind-test"></span>);
const dom = screen.getByTestId("tailwind-test");
const actual = getComputedStyle(dom).color;
expect(actual).toBe(expected);
});
});
型
1条答案
按热度按时间zf9nrax11#
字符串