Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Testing pure UI components with multiple props variations #796

Open
avg0043 opened this issue Mar 11, 2020 · 1 comment
Open

Testing pure UI components with multiple props variations #796

avg0043 opened this issue Mar 11, 2020 · 1 comment

Comments

@avg0043
Copy link

avg0043 commented Mar 11, 2020

Hi !
I have to test a library of pure presentational components. In general, the components receive props like: isDisabled, isRounded... which only shows/hide html elements or add some class names.

For this reason, I think that the best approach to test this is using snapshots.
Example component:

const Button = props => {
  const {
    children,
    isDisabled,
    isRounded,
    isSlim,
    icon,
    extraClass
  } = props

  const classes = cx(
    `clc-button`,
    {
      'clc-button--disabled': isDisabled,
      'clc-button--rounded': isRounded,
      'clc-button--slim': isSlim,
    },
    extraClass,
  )

  return (
    <button className={classes}>
      {icon && <Icon type={icon} />}
      {children && <span className="clc-button-text">{children}</span>}
    </button>
  )
}

But my main question is:
¿Should I create a snapshot test per each prop combination?

<Button isDisabled={true} /> (snapshot 1)
<Button isRounded={true} /> (snapshot 2)
...

¿Or should I create an only one general snapshot test sending the most props possible?

<Button isDisabled={true} isRounded={true} isSlim={true} icon="ball" /> (snapshot 1)

Thanks! :)

@avg0043
Copy link
Author

avg0043 commented Mar 11, 2020

As additional question, ¿should I add the styles to the snapshots too?
My components library is using scss styles, so if true, ¿which library should I use to integrate into the snapshotSerializers jest config?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant