Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upJest tests fail: Using the "styled" tag in runtime is not supported. #636
Comments
|
I'm also facing this error with Jest + Linaria + React + TypeScript, using module.exports = {
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"],
testPathIgnorePatterns: [`node_modules`],
testURL: `http://localhost`,
moduleNameMapper: {
".+\\.(css|styl|less|sass|scss)$": `identity-obj-proxy`,
},
transform: {
"^.+\\.tsx?$": `ts-jest`,
},
globals: {
__PATH_PREFIX__: ``,
"ts-jest": {
babelConfig: {
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-react",
["linaria/babel", { evaluate: true, displayName: true }],
],
},
},
},
};Environment
InvestigationI'm not sure if I'm facing the same issue as @viczhuravlev, though I suspect I am. Debugging the
From source code that looks like: import { styled } from "linaria/react";
import React from "react";
const Styled = {
Path: styled.circle`
fill: none;
stroke: var(--color);
stroke-linecap: round;
stroke-width: var(--stroke);
animation: spinnerDash 1.5s ease-in-out infinite;
`,
};
export default Styled.Path;The Gatsby and Jest-based builds have slightly different ASTs regarding line numbers, but the most significant difference appears to be the difference between the AST subtree destructed as AST Tag NodesIn these, there is the existence of a new parent object on the "use strict";
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
const react_1 = require("linaria/react");
const react_2 = __importDefault(require("react"));
const Styled = {
Path: react_1.styled.circle`
fill: none;
stroke: var(--primary);
stroke-linecap: round;
stroke-width: 8px;
`
};
const Spinner = () => <svg viewBox="0 0 50 50">
<Styled.Path cx="25" cy="25" r="20" />
</svg>;
exports.default = Spinner;This is from the whole file, which is here (gist). For comparison, the Gatsby build is here (gist). |
|
Maybe this can help: #617 |
Environment
Description
Hi! I want to change emotion to linaria, but I met a problem with testing.
I have a component with
styled.*:jest.config.js:
And when I run test, I get the problem(but with build is fine):

Please, help me, I tried different ways already
Reproducible Demo
Please clone and install the following git repo: https://github.com/viczhuravlev/gramr-ui/tree/feat/changeEmotionToLinaria