@@ -40,37 +40,39 @@ export default function App() {
40
40
}
41
41
` ;
42
42
43
- const jasmineTest = `import React from 'react';
44
- import ShallowRenderer from 'react-shallow-renderer';
43
+ const testSetup = `global.IS_REACT_ACT_ENVIRONMENT = true;` ;
44
+
45
+ const jasmineTest = `import React, {act} from 'react';
46
+ import ReactDOMClient from 'react-dom/client';
45
47
import App from '../src/App';
46
48
47
49
describe('Component App', () => {
48
- it('should render message', () => {
49
- const renderer = new ShallowRenderer( );
50
- renderer.render(<App />);
51
- let result = renderer.getRenderOutput();
52
- expect(result.type).toBe('div' );
53
- expect(result.props.children).toEqual(
54
- <h1>Hello React!</h1>
55
- );
50
+ it('should render message', async () => {
51
+ const container = document.createElement('div' );
52
+
53
+ await act( async () => {
54
+ ReactDOMClient.createRoot(container).render(<App /> );
55
+ });
56
+ const h1 = container.querySelector('h1');
57
+ expect(h1.textContent).toBe('Hello React!' );
56
58
});
57
59
});
58
60
` ;
59
61
60
- const mochaTest = `import React from 'react';
61
- import ShallowRenderer from 'react-shallow-renderer ';
62
- import {expect} from 'chai';
62
+ const mochaTest = `import React, {act} from 'react';
63
+ import ReactDOMClient from 'react-dom/client ';
64
+ import { expect } from 'chai';
63
65
import App from '../src/App';
64
66
65
67
describe('Component App', () => {
66
- it('should render message', () => {
67
- const renderer = new ShallowRenderer( );
68
- renderer.render(<App />);
69
- let result = renderer.getRenderOutput();
70
- expect(result.type).to.equal('div' );
71
- expect(result.props.children).to.deep.equal(
72
- <h1>Hello React!</h1>
73
- );
68
+ it('should render message', async () => {
69
+ const container = document.createElement('div' );
70
+
71
+ await act( async () => {
72
+ ReactDOMClient.createRoot(container).render(<App /> );
73
+ });
74
+ const h1 = container.querySelector('h1');
75
+ expect(h1.textContent).to.equal('Hello React!' );
74
76
});
75
77
});
76
78
` ;
@@ -96,16 +98,24 @@ export default function({transpiler, testFramework}) {
96
98
}
97
99
] ;
98
100
99
- if ( testFramework === 'jasmine' ) {
100
- files . push ( {
101
- filename : `test/app.spec${ ext } ` ,
102
- content : jasmineTest
103
- } ) ;
104
- } else if ( testFramework === 'mocha' ) {
101
+
102
+ if ( testFramework !== 'none' ) {
105
103
files . push ( {
106
- filename : `test/app.spec ${ ext } ` ,
107
- content : mochaTest
104
+ filename : `test/setup ${ ext } ` ,
105
+ content : testSetup
108
106
} ) ;
107
+
108
+ if ( testFramework === 'jasmine' ) {
109
+ files . push ( {
110
+ filename : `test/app.spec${ ext } ` ,
111
+ content : jasmineTest
112
+ } ) ;
113
+ } else if ( testFramework === 'mocha' ) {
114
+ files . push ( {
115
+ filename : `test/app.spec${ ext } ` ,
116
+ content : mochaTest
117
+ } ) ;
118
+ }
109
119
}
110
120
111
121
return files ;
0 commit comments