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

Proposal: Change the way our uikit tests are structures & snapshots are generated #1

Closed
wants to merge 18 commits into from

Conversation

ChefHutch
Copy link
Owner

@ChefHutch ChefHutch commented Mar 16, 2021

All just my opinion, keen to hear yours!

Problem

  • Current snapshots have hashed classNames
  • Current snapshots don't capture styles. I'm not sure snapshotting the dom tree without styles is particularly useful, as it will not catch the kind of regressive visual changes to components that snapshots are useful for.
  • Once styles are added to the inlineSnapshots - the test files will become massive, before any other unit test has been added.
  • Tests being contained within their own folder decouples them psychologically from the building of a component.

Proposed solution

  • Separate tests into the relevant components' folder. Helps prevents tests become an afterthought and ties them to the development of that component.
> pancake-uikit
   > src
      > components
         > Component
              > index.tsx
              ...     
              > index.test.tsx
              > __snapshots__
  • Use .toMatchSnapshot() instead of toMatchInlineSnapshot()
  • Import jest-styled-components to capture styles in snapshots (so that inadvertant style changes are caught), and remove hashes from classNames
  • Added some generic component tests for tabMenu in order to give additional context

Next steps

  • ✅ If this approach is agreed, I'll make a PR updating this across all testing in the uikit.
  • Including importing "jest-styled-components" within renderWithTheme, rather than the specific test.

@ChefHutch ChefHutch changed the title Idea: Change the way our snapshots are generated Proposal: Change the way our uikit tests are structures & snapshots are generated Mar 17, 2021
@ChefHutch ChefHutch marked this pull request as ready for review March 17, 2021 10:31
@ChefHutch ChefHutch self-assigned this Mar 17, 2021
@hachiojidev
Copy link

@ChefHutch

Import jest-styled-components to capture styles in snapshots (so that inadvertant style changes are caught), and remove hashes from classNames

We already do this in setupTests.js

ChefHutch added a commit that referenced this pull request Mar 18, 2021
ChefHutch added a commit that referenced this pull request Mar 18, 2021
ChefHutch added a commit that referenced this pull request Mar 18, 2021
@ChefHutch
Copy link
Owner Author

@hachiojidev

Import jest-styled-components to capture styles in snapshots (so that inadvertant style changes are caught), and remove hashes from classNames

We already do this in setupTests.js

So we do! I'm not sure it's working? We'd see styles in our snapshots and non-hashed classnames if it was. I've spent too much time trying to debug it this morning, sunken cost fallacy kicking in - will just make an issue and leave it.

@ChefHutch ChefHutch changed the base branch from feature/tab-bar to feature/tab-bar-rebase-2 March 18, 2021 12:12
@ChefHutch
Copy link
Owner Author

Closing as per Slack discussion. Made an issue for the fact that setupTests.js' jest-styled-components import isn't firing pancakeswap#20

@ChefHutch ChefHutch closed this Mar 18, 2021
ChefHutch added a commit that referenced this pull request Mar 19, 2021
…cakeswap#19)

* chore(tab-menu): Rough component setup

* chore(tab-menu): Testing user

* style(styled-tab): V rough component layout and styles

* style(styled-tab): Specific styles applied

* style(styled-tab): Refinding styles and element types

* fix(tab-menu): Tidy interfaces and props being passed to tab-bar

* test(tab-menu): Added snapshot

* style(tab-menu): Update comp names and add extra stories

* chore(tab-menu): Remove unused commented code

* test(tab-menu): Fix incorrect test import

* style(tab-menu): Add width % handling below 576px

* test(tab-menu): Update snaps

* test(tab-menu): Remove test files from this PR - see #1 for proposal on implementing tests

* style(tab-menu): Move away from % widths and towards flex-grow

* style(tab-menu): Set 8px min padding to tab

* style(tab-menu): Fix import order

* style(tab-menu): Remove styled tabmenu comp and move into tabmenu

* style(tab-menu): Change breakpoint for style change to 853px

* test(tab-menu): Add tabmenu test file

* test(tab-menu): Remove duplicate setupTests

* fix(tab-menu): Del & regenerate yarn.lock
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.

4 participants