Skip to content

Unused variable in example code in docs #115

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

Closed
apaatsio opened this issue Jun 13, 2018 · 5 comments
Closed

Unused variable in example code in docs #115

apaatsio opened this issue Jun 13, 2018 · 5 comments

Comments

@apaatsio
Copy link

Relevant code or config:

In the documentation at https://chrisnoring.gitbooks.io/react/content/testing/react-testing-library.html there is this example.

it('load data', async() => {
    const {getByText, getByTestId, getByPlaceholderText, container} = render(<Select />);

    Simulate.click(getByText('Load'));
    await wait(() => getByTestId('data'))
    const data = getByTestId('data')
    const elem = getByTestId('item');
    expect(elem).toHaveTextContent('test');
  })

Problem description:

The variable data is never used, so the line const data = getByTestId('data') is unnecessary since it doesn't have any effect on the outcome of the test.

Suggested solution:

Remove the line const data = getByTestId('data')

@antsmartian
Copy link
Collaborator

@apaatsio It would be great, if you can give us a PR. Will be happy to merge it.

@gnapse
Copy link
Member

gnapse commented Jun 16, 2018

I'm confused. Isn't that code and the line to be removed in a documentation that's not part of this repo? Why would that be an issue to be raised in this repo then?

@antsmartian
Copy link
Collaborator

@gnapse Yes you are right. I didn't notice the link properly. Closing the issue.

@apaatsio
Copy link
Author

What is the correct repo for this issue?

@gnapse
Copy link
Member

gnapse commented Jun 16, 2018

I don't know, you'd have to checkout if that website to which you linked has a GitHub repo of its source code, or ask the author or something.

julienw pushed a commit to julienw/react-testing-library that referenced this issue Dec 20, 2018
…library#124)

<!--
Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated!

Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Also, please make sure you're familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).

If you're new to contributing to open source projects, you might find this free
video course helpful: http://kcd.im/pull-request

Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->

**What**:

Replace the existing select query mechanism which uses `HTMLSelectElement .selectedOptions` with a query that searches for the `selected` attribute of an `HTMLOptionElement`.

<!-- Why are these changes necessary? -->

**Why**:

Closes testing-library#115.

Since `selectedOptions` is not a reactive property, JSDOM was not updating to match the selected option in a select Element. The `selected` attribute is reactive.

<!-- How were these changes implemented? -->

**How**:

Instead of iterating through `selectedOptions` of an HTMLSelectElement, we iterate through all HTMLSelectOptions and isolate the ones that are selected.
<!-- Have you done all of these things?  -->

I've gone ahead and tested this locally to make sure that it would be reactive! 👍 

**Checklist**:

<!-- add "N/A" to the end of each line that's irrelevant to your changes -->

<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->

- [ ] Documentation N/A
- [ ] Tests N/A
- [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
- [x] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions -->

<!-- feel free to add additional comments -->
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

No branches or pull requests

3 participants