jaxon-php /
jaxon-mono
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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. Loading history...
|
|||
| 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('Get value from an object in an event handler', () => { |
||
| 204 | document.body.innerHTML = `<div id="wrapper"><span class="username"></span></div>`; |
||
| 205 | |||
| 206 | // Javascript code: user.name = 'Mister Johnson' |
||
| 207 | 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. Loading history...
|
|||
| 208 | calls: [{ |
||
| 209 | _type: 'attr', |
||
| 210 | _name: 'user', |
||
| 211 | value: { name: 'Mister Johnson' }, |
||
| 212 | }], |
||
| 213 | }); |
||
| 214 | |||
| 215 | // Javascript code: const username = user.name |
||
| 216 | const username = call.execExpr({ |
||
| 217 | calls: [{ |
||
| 218 | _type: 'attr', |
||
| 219 | _name: 'user', |
||
| 220 | }, { |
||
| 221 | _type: 'attr', |
||
| 222 | _name: 'name', |
||
| 223 | }], |
||
| 224 | }); |
||
| 225 | |||
| 226 | expect(username).toBe('Mister Johnson'); |
||
| 227 | |||
| 228 | // Set an event handler |
||
| 229 | // Javascript code: $('.username')->on('click', () => $(this)->html(user.name)) |
||
| 230 | call.execExpr({ |
||
| 231 | calls: [{ |
||
| 232 | _type: 'select', |
||
| 233 | _name: '.username', |
||
| 234 | mode: 'jq', |
||
| 235 | }, { |
||
| 236 | _type: 'event', |
||
| 237 | _name: 'click', |
||
| 238 | mode: 'jq', |
||
| 239 | func: { |
||
| 240 | _type: 'expr', |
||
| 241 | calls: [{ |
||
| 242 | _type: 'select', |
||
| 243 | _name: 'this', |
||
| 244 | mode: 'jq', |
||
| 245 | }, { |
||
| 246 | _type: 'func', |
||
| 247 | _name: 'html', |
||
| 248 | args: [{ |
||
| 249 | _type: 'expr', |
||
| 250 | calls: [{ |
||
| 251 | _type: 'attr', |
||
| 252 | _name: 'user', |
||
| 253 | }, { |
||
| 254 | _type: 'attr', |
||
| 255 | _name: 'name', |
||
| 256 | }], |
||
| 257 | }], |
||
| 258 | }], |
||
| 259 | }, |
||
| 260 | }], |
||
| 261 | }); |
||
| 262 | |||
| 263 | 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. Loading history...
|
|||
| 264 | |||
| 265 | // Trigger the event |
||
| 266 | query.jq('.username').trigger('click'); |
||
| 267 | |||
| 268 | expect(query.jq('.username').text()).toBe('Mister Johnson'); |
||
| 269 | }); |
||
| 270 | |||
| 271 | test('Access to undefined vars', () => { |
||
| 272 | expect(window.defValue).toBe(undefined); |
||
| 273 | |||
| 274 | // Javascript code: const undefValue1 = window.defValue |
||
| 275 | 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. Loading history...
|
|||
| 276 | calls: [{ |
||
| 277 | _type: 'attr', |
||
| 278 | _name: 'window', |
||
| 279 | }, { |
||
| 280 | _type: 'attr', |
||
| 281 | _name: 'defValue', |
||
| 282 | }], |
||
| 283 | }); |
||
| 284 | |||
| 285 | expect(undefValue1).toBe(undefined); |
||
| 286 | |||
| 287 | // Javascript code: window.defValue = '1024' |
||
| 288 | call.execExpr({ |
||
| 289 | calls: [{ |
||
| 290 | _type: 'attr', |
||
| 291 | _name: 'window', |
||
| 292 | }, { |
||
| 293 | _type: 'attr', |
||
| 294 | _name: 'defValue', |
||
| 295 | value: '1024', |
||
| 296 | }], |
||
| 297 | }); |
||
| 298 | |||
| 299 | expect(window.defValue).toBe('1024'); |
||
| 300 | |||
| 301 | // Javascript code: const defValue = window.defValue |
||
| 302 | const defValue = call.execExpr({ |
||
| 303 | calls: [{ |
||
| 304 | _type: 'attr', |
||
| 305 | _name: 'window', |
||
| 306 | }, { |
||
| 307 | _type: 'attr', |
||
| 308 | _name: 'defValue', |
||
| 309 | }], |
||
| 310 | }); |
||
| 311 | |||
| 312 | expect(defValue).toBe('1024'); |
||
| 313 | |||
| 314 | // Javascript code: const undefValue2 = window.defValue.intValue |
||
| 315 | const undefValue2 = call.execExpr({ |
||
| 316 | calls: [{ |
||
| 317 | _type: 'attr', |
||
| 318 | _name: 'window', |
||
| 319 | }, { |
||
| 320 | _type: 'attr', |
||
| 321 | _name: 'defValue', |
||
| 322 | }, { |
||
| 323 | _type: 'attr', |
||
| 324 | _name: 'intValue', |
||
| 325 | }], |
||
| 326 | }); |
||
| 327 | |||
| 328 | expect(undefValue2).toBe(undefined); |
||
| 329 | |||
| 330 | // Javascript code: const undefValue3 = window.intValue.defValue |
||
| 331 | const undefValue3 = call.execExpr({ |
||
| 332 | calls: [{ |
||
| 333 | _type: 'attr', |
||
| 334 | _name: 'window', |
||
| 335 | }, { |
||
| 336 | _type: 'attr', |
||
| 337 | _name: 'intValue', |
||
| 338 | }, { |
||
| 339 | _type: 'attr', |
||
| 340 | _name: 'defValue', |
||
| 341 | }], |
||
| 342 | }); |
||
| 343 | |||
| 344 | expect(undefValue3).toBe(undefined); |
||
| 345 | }); |
||
| 346 | |||
| 347 | test('Access to "global" vars', () => { |
||
| 348 | expect(window.strValue).toBe(undefined); |
||
| 349 | |||
| 350 | // Javascript code: window.strValue = '1024' |
||
| 351 | 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. Loading history...
|
|||
| 352 | calls: [{ |
||
| 353 | _type: 'attr', |
||
| 354 | _name: 'window', |
||
| 355 | }, { |
||
| 356 | _type: 'attr', |
||
| 357 | _name: 'strValue', |
||
| 358 | value: '1024', |
||
| 359 | }], |
||
| 360 | }); |
||
| 361 | |||
| 362 | expect(window.strValue).toBe('1024'); |
||
| 363 | |||
| 364 | // Javascript code: const strValue = window.strValue |
||
| 365 | const strCallValue = call.execCall({ |
||
| 366 | _type: 'attr', |
||
| 367 | _name: 'strValue', |
||
| 368 | }); |
||
| 369 | |||
| 370 | expect(strCallValue).toBe('1024'); |
||
| 371 | |||
| 372 | // Javascript code: const strValue = window.strValue |
||
| 373 | const strExprValue = call.execExpr({ |
||
| 374 | calls: [{ |
||
| 375 | _type: 'attr', |
||
| 376 | _name: 'strValue', |
||
| 377 | }], |
||
| 378 | }); |
||
| 379 | |||
| 380 | expect(strExprValue).toBe('1024'); |
||
| 381 | |||
| 382 | // Javascript code: const intValue = parseInt(window.strValue) |
||
| 383 | const intValue = call.execExpr({ |
||
| 384 | calls: [{ |
||
| 385 | _type: 'func', |
||
| 386 | _name: 'parseInt', |
||
| 387 | args: [{ |
||
| 388 | _type: 'expr', |
||
| 389 | calls: [{ |
||
| 390 | _type: 'attr', |
||
| 391 | _name: 'strValue', |
||
| 392 | }], |
||
| 393 | }], |
||
| 394 | }], |
||
| 395 | }); |
||
| 396 | |||
| 397 | expect(intValue).toBe(1024); |
||
| 398 | }); |
||
| 399 |
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.