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

TypeError container.queryselectorall is not a function #526

Closed
kvedantmahajan opened this issue Nov 9, 2019 · 10 comments
Closed

TypeError container.queryselectorall is not a function #526

kvedantmahajan opened this issue Nov 9, 2019 · 10 comments

Comments

@kvedantmahajan
Copy link

kvedantmahajan commented Nov 9, 2019

 "react": "^16.9.0",
 "@testing-library/jest-dom": "^4.1.2",
 "@testing-library/react": "^9.2.0",

Relevant code or config:

 test("toggles", () => {
        const { getByTestId } = render(
            <Collapse data-testid="collapse" activeKey={2}>
                <Panel panelKey={1} header="Panel Header 1">
                    Some content
                </Panel>
                <Panel panelKey={2} header="Panel Header 2">
                    Some content
                </Panel>
                <Panel panelKey={3} header="Panel Header 3" disabled>
                    Some content
                </Panel>
            </Collapse>
        );
    });

What I did

const node = getByTestId("collapse");
console.log(node);

Problem description:

Ok, data-testid is not working here as expected. It throws error below

collapse › encountered a declaration exception
TypeError: container.querySelectorAll is not a function

Here is my collapse implementation

export const Collapse = ({
	activeKey = 1,
	accordion,
	onChange,
	expandIconPosition,
	children,
	...rest
}: CollapseProps) => {
	const [key, setKey] = React.useState(activeKey);

	const closeOtherPanels = (key: string | number) => {
		setKey(key);
	};

	return (
		<CollapseContext.Provider
			value={{
				key,
				accordion,
				closeOtherPanels,
				onChange,
				expandIconPosition
			}}
		>
			<CollapseWrap {...rest}>{children}</CollapseWrap>
		</CollapseContext.Provider>
	);
};
@kvedantmahajan kvedantmahajan changed the title typeerror container.queryselectorall is not a function TypeError container.queryselectorall is not a function Nov 9, 2019
@alexkrolick
Copy link
Collaborator

Are you running this with a JSDOM environment, like the one from Jest?

@kvedantmahajan
Copy link
Author

kvedantmahajan commented Nov 9, 2019

I didn't quite follow your comment. From whatever I picked up. I use yarn unit -u which is in turn "unit": "jest", to run my tests.

In my jest.config.js

setupFilesAfterEnv: ['./jest.setup.js'],

jest.setup.js

import '@testing-library/jest-dom/extend-expect';

@kentcdodds
Copy link
Member

Hi @kushalmahajan,

What is the implementation of CollapseWrap? If you could create a reproduction on codesandbox and post it to https://spectrum.chat/testing-library/help-react that would be helpful.

This is unlikely an issue with the library, so I'll close this here and ask you to take it over there. Thanks!

@fredbliss
Copy link

I can confirm this using your testing-javascript course code. As soon as you get to branch cypress-04, this error appears with Chrome 79 and Electron 78. @kentcdodds ... Help!

@kentcdodds
Copy link
Member

Hi Fred, could you open a new issue on Cypress Testing Library please? And if you could screenshot the error you're seeing that would also be helpful. Thank you.

@fredbliss
Copy link

fredbliss commented Jan 30, 2020

@kentcdodds
Copy link
Member

Thank you!

@kvedantmahajan
Copy link
Author

@kentcdodds I did edit for a Collapse implementation earlier. Any thoughts?

@kentcdodds
Copy link
Member

Sorry @kushalmahajan, that still doesn't give me enough information to diagnose the issue. Please follow the instructions in https://kcd.im/rtl-help to solve this issue.

@kentcdodds
Copy link
Member

Your getQueriesForElement call should be getQueriesForElement(root) not getQueriesForElememt("root").

Is there a reason you're not using @testing-library/react exports of render and screen? I think you'd have better success with those.

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

4 participants