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

fix: add a convertCssObject to create a valid style object within the toHaveStyle. #591

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ludacirs
Copy link

What:

I created convertCssObject that assigns correct properties and values, and called getStyleDeclaration before it.

Why:

In the haveToStyle method, when given a property is in camelCase and the value is a number, there was a bug where incorrect test cases were passing due to internal comparison of empty strings.

so, the following tests pass.

// passed
const {container} = render(`<div class="border" style="border-width: 2px;/>`)
expect(container.querySelector('.border')).toHaveStyle({ borderWidth: '' })

// passed
const {container} = render(`<div class="border" style="border-width: 2px;/>`)
expect(container.querySelector('.border')).toHaveStyle({ borderWidth: 1 })

// passed
const {container} = render(`<div class="border" style="border-width: 2px;/>`)
expect(container.querySelector('.border')).toHaveStyle({ borderWidth: '2' })

I provided more detailed analysis in a comment on the relevant issue.

How:

When a number is passed as a value, I checked if the property requires the 'px' unit, and if so, appended 'px'. To prevent getPropertyValue function from returning an empty string when encountering camelCase, I converted properties to snake-case, excluding custom properties.

Checklist:

  • Documentation
  • tests
  • Updated Type Definitions
  • Ready to be merged

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

Successfully merging this pull request may close these issues.

1 participant