-
Notifications
You must be signed in to change notification settings - Fork 62
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
Unable to test iX component using React Testing Library and Jest #1288
Comments
We are using the same test setup maybe this helps you to get your tests running: https://github.com/siemens/ix/blob/main/packages/react/src/tests/toast/toast.spec.tsx or import { render, waitFor } from '@testing-library/react';
import React from 'react';
import { describe, it } from 'vitest';
import { deepQuerySelector } from 'shadow-dom-testing-library';
import { IxContentHeader } from '../..';
describe(`content-header`, async () => {
it(`basic`, async () => {
const page = render(
<>
<IxContentHeader
headerTitle="Content Header"
headerSubtitle="My Subtitle"
>
Custom Content
</IxContentHeader>
</>
);
await waitFor(() =>
expect(deepQuerySelector(page.container, '.subtitle')).toBeInTheDocument()
);
expect(deepQuerySelector(page.container, '.subtitle')?.innerText).toEqual(
'My Subtitle'
);
});
}); Please check your testing environment, the react components are no pure react components they use web components to render the content. You have to pierce through this layer IMO it is not necessary to test the internals of the ix components this should not be a part of your unit test. |
Prerequisites
What happened?
UI testing of iX components is not working with React Testing Library and Jest.
For example, testing text displayed by
IxContentHeader
did not work and produces following error:TestingLibraryElementError: Unable to find an element with the text:
After following instructions in code to produce this issue, you can see that:
IxContentHeader
is failedIxTypography
is passedWhat type of frontend framework are you seeing the problem on?
React
Which version of iX do you use?
v2.2.1
Code to produce this issue.
npm install
npm test
The text was updated successfully, but these errors were encountered: