Skip to content

Commit 48f7664

Browse files
author
Jack Pope
committed
Update more tests
1 parent b81de30 commit 48f7664

File tree

3 files changed

+230
-113
lines changed

3 files changed

+230
-113
lines changed

packages/react-art/src/__tests__/ReactART-test.js

Lines changed: 99 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,8 @@ import Wedge from 'react-art/Wedge';
2424

2525
// Isolate DOM renderer.
2626
jest.resetModules();
27-
2827
const ReactDOMClient = require('react-dom/client');
29-
const act = require('internal-test-utils').act;
30-
31-
// Isolate test renderer.
32-
jest.resetModules();
33-
const ReactTestRenderer = require('react-test-renderer');
28+
let act = require('internal-test-utils').act;
3429

3530
// Isolate the noop renderer
3631
jest.resetModules();
@@ -45,8 +40,16 @@ let TestComponent;
4540
let waitFor;
4641
let groupRef;
4742

43+
// let ReactDOMClient;
44+
// let ReactTestRenderer
45+
// let ReactNoop
46+
// let Scheduler
47+
// let act;
48+
4849
const Missing = {};
4950

51+
// function setup()
52+
5053
function testDOMNodeStructure(domNode, expectedStructure) {
5154
expect(domNode).toBeDefined();
5255
expect(domNode.nodeName).toBe(expectedStructure.nodeName);
@@ -73,6 +76,7 @@ describe('ReactART', () => {
7376
let container;
7477

7578
beforeEach(() => {
79+
jest.resetModules();
7680
container = document.createElement('div');
7781
document.body.appendChild(container);
7882

@@ -449,85 +453,125 @@ describe('ReactART', () => {
449453
});
450454

451455
describe('ReactARTComponents', () => {
452-
it('should generate a <Shape> with props for drawing the Circle', () => {
453-
const circle = ReactTestRenderer.create(
454-
<Circle radius={10} stroke="green" strokeWidth={3} fill="blue" />,
455-
);
456+
let ReactTestRenderer;
457+
beforeEach(() => {
458+
jest.resetModules();
459+
ReactTestRenderer = require('react-test-renderer');
460+
act = require('internal-test-utils').act;
461+
});
462+
463+
it('should generate a <Shape> with props for drawing the Circle', async () => {
464+
let circle;
465+
await act(() => {
466+
circle = ReactTestRenderer.create(
467+
<Circle radius={10} stroke="green" strokeWidth={3} fill="blue" />,
468+
);
469+
});
456470
expect(circle.toJSON()).toMatchSnapshot();
457471
});
458472

459-
it('should generate a <Shape> with props for drawing the Rectangle', () => {
460-
const rectangle = ReactTestRenderer.create(
461-
<Rectangle width={50} height={50} stroke="green" fill="blue" />,
462-
);
473+
it('should generate a <Shape> with props for drawing the Rectangle', async () => {
474+
let rectangle;
475+
await act(() => {
476+
rectangle = ReactTestRenderer.create(
477+
<Rectangle width={50} height={50} stroke="green" fill="blue" />,
478+
);
479+
});
463480
expect(rectangle.toJSON()).toMatchSnapshot();
464481
});
465482

466-
it('should generate a <Shape> with positive width when width prop is negative', () => {
467-
const rectangle = ReactTestRenderer.create(
468-
<Rectangle width={-50} height={50} />,
469-
);
483+
it('should generate a <Shape> with positive width when width prop is negative', async () => {
484+
let rectangle;
485+
await act(() => {
486+
rectangle = ReactTestRenderer.create(
487+
<Rectangle width={-50} height={50} />,
488+
);
489+
});
470490
expect(rectangle.toJSON()).toMatchSnapshot();
471491
});
472492

473-
it('should generate a <Shape> with positive height when height prop is negative', () => {
474-
const rectangle = ReactTestRenderer.create(
475-
<Rectangle height={-50} width={50} />,
476-
);
493+
it('should generate a <Shape> with positive height when height prop is negative', async () => {
494+
let rectangle;
495+
await act(() => {
496+
rectangle = ReactTestRenderer.create(
497+
<Rectangle height={-50} width={50} />,
498+
);
499+
});
477500
expect(rectangle.toJSON()).toMatchSnapshot();
478501
});
479502

480-
it('should generate a <Shape> with a radius property of 0 when top left radius prop is negative', () => {
481-
const rectangle = ReactTestRenderer.create(
482-
<Rectangle radiusTopLeft={-25} width={50} height={50} />,
483-
);
503+
it('should generate a <Shape> with a radius property of 0 when top left radius prop is negative', async () => {
504+
let rectangle;
505+
await act(() => {
506+
rectangle = ReactTestRenderer.create(
507+
<Rectangle radiusTopLeft={-25} width={50} height={50} />,
508+
);
509+
});
484510
expect(rectangle.toJSON()).toMatchSnapshot();
485511
});
486512

487-
it('should generate a <Shape> with a radius property of 0 when top right radius prop is negative', () => {
488-
const rectangle = ReactTestRenderer.create(
489-
<Rectangle radiusTopRight={-25} width={50} height={50} />,
490-
);
513+
it('should generate a <Shape> with a radius property of 0 when top right radius prop is negative', async () => {
514+
let rectangle;
515+
await act(() => {
516+
rectangle = ReactTestRenderer.create(
517+
<Rectangle radiusTopRight={-25} width={50} height={50} />,
518+
);
519+
});
491520
expect(rectangle.toJSON()).toMatchSnapshot();
492521
});
493522

494-
it('should generate a <Shape> with a radius property of 0 when bottom right radius prop is negative', () => {
495-
const rectangle = ReactTestRenderer.create(
496-
<Rectangle radiusBottomRight={-30} width={50} height={50} />,
497-
);
523+
it('should generate a <Shape> with a radius property of 0 when bottom right radius prop is negative', async () => {
524+
let rectangle;
525+
await act(() => {
526+
rectangle = ReactTestRenderer.create(
527+
<Rectangle radiusBottomRight={-30} width={50} height={50} />,
528+
);
529+
});
498530
expect(rectangle.toJSON()).toMatchSnapshot();
499531
});
500532

501-
it('should generate a <Shape> with a radius property of 0 when bottom left radius prop is negative', () => {
502-
const rectangle = ReactTestRenderer.create(
503-
<Rectangle radiusBottomLeft={-25} width={50} height={50} />,
504-
);
533+
it('should generate a <Shape> with a radius property of 0 when bottom left radius prop is negative', async () => {
534+
let rectangle;
535+
await act(() => {
536+
rectangle = ReactTestRenderer.create(
537+
<Rectangle radiusBottomLeft={-25} width={50} height={50} />,
538+
);
539+
});
505540
expect(rectangle.toJSON()).toMatchSnapshot();
506541
});
507542

508-
it('should generate a <Shape> where top radius is 0 if the sum of the top radius is greater than width', () => {
509-
const rectangle = ReactTestRenderer.create(
510-
<Rectangle
511-
radiusTopRight={25}
512-
radiusTopLeft={26}
513-
width={50}
514-
height={40}
515-
/>,
516-
);
543+
it('should generate a <Shape> where top radius is 0 if the sum of the top radius is greater than width', async () => {
544+
let rectangle;
545+
await act(() => {
546+
rectangle = ReactTestRenderer.create(
547+
<Rectangle
548+
radiusTopRight={25}
549+
radiusTopLeft={26}
550+
width={50}
551+
height={40}
552+
/>,
553+
);
554+
});
517555
expect(rectangle.toJSON()).toMatchSnapshot();
518556
});
519557

520-
it('should generate a <Shape> with props for drawing the Wedge', () => {
521-
const wedge = ReactTestRenderer.create(
522-
<Wedge outerRadius={50} startAngle={0} endAngle={360} fill="blue" />,
523-
);
558+
it('should generate a <Shape> with props for drawing the Wedge', async () => {
559+
let wedge;
560+
await act(() => {
561+
wedge = ReactTestRenderer.create(
562+
<Wedge outerRadius={50} startAngle={0} endAngle={360} fill="blue" />,
563+
);
564+
});
524565
expect(wedge.toJSON()).toMatchSnapshot();
525566
});
526567

527-
it('should return null if startAngle equals to endAngle on Wedge', () => {
528-
const wedge = ReactTestRenderer.create(
529-
<Wedge outerRadius={50} startAngle={0} endAngle={0} fill="blue" />,
530-
);
568+
it('should return null if startAngle equals to endAngle on Wedge', async () => {
569+
let wedge;
570+
await act(() => {
571+
wedge = ReactTestRenderer.create(
572+
<Wedge outerRadius={50} startAngle={0} endAngle={0} fill="blue" />,
573+
);
574+
});
531575
expect(wedge.toJSON()).toBeNull();
532576
});
533577
});

packages/react-debug-tools/src/__tests__/ReactDevToolsHooksIntegration-test.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ describe('React hooks DevTools integration', () => {
5555
return <div>count:{count}</div>;
5656
}
5757

58-
const renderer = ReactTestRenderer.create(<MyComponent />);
58+
let renderer;
59+
await act(() => {
60+
renderer = ReactTestRenderer.create(<MyComponent />);
61+
});
5962
expect(renderer.toJSON()).toEqual({
6063
type: 'div',
6164
props: {},
@@ -107,7 +110,10 @@ describe('React hooks DevTools integration', () => {
107110
);
108111
}
109112

110-
const renderer = ReactTestRenderer.create(<MyComponent />);
113+
let renderer;
114+
await act(() => {
115+
renderer = ReactTestRenderer.create(<MyComponent />);
116+
});
111117
expect(renderer.toJSON()).toEqual({
112118
type: 'div',
113119
props: {},
@@ -155,7 +161,10 @@ describe('React hooks DevTools integration', () => {
155161
return <div>count:{count}</div>;
156162
}
157163

158-
const renderer = ReactTestRenderer.create(<MyComponent />);
164+
let renderer;
165+
await act(() => {
166+
renderer = ReactTestRenderer.create(<MyComponent />);
167+
});
159168
expect(renderer.toJSON()).toEqual({
160169
type: 'div',
161170
props: {},
@@ -192,14 +201,16 @@ describe('React hooks DevTools integration', () => {
192201
function MyComponent() {
193202
return 'Done';
194203
}
195-
196-
const renderer = ReactTestRenderer.create(
197-
<div>
198-
<React.Suspense fallback={'Loading'}>
199-
<MyComponent />
200-
</React.Suspense>
201-
</div>,
202-
);
204+
let renderer;
205+
await act(() => {
206+
renderer = ReactTestRenderer.create(
207+
<div>
208+
<React.Suspense fallback={'Loading'}>
209+
<MyComponent />
210+
</React.Suspense>
211+
</div>,
212+
);
213+
});
203214
const fiber = renderer.root._currentFiber().child;
204215
if (__DEV__) {
205216
// First render was locked
@@ -254,7 +265,6 @@ describe('React hooks DevTools integration', () => {
254265
<MyComponent />
255266
</React.Suspense>
256267
</div>,
257-
{unstable_isConcurrent: true},
258268
),
259269
);
260270

0 commit comments

Comments
 (0)