test: Optimize test cases (#39414)

This commit is contained in:
JarvisArt 2022-12-09 10:08:11 +08:00 committed by GitHub
parent 7e821bc8f6
commit d684b52abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -17,7 +17,11 @@ exports[`Watermark MutationObserver should work properly 1`] = `
<div
class="watermark"
style="position: relative;"
/>
>
<div
style="z-index: 9; position: absolute; left: 0; top: 0; width: 100%; height: 100%; background-size: 216px; pointer-events: none; background-repeat: repeat; background-position: 0px 0px; background-image: url('data:image/png;base64,00');"
/>
</div>
</div>
`;
@ -28,7 +32,7 @@ exports[`Watermark Observe the modification of style 1`] = `
style="position: relative;"
>
<div
style=""
style="z-index: 9; position: absolute; left: 0; top: 0; width: 100%; height: 100%; background-size: 216px; pointer-events: none; background-repeat: repeat; background-position: -300px -300px; background-image: url('data:image/png;base64,00');"
/>
</div>
</div>

View File

@ -2,7 +2,7 @@ import React from 'react';
import Watermark from '..';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
import { render } from '../../../tests/utils';
import { render, waitFor } from '../../../tests/utils';
describe('Watermark', () => {
mountTest(Watermark);
@ -49,19 +49,21 @@ describe('Watermark', () => {
expect(container).toMatchSnapshot();
});
it('MutationObserver should work properly', () => {
it('MutationObserver should work properly', async () => {
const { container } = render(<Watermark className="watermark" content="MutationObserver" />);
const target = container.querySelector<HTMLDivElement>('.watermark div');
target?.remove();
await waitFor(() => expect(target).toBeTruthy());
expect(container).toMatchSnapshot();
});
it('Observe the modification of style', () => {
it('Observe the modification of style', async () => {
const { container } = render(
<Watermark offset={[-200, -200]} className="watermark" content="MutationObserver" />,
);
const target = container.querySelector<HTMLDivElement>('.watermark div');
target?.setAttribute('style', '');
await waitFor(() => expect(target).toBeTruthy());
expect(container).toMatchSnapshot();
});
});