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

nth-child inside nth-child selector returning null #6706

Closed
anselmbradford opened this issue Jul 17, 2018 · 3 comments
Closed

nth-child inside nth-child selector returning null #6706

anselmbradford opened this issue Jul 17, 2018 · 3 comments

Comments

@anselmbradford
Copy link

🐛 Bug Report

It appears an nth-child selector inside another nth-child selector returns null.

To Reproduce

Steps to reproduce the behavior:

  1. Visit this codepen and see that the HTML can be queried with the selector '#test-one tbody tr:nth-child(1) td:nth-child(3)' and logs:
<td>
    2.6 mi
</td>
  1. Create this jest unit test with the same HTML and selector and see that it logs dom node: null when run:
const HTML_SNIPPET = `
<table id="test-one">
    <thead>
        <tr>
            <th>
                Agency
            </th>
            <th>
              <button>
                Languages
              </button>
            </th>
            <th>
              <button>
                Distance
              </button>
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                Alpha
            </td>
            <td>
                English
            </td>
            <td>
                2.6 mi
            </td>
        </tr>
        <tr>
            <td>
                Beta
            </td>
            <td>
                English, Spanish
            </td>
            <td>
                1.4 mi
            </td>
        </tr>
        <tr>
            <td>
                Gamma
            </td>
            <td>
                English, French, Spanish
            </td>
            <td>
                1.4 mi
            </td>
        </tr>
        <tr>
            <td>
                Delta
            </td>
            <td>
                English, Spanish
            </td>
            <td>
                3.2 mi
            </td>
        </tr>
        <tr>
            <td>
                Epsilon
            </td>
            <td>
                English
            </td>
            <td>
                1.6 mi
            </td>
        </tr>
        <tr>
            <td>
              Zeta
            </td>
            <td>
              English, Spanish
            </td>
            <td>
              1.2 mi
            </td>
        </tr>
        <tr>
            <td>
                Eta
            </td>
            <td>
                English
            </td>
            <td>
                11.1 mi
            </td>
        </tr>
    </tbody>
</table>
`;

describe( 'Table', () => {

  beforeEach( () => {
    document.body.innerHTML = HTML_SNIPPET;
  } );

  it( 'should have the .sort-up class sort table on load', () => {
    const selector = '#test-one tbody tr:nth-child(1) td:nth-child(3)';
    const dom = document.querySelector( selector );

    console.log( 'dom node:', dom );
  } );

} );
  1. Change query to '#test-one tbody tr:nth-child(1) td' and see that dom node: HTMLTableCellElement {} is logged, appearing to indicate issue is with the inner nth-child query in the selector.

Expected behavior

Jest and codepen example should behave the same way in regard to selectors.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS Sierra 10.12.6
    CPU: x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  Binaries:
    Node: 8.11.1 - ~/.nvm/versions/node/v8.11.1/bin/node
    npm: 5.6.0 - ~/.nvm/versions/node/v8.11.1/bin/npm
  npmPackages:
    jest: ^23.4.1 => 23.4.1
@anselmbradford
Copy link
Author

Appears this may be fixed in these unreleased jsdom changes jsdom/jsdom#2262

@thymikee
Copy link
Collaborator

Jest ships with older JSDOM to support Node 6. See #7538 (comment) on how to make Jest work other version of JSDOM.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
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

2 participants