1 | const jq = require('jquery'); |
||
2 | const { |
||
3 | parser: { call, query }, |
||
4 | } = require('../dist/jaxon.module'); |
||
5 | |||
6 | // Init the selector library. |
||
7 | query.jq = jq; |
||
0 ignored issues
–
show
|
|||
8 | |||
9 | test('Read str value from the DOM', () => { |
||
10 | document.body.innerHTML = `<div id="wrapper"><span id="integer">1024</span></div>`; |
||
11 | |||
12 | // Javascript code: const strValue = $('#integer')->text() |
||
13 | const strValue = call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
14 | calls: [{ |
||
15 | _type: 'select', |
||
16 | _name: '#integer', |
||
17 | mode: 'jq', |
||
18 | }, { |
||
19 | _type: 'func', |
||
20 | _name: 'text', |
||
21 | }], |
||
22 | }); |
||
23 | |||
24 | expect(strValue).toBe('1024'); |
||
25 | }); |
||
26 | |||
27 | test('Read str value from the DOM', () => { |
||
28 | document.body.innerHTML = `<div id="wrapper"><span id="integer">1024</span></div>`; |
||
29 | |||
30 | // Javascript code: const strValue = $('#integer')->html() |
||
31 | const strValue = call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
32 | calls: [{ |
||
33 | _type: 'select', |
||
34 | _name: '#integer', |
||
35 | mode: 'jq', |
||
36 | }, { |
||
37 | _type: 'func', |
||
38 | _name: 'html', |
||
39 | }], |
||
40 | }); |
||
41 | |||
42 | expect(strValue).toBe('1024'); |
||
43 | }); |
||
44 | |||
45 | test('Read int value from the DOM', () => { |
||
46 | document.body.innerHTML = `<div id="wrapper"><span id="integer">1024</span></div>`; |
||
47 | |||
48 | // Javascript code: const intValue = parseInt(query.jq('#integer')->text()) |
||
49 | const intValue = call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
50 | calls: [{ |
||
51 | _type: 'func', |
||
52 | _name: 'parseInt', |
||
53 | args: [{ |
||
54 | _type: 'expr', |
||
55 | calls: [{ |
||
56 | _type: 'select', |
||
57 | _name: '#integer', |
||
58 | mode: 'jq', |
||
59 | }, { |
||
60 | _type: 'func', |
||
61 | _name: 'text', |
||
62 | }] |
||
63 | }], |
||
64 | }], |
||
65 | }); |
||
66 | |||
67 | expect(intValue).toBe(1024); |
||
68 | }); |
||
69 | |||
70 | test('Read int value from the DOM, with the toInt() "method"', () => { |
||
71 | document.body.innerHTML = `<div id="wrapper"><span id="integer">1024</span></div>`; |
||
72 | |||
73 | // Javascript code: const intValue = parseInt(query.jq('#integer')->text()) |
||
74 | const intValue = call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
75 | calls: [{ |
||
76 | _type: 'select', |
||
77 | _name: '#integer', |
||
78 | mode: 'jq', |
||
79 | }, { |
||
80 | _type: 'func', |
||
81 | _name: 'text', |
||
82 | }, { |
||
83 | _type: 'func', |
||
84 | _name: 'toInt', |
||
85 | }], |
||
86 | }); |
||
87 | |||
88 | expect(intValue).toBe(1024); |
||
89 | }); |
||
90 | |||
91 | test('Assign element inner html', () => { |
||
92 | document.body.innerHTML = `<div id="wrapper"><span id="username"></span></div>`; |
||
93 | |||
94 | // Javascript code: $('#username')->html('Mister Johnson') |
||
95 | call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
96 | calls: [{ |
||
97 | _type: 'select', |
||
98 | _name: '#username', |
||
99 | mode: 'jq', |
||
100 | }, { |
||
101 | _type: 'func', |
||
102 | _name: 'html', |
||
103 | args: ['Mister Johnson'], |
||
104 | }], |
||
105 | }); |
||
106 | |||
107 | expect(query.jq('#username').text()).toBe('Mister Johnson'); |
||
0 ignored issues
–
show
The variable
query seems to be never declared. If this is a global, consider adding a /** global: query */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
108 | }); |
||
109 | |||
110 | // test('Assign element outer html', () => { |
||
111 | // document.body.innerHTML = `<div id="wrapper"><span id="username">Feuzeu</span></div>`; |
||
112 | |||
113 | // // Javascript code: $('#username')->prop('outerHTML', 'Mister Johnson') |
||
114 | // call.execExpr({ |
||
115 | // calls: [{ |
||
116 | // _type: 'select', |
||
117 | // _name: '#username', |
||
118 | // mode: 'jq', |
||
119 | // }, { |
||
120 | // _type: 'func', |
||
121 | // _name: 'prop', |
||
122 | // args: ['outerHTML', 'Mister Johnson'], |
||
123 | // }], |
||
124 | // }); |
||
125 | |||
126 | // expect(query.jq('#wrapper').html()).toBe('Mister Johnson'); |
||
127 | // }); |
||
128 | |||
129 | test('Set an event handler', () => { |
||
130 | document.body.innerHTML = `<div id="wrapper"><span id="username"></span></div>`; |
||
131 | |||
132 | // Set an event handler |
||
133 | // Javascript code: $('#username')->on('click', () => $('#username')->html('Mister Johnson')) |
||
134 | call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
135 | calls: [{ |
||
136 | _type: 'select', |
||
137 | _name: '#username', |
||
138 | mode: 'jq', |
||
139 | }, { |
||
140 | _type: 'event', |
||
141 | _name: 'click', |
||
142 | mode: 'jq', |
||
143 | func: { |
||
144 | _type: 'expr', |
||
145 | calls: [{ |
||
146 | _type: 'select', |
||
147 | _name: '#username', |
||
148 | mode: 'jq', |
||
149 | }, { |
||
150 | _type: 'func', |
||
151 | _name: 'html', |
||
152 | args: ['Mister Johnson'], |
||
153 | }], |
||
154 | }, |
||
155 | }], |
||
156 | }); |
||
157 | |||
158 | expect(query.jq('#username').text()).toBe(''); |
||
0 ignored issues
–
show
The variable
query seems to be never declared. If this is a global, consider adding a /** global: query */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
159 | |||
160 | // Trigger the event handler |
||
161 | query.jq('#username').trigger('click'); |
||
162 | |||
163 | expect(query.jq('#username').text()).toBe('Mister Johnson'); |
||
164 | }); |
||
165 | |||
166 | test('Use "this" in an event handler', () => { |
||
167 | document.body.innerHTML = `<div id="wrapper"><span class="username"></span></div>`; |
||
168 | |||
169 | // Set an event handler |
||
170 | // Javascript code: $('.username')->on('click', () => $(this)->html('Mister Johnson')) |
||
171 | call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
172 | calls: [{ |
||
173 | _type: 'select', |
||
174 | _name: '.username', |
||
175 | mode: 'jq', |
||
176 | }, { |
||
177 | _type: 'event', |
||
178 | _name: 'click', |
||
179 | mode: 'jq', |
||
180 | func: { |
||
181 | _type: 'expr', |
||
182 | calls: [{ |
||
183 | _type: 'select', |
||
184 | _name: 'this', |
||
185 | mode: 'jq', |
||
186 | }, { |
||
187 | _type: 'func', |
||
188 | _name: 'html', |
||
189 | args: ['Mister Johnson'], |
||
190 | }], |
||
191 | }, |
||
192 | }], |
||
193 | }); |
||
194 | |||
195 | expect(query.jq('.username').text()).toBe(''); |
||
0 ignored issues
–
show
The variable
query seems to be never declared. If this is a global, consider adding a /** global: query */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
196 | |||
197 | // Trigger the event |
||
198 | query.jq('.username').trigger('click'); |
||
199 | |||
200 | expect(query.jq('.username').text()).toBe('Mister Johnson'); |
||
201 | }); |
||
202 | |||
203 | test('Access to undefined vars', () => { |
||
204 | expect(window.defValue).toBe(undefined); |
||
205 | |||
206 | // Javascript code: const undefValue1 = window.defValue |
||
207 | const undefValue1 = call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
208 | calls: [{ |
||
209 | _type: 'attr', |
||
210 | _name: 'window', |
||
211 | }, { |
||
212 | _type: 'attr', |
||
213 | _name: 'defValue', |
||
214 | }], |
||
215 | }); |
||
216 | |||
217 | expect(undefValue1).toBe(undefined); |
||
218 | |||
219 | // Javascript code: window.defValue = '1024' |
||
220 | call.execExpr({ |
||
221 | calls: [{ |
||
222 | _type: 'attr', |
||
223 | _name: 'window', |
||
224 | }, { |
||
225 | _type: 'attr', |
||
226 | _name: 'defValue', |
||
227 | value: '1024', |
||
228 | }], |
||
229 | }); |
||
230 | |||
231 | expect(window.defValue).toBe('1024'); |
||
232 | |||
233 | // Javascript code: const defValue = window.defValue |
||
234 | const defValue = call.execExpr({ |
||
235 | calls: [{ |
||
236 | _type: 'attr', |
||
237 | _name: 'window', |
||
238 | }, { |
||
239 | _type: 'attr', |
||
240 | _name: 'defValue', |
||
241 | }], |
||
242 | }); |
||
243 | |||
244 | expect(defValue).toBe('1024'); |
||
245 | |||
246 | // Javascript code: const undefValue2 = window.defValue.intValue |
||
247 | const undefValue2 = call.execExpr({ |
||
248 | calls: [{ |
||
249 | _type: 'attr', |
||
250 | _name: 'window', |
||
251 | }, { |
||
252 | _type: 'attr', |
||
253 | _name: 'defValue', |
||
254 | }, { |
||
255 | _type: 'attr', |
||
256 | _name: 'intValue', |
||
257 | }], |
||
258 | }); |
||
259 | |||
260 | expect(undefValue2).toBe(undefined); |
||
261 | |||
262 | // Javascript code: const undefValue3 = window.intValue.defValue |
||
263 | const undefValue3 = call.execExpr({ |
||
264 | calls: [{ |
||
265 | _type: 'attr', |
||
266 | _name: 'window', |
||
267 | }, { |
||
268 | _type: 'attr', |
||
269 | _name: 'intValue', |
||
270 | }, { |
||
271 | _type: 'attr', |
||
272 | _name: 'defValue', |
||
273 | }], |
||
274 | }); |
||
275 | |||
276 | expect(undefValue3).toBe(undefined); |
||
277 | }); |
||
278 | |||
279 | test('Access to "global" vars', () => { |
||
280 | expect(window.strValue).toBe(undefined); |
||
281 | |||
282 | // Javascript code: window.strValue = '1024' |
||
283 | call.execExpr({ |
||
0 ignored issues
–
show
The variable
call seems to be never declared. If this is a global, consider adding a /** global: call */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. ![]() |
|||
284 | calls: [{ |
||
285 | _type: 'attr', |
||
286 | _name: 'window', |
||
287 | }, { |
||
288 | _type: 'attr', |
||
289 | _name: 'strValue', |
||
290 | value: '1024', |
||
291 | }], |
||
292 | }); |
||
293 | |||
294 | expect(window.strValue).toBe('1024'); |
||
295 | |||
296 | // Javascript code: const strValue = window.strValue |
||
297 | const strCallValue = call.execCall({ |
||
298 | _type: 'attr', |
||
299 | _name: 'strValue', |
||
300 | }); |
||
301 | |||
302 | expect(strCallValue).toBe('1024'); |
||
303 | |||
304 | // Javascript code: const strValue = window.strValue |
||
305 | const strExprValue = call.execExpr({ |
||
306 | calls: [{ |
||
307 | _type: 'attr', |
||
308 | _name: 'strValue', |
||
309 | }], |
||
310 | }); |
||
311 | |||
312 | expect(strExprValue).toBe('1024'); |
||
313 | |||
314 | // Javascript code: const intValue = parseInt(window.strValue) |
||
315 | const intValue = call.execExpr({ |
||
316 | calls: [{ |
||
317 | _type: 'func', |
||
318 | _name: 'parseInt', |
||
319 | args: [{ |
||
320 | _type: 'expr', |
||
321 | calls: [{ |
||
322 | _type: 'attr', |
||
323 | _name: 'strValue', |
||
324 | }], |
||
325 | }], |
||
326 | }], |
||
327 | }); |
||
328 | |||
329 | expect(intValue).toBe(1024); |
||
330 | }); |
||
331 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.