Help Configuring Expo 52 with Jest and @testing-library/react-native to Test Elements with expect().toHaveStyle
@danstepanov 已经在做这个了。
开始于 2026年4月15日。
评估
这个 Issue 还没有评估数据。
描述
Hi there! 👋🏾
I’m currently working on a project with Expo 52 and trying to set up Jest testing with @testing-library/react-native. Everything works fine in development and production, but I’m having trouble running tests that involve NativeWind styles.
In my tests, I’m trying to use expect(text).toHaveStyle() to check if the styles are being applied correctly, but it's not working in the test environment.
I’ve already followed the steps in the documentation, but I’m still facing issues with applying styles during tests.
Example Code
I have the following code using useColorScheme():
import * as React from "react";
import { Text, View } from "react-native";
import { render } from "@testing-library/react-native";
const BlackViewWhiteText = () => {
return (
<View
testID="black-view"
className="bg-black flex-1 justify-center items-center"
>
<Text className="text-white">white text</Text>
</View>
);
};
it("should correct styles for black background and white text using NativeWind", () => {
const { getByText, toJSON, getByTestId } = render(<BlackViewWhiteText />);
const text = getByText("white text");
const view = getByTestId("black-view");
expect(toJSON()).toMatchSnapshot();
expect(text).toHaveProp("className");
expect(view).toHaveStyle({ color: "black" }); // same rgb(0,0,0)
expect(text).toHaveStyle({ color: "white" }); // same rgb(255,255,255)
/* expect(element).toHaveStyle()
- Expected
+ Received
- color: black;
*/
});
However, the test is not behaving as expected when it comes to checking styles, especially with the NativeWind utilities. I would appreciate any help on how to properly configure Expo 52 with Jest and @testing-library/react-native to make these tests pass.
It would also be great to have an example of the Jest configuration and how to test the useColorScheme changing dark mode.
Thanks in advance for your help!
- 主要语言
- JavaScript
- 星标
- 8.1k
- 派生
- 409
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nativewind/nativewind 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
nativewind/nativewind#1879 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
nativewind/nativewind#1878 ·
-
`withNativewind(config, { globalClassNamePolyfill: undefined })` turns the className polyfill off可能已有人在做 @EnesKartal 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
nativewind/nativewind#1877 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 85/100
nativewind/nativewind#1870 · 4 个 reaction ·
-
printUpgradeWarning crashes the app when serializing props that contain a context object with a throwing getter (e.g. React Navigation)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭needs investigation needs reproduction
难度 2/5 1-3 小时 新手友好度 65/100
nativewind/nativewind#1812 · 5 条评论 ·
查看 nativewind/nativewind 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
solana-foundation/solana-web3.js#4015 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
gramps-project/gramps-web#1604 ·
维护者通常 1 天内回复
-
enhancement good first issue hacktoberfest help wanted
难度 2/5 1-3 小时 新手友好度 85/100
BinaryBaconLabs/todo-app#18 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 66/100
sutantyo/flight-watch#32 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复