Skip to content

feat(native): add toHaveStyle #152

New issue

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

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

Already on GitHub? # to your account

Draft
wants to merge 3 commits into
base: feat/native-to-have-prop
Choose a base branch
from

Conversation

ACR1209
Copy link

@ACR1209 ACR1209 commented Jun 2, 2025

Description

This PR adds the toHaveStyle matcher for the React Native module

@ACR1209 ACR1209 requested a review from suany0805 June 2, 2025 17:23

const error = new AssertionError({
actual: this.actual,
message: `Expected element ${this.toString()} to have style ${JSON.stringify(flattenedStyle)}.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think there could be a different way of hanlding the style object to string? since that is what users will be reading when a test fails, it should be clear and readable :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like this work for us, or do you have a specific error message in mind?

Expected element <View ... /> to have style:
-"background_color": red
-"color": white

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly :) that would work


import { AssertiveStyle, StyleObject } from "./types";

export function getFlattenedStyle(style: AssertiveStyle): StyleObject {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add this in hour helpers.ts file instead of just creating a new styles.ts file for this

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants