-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathunit-testing-react.htm
More file actions
224 lines (202 loc) · 10.5 KB
/
unit-testing-react.htm
File metadata and controls
224 lines (202 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DataFormsJS React Components Unit Testing</title>
<!-- <link rel="stylesheet" href="vendor/mocha/mocha.css"> -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/mocha@9.2.2/mocha.css" />
<style>
.nav {
font-family: Arial, Helvetica, sans-serif;
margin: 20px;
}
.nav div { margin-top:10px; }
.error { background-color:red; color:white; padding:2em; font-size:2em; }
#root,
.test-content {
padding: 50px;
border: 1px solid black;
margin: 50px;
/* display: none; */
}
#polyfill-status { color:#999; }
table { border-collapse: collapse; }
table, th, td { border: 1px solid black; padding:.5em 1em; }
#mocha-stats { background-color: white; }
</style>
</head>
<body>
<div class="nav">
<a href="./">Back to all Unit Tests</a>
<div id="compile-type">Compiler: <strong></strong></div>
<div id="polyfill-status" style="display: none;">(Polyfill Downloaded)</div>
</div>
<div id="mocha"></div>
<div id="root"></div>
<section class="test-content json-data"></section>
<section class="test-content json-error"></section>
<section class="test-content added-by-test"></section>
<section class="test-content spread-syntax"></section>
<!--
React
https://reactjs.org
https://reactjs.org/docs/cdn-links.html
<script src="vendor/react.production.min.js" crossorigin="anonymous"></script>
<script src="vendor/react-dom.production.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.production.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@17.0.2/umd/react-dom.production.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.production.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@17.0.2/umd/react-dom.production.min.js" crossorigin="anonymous"></script>
-->
<script src="https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.production.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@17.0.2/umd/react-dom.production.min.js" crossorigin="anonymous"></script>
<!--
DataFormsJS JSX Loader
This should succeed when using both [jsxLoader.js] and [jsxLoader.min.js].
When making updates to the file both need to be tested.
-->
<!-- <script src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/react/jsxLoader.min.js"></script> -->
<script src="/src/react/jsxLoader.min.js"></script>
<script>
// View content from console if needed:
jsxLoader.logCompileTime = true;
jsxLoader.logCompileDetails = false;
// Uncomment to use Babel Standalone with source maps enabled which
// allows for full debugging with Browser DevTools (Chrome, Firefox, Safari).
// This will cause two tests to fail.
//
// jsxLoader.isSupportedBrowser = false;
// jsxLoader.sourceMaps = true;
</script>
<!--
DataFormJS React Components
All of these options should work for testing DataFormsJS Components when using React.
# 1) Check the single build file(s)
#
[module="type"] for modern browsers
[nomodule] for IE and legacy
Additional individual components not included with the main file.
#
<script type="module" src="/src/react/es6/DataFormsJS.min.js"></script>
<script type="module" src="/src/react/es6/I18n.min.js"></script>
<script type="module" src="/src/react/es6/ImageGallery.min.js"></script>
<script type="module" src="/src/react/es6/LeafletMap.min.js"></script>
<script nomodule src="/src/react/es5/DataFormsJS.min.js"></script>
<script nomodule src="/src/react/es5/I18n.min.js"></script>
<script nomodule src="/src/react/es5/ImageGallery.min.js"></script>
<script nomodule src="/src/react/es5/LeafletMap.min.js"></script>
# 2) Include individual component files using the es5 build
<script src="/src/react/es5/ErrorBoundary.js"></script>
<script src="/src/react/es5/JsonData.js"></script>
<script src="/src/react/es5/InputFilter.js"></script>
<script src="/src/react/es5/SortableTable.js"></script>
<script src="/src/react/es5/I18n.js"></script>
<script src="/src/react/es5/Format.js"></script>
<script src="/src/react/es5/LeafletMap.js"></script>
<script src="/src/react/es5/LazyLoad.js"></script>
<script src="/src/react/es5/Cache.js"></script>
<script src="/src/react/es5/ImageGallery.js"></script>
# 3) Include individual component files using the es6 build (modern browsers only)
<script type="module" src="/src/react/es6/ErrorBoundary.min.js"></script>
<script type="module" src="/src/react/es6/JsonData.min.js"></script>
<script type="module" src="/src/react/es6/InputFilter.min.js"></script>
<script type="module" src="/src/react/es6/SortableTable.min.js"></script>
<script type="module" src="/src/react/es6/I18n.min.js"></script>
<script type="module" src="/src/react/es6/Format.min.js"></script>
<script type="module" src="/src/react/es6/LeafletMap.min.js"></script>
<script type="module" src="/src/react/es6/LazyLoad.min.js"></script>
<script type="module" src="/src/react/es6/Cache.min.js"></script>
<script type="module" src="/src/react/es6/ImageGallery.min.js"></script>
# 4) Include individual component source files for babel/jsxLoader - es6 build
<script type="text/babel" src="/src/react/es6/ErrorBoundary.js"></script>
<script type="text/babel" src="/src/react/es6/JsonData.js"></script>
<script type="text/babel" src="/src/react/es6/InputFilter.js"></script>
<script type="text/babel" src="/src/react/es6/SortableTable.js"></script>
<script type="text/babel" src="/src/react/es6/I18n.js"></script>
<script type="text/babel" src="/src/react/es6/Format.js"></script>
<script type="text/babel" src="/src/react/es6/LeafletMap.js"></script>
<script type="text/babel" src="/src/react/es6/LazyLoad.js"></script>
<script type="text/babel" src="/src/react/es6/Cache.js"></script>
<script type="text/babel" src="/src/react/es6/ImageGallery.js"></script>
-->
<script type="module" src="/src/react/es6/DataFormsJS.min.js"></script>
<script type="module" src="/src/react/es6/I18n.min.js"></script>
<script type="module" src="/src/react/es6/ImageGallery.min.js"></script>
<script type="module" src="/src/react/es6/LeafletMap.min.js"></script>
<script nomodule src="/src/react/es5/DataFormsJS.min.js"></script>
<script nomodule src="/src/react/es5/I18n.min.js"></script>
<script nomodule src="/src/react/es5/ImageGallery.min.js"></script>
<script nomodule src="/src/react/es5/LeafletMap.min.js"></script>
<!--
https://mochajs.org/
<script src="vendor/chai/chai.js"></script>
<script src="vendor/mocha/mocha.js"></script>
-->
<script src="https://cdn.jsdelivr.net/npm/chai@4.5.0/chai.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mocha@9.2.2/mocha.js"></script>
<!--
Unit Testing Scripts
Files [404.jsx] and [error.jsx] are included to make sure
that content is still loaded from [unit-testing.jsx].
The inline babel scripts are dependant on each other in the order
defined and both must be loaded after [unit-testing.jsx]. This is
done to verify that [jsxLoader.js] adds scripts in the correct order.
-->
<script type="text/babel">
class App extends React.Component {
render() {
return <UnitTestPage />
}
}
</script>
<script type="text/babel">
ReactDOM.render(
<App />,
document.getElementById('root')
);
ReactDOM.render(
<TestJsonDataSuccess />,
document.querySelector('.test-content.json-data')
);
ReactDOM.render(
<TestJsonDataError />,
document.querySelector('.test-content.json-error')
);
</script>
<script type="text/babel" src="js/404.jsx"></script>
<script type="text/babel" src="js/error.jsx"></script>
<script type="text/babel" src="js/unit-testing.jsx"></script>
<!--
This will be loaded by a Unit Test. Only scripts with [type="text/babel"]
are processed automatically when the page loads.
-->
<script type="text/jsx">
ReactDOM.render(
<div>Hello World</div>,
document.querySelector('.test-content.added-by-test')
);
</script>
<!--
Mocha Setup
-->
<script class="mocha-init">
mocha.setup({
ui: 'bdd',
globals: [
// Prevent known errors from React and Vue Dev Tools.
// Mocha will show errors from these due to `checkLeaks()`.
'__VUE_DEVTOOLS_TOAST__',
'__REACT_DEVTOOLS_COMPONENT_FILTERS__',
'__REACT_DEVTOOLS_APPEND_COMPONENT_STACK__',
// Global variables defined during testing by [page.jsx]
'testJsonDataHtml',
'testJsonDataErrorHtml',
],
});
mocha.checkLeaks();
</script>
<script src="js/unit-testing-react.js"></script>
<script class="mocha-exec" src="js/unit-testing-react-setup.js"></script>
</body>
</html>