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
enyeal added a commit to STAPLE-verse/STAPLE that referenced this issue Oct 19, 2024
… errors.

The main issue is that in some components there is some styling declared as <style  jsx>, but when running the tests for these components we get the warning
        “Warning: Received `true` for a non-boolean attribute `jsx`”.
 If we change to <style  jsx = “true”>, the warning is fixed but then we get a compile error:
        Type error: Type 'string' is not assignable to type 'boolean | undefined'.

I do not understand completely why not setting this variable is giving the warning, but some explanation and suggestions for fixes are provided in the following links:

vitejs/vite#6136
vercel/styled-jsx#838
https://github.com/vercel/styled-jsx#rendering-in-tests

I tried all of them, but they did not fix the warning. However, in the end, by just removing the jsx tag, it seems to work ( the app compiles and not warnings).
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