Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Received true for a non-boolean attribute jsx even with ["styled-jsx/babel-test"] #838

Open
GermanJablo opened this issue Oct 7, 2023 · 0 comments

Comments

@GermanJablo
Copy link

When I run my tests in Vitest using the jsdom environment I receive the error:

Warning: Received true for a non-boolean attribute jsx.

According to the readme, this error is fixed with styled-jsx/babel-test, but it is not working for me.

vitest.config.ts

import { defineConfig } from "vite";
import { loadEnvConfig } from "@next/env";

loadEnvConfig(process.cwd());

export default defineConfig({
  test: {
    environment: "jsdom",
  },
});

Sample.test.tsx

import { createRoot } from "react-dom/client";
import * as ReactTestUtils from "react-dom/test-utils";
import { expect, test } from "vitest";

function Hello() {
	return (
	  <div>
		Hello
		<style jsx global>
		  {`
			div {
			  color: red;
			}
		  `}
		</style>
	  </div>
	);
  }

const root = document.createElement("div");
document.body.appendChild(root);
ReactTestUtils.act(() => {
  createRoot(root).render(
    <Hello />
  );
});

test("Hello", () => {
  expect(root.innerHTML).toBe("<div>Hello</div>");
});

.babelrc

{
  "presets": ["next/babel", "@babel/preset-typescript"],
  "env": {
    "test": {
      "plugins": ["styled-jsx/babel-test"]
    }
  }
}

Environment

  • Next: 13.4.19
  • OS: Windows 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant