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

Guide on creating idompotent tests using React Testing library #79

Closed
charlieforward9 opened this issue May 17, 2024 · 17 comments
Closed
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@charlieforward9
Copy link

With only a few months under my belt with BDD/TDD, I am still learning how to structure these tests to be valid and isolated from each other.

With the Feature/Scenario hierarchy, I am still figuring out how to test unique capabilities (scenarios) of a component (feature) within the same test file without having overlap between scenarios.

For example, when testing a search bar, I type abc and then check for results. In the next scenario, I would type def. However, I am having an issue where it does not reset the previous scenario and I get abcdef in the search bar. I ham including Before/AfterEachScenario hooks, but it would be nice to have some sort of auto reset if we are using the React Testing Library render method

I will continue developing and possibly make a template repo for this if I figure it out.

@amiceli
Copy link
Owner

amiceli commented May 17, 2024

vitest-cucumber is framework agnostic, so it won't provide logic for a specific framework.
In my (company or side) projects using Vue, we use hooks to set/reset components, mocks etc. Like you do ;).

I made a template repo for Vue not for React.
I don't use this framework so I like your idea !
If you do a template for React I will include it in doc and you as contributor ;).

@charlieforward9
Copy link
Author

Great, I will take this as a task, if youd like to add me as the assignee, I will have it in my task list as something to get around to when I have some extra time.

@amiceli amiceli added the documentation Improvements or additions to documentation label May 19, 2024
@charlieforward9
Copy link
Author

charlieforward9 commented May 22, 2024

CC// @saiNaruUFL will be working on this as well. Create sample with https://github.com/testing-library/react-testing-library-help

Refs:
https://testing-library.com/docs/react-testing-library/api
testing-library/react-testing-library#218

@charlieforward9
Copy link
Author

@amiceli I notice you say this repo is for

using Gherkin in your unit tests

Is there a reason you did not specify all types of testing?

We are trying to use this structure for component and e2e, and want to make sure that the scenarios are isolated from each other.

Can you confirm that the Scenarios of a feature do not share any state that is defined within the scenario block?

@amiceli
Copy link
Owner

amiceli commented May 23, 2024

I made this repo when I needed Gherkin in my company/side projects for unit tests.
I never tested vitest-cucumber with e2e tests.
For me vitest is for unit tests and, for example,cypress for e2e tests.

For state, each Scenario is a describe. If you defined a variable in a Scenario isn't shared with others.

@charlieforward9
Copy link
Author

@charlieforward9
Copy link
Author

charlieforward9 commented May 28, 2024

We are still having issues with creating idempotent tests. We are unsure where the problem stems from, but are continuing to look into this to create a testing template with vitest + vitest-cucumber + react-testing-library (with a custom Redux wrapper).

Our main issue is with the redux state

  • When calling render within describeFeature, it does not reset across Scenarios
  • When calling render within Scenario, actions (type, click, etc) do not update the component...

@saiNaruUFL
Copy link

@amiceli
Copy link
Owner

amiceli commented May 28, 2024

If you use rerender inside describe, afterAll, etc without vitest-cucumber but just with vitest, you have same issue ?

@charlieforward9
Copy link
Author

charlieforward9 commented May 29, 2024

We found a fix, we were messing up with our useAppDispatch hook which was causing problems down the line. We will be publishing a vitest-cucumber template repo soon for this library that incorporates testing-library/react and react-redux.

@saiNaruUFL can be assigned to this since he will be making the example repo.

@amiceli
Copy link
Owner

amiceli commented Oct 18, 2024

No updated for a while, I closed.
It will re-open if this issue is updated ;).

@amiceli amiceli closed this as completed Oct 18, 2024
@charlieforward9
Copy link
Author

@amiceli We were not able to generate an example library yet due to other priority tasks, however, we are having @saiNaruUFL create test documentation and if he thinks he can do it within a day, this will be a helpful piece of our internal docs.

I would keep this open in favor of amiceli/vitest-cucumber-example#1 given its documented much better with more context.

@amiceli
Copy link
Owner

amiceli commented Oct 19, 2024

All right, I keep it open ;).

@amiceli amiceli reopened this Oct 19, 2024
@saiNaruUFL
Copy link

Here is the Vitest-Cucumber_RTL_Template: https://github.com/Agriculture-Intelligence/vitest-cucumber_rtl_template

@charlieforward9
Copy link
Author

@amiceli this repo is now available to be added into your docs as a template for your awesome package. I will close it out on my end as the task is now complete.

@amiceli
Copy link
Owner

amiceli commented Nov 5, 2024

Well done ! I'm going to add it in the doc ;).

@amiceli
Copy link
Owner

amiceli commented Nov 5, 2024

I added it on the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants