How to use makeTest method in Mocha

Best JavaScript code snippet using mocha

define-property-command-tests.js

Source:define-property-command-tests.js Github

copy

Full Screen

...8/***************************************************************************************************9 * define property command tests10 */11__(function() {12 module.exports = util.makeTest({13 /***************************************************************************14 * name15 */16 name: 'DefinePropertyCommandTests',17 /***************************************************************************18 * description19 */20 description: 'Define property command tests',21 /***************************************************************************22 * setup23 */24 setup: function () { },25 /***************************************************************************26 * teardown27 */28 teardown: function () { },29 /***************************************************************************30 * tests31 */32 tests: [33 util.makeTest({34 name: 'SetTests',35 tests: [36 util.makeTest({37 name: 'PropertyPathSetTest',38 doTest: function() {39 let _prototype = {40 a: {41 b: {42 c: 143 }44 }45 }46 let object = o({47 _type: _prototype,48 '$a.b.c': 2,49 d: 350 })51 util.isMatch(object, {52 a: {53 b: {54 c: 255 }56 },57 d: 358 })59 }60 }),61 util.makeTest({62 name: 'PropertyPathSetNonExistentPathTest',63 doTest: function() {64 let _prototype = {65 a: {66 b: {67 c: 168 }69 }70 }71 let object = o({72 _type: _prototype,73 '$d.e.f': 274 })75 util.isMatch(object, {76 a: {77 b: {78 c: 179 }80 },81 d: {82 e: {83 f: 284 }85 }86 })87 }88 }),89 util.makeTest({90 name: 'PropertyPathArrayIndexTest',91 doTest: function() {92 let _prototype = {93 a: {94 b: {95 c: 196 }97 }98 }99 let object = o({100 _type: _prototype,101 '$a.b.d[0]': 2102 })103 util.isMatch(object, {104 a: {105 b: {106 c: 1,107 d: [2]108 }109 },110 })111 }112 }),113 util.makeTest({114 name: 'PropertyPathSparseArrayIndexTest',115 doTest: function() {116 let _prototype = {117 a: {118 b: {119 c: 1120 }121 }122 }123 let object = o({124 _type: _prototype,125 '$a.b.d[100]': 2126 })127 util.isMatch(object, {128 a: {129 b: {130 c: 1,131 d: _.map(_.range(100), i => i === 99 ? 2 : undefined)132 }133 },134 })135 }136 }),137 util.makeTest({138 name: 'PropertyPathIntLikeStringsTreatedAsPropertiesTest',139 description: 'Test the behavior of integer like strings (e.g., "01")',140 doTest: function() {141 let _prototype = {142 a: {143 b: {144 c: 1145 }146 }147 }148 let object = o({149 _type: _prototype,150 '$a.b.d[01]': 2151 })152 util.isMatch(object, {153 a: {154 b: {155 c: 1,156 d: {157 '01': 2158 }159 }160 },161 })162 }163 }),164 util.makeTest({165 name: 'PropertyPathArrayIndexIntoObjectTest',166 doTest: function() {167 let _prototype = {168 a: {169 b: {170 c: 1,171 d: {172 e: 2173 }174 }175 }176 }177 let object = o({178 _type: _prototype,179 '$a.b.d[1]': 3180 })181 util.isMatch(object, {182 a: {183 b: {184 c: 1,185 d: {186 e: 2,187 1: 3188 }189 }190 },191 })192 }193 }),194 util.makeTest({195 name: 'PropertyPathStringIndexThrowsTest',196 doTest: function() {197 let _prototype = {198 a: {199 b: {200 c: 'bar',201 }202 }203 }204 assert.throws(205 () => {206 let object = o({207 _type: _prototype,208 '$a.b.c[2]': 'z'209 })210 }, TypeError)211 }212 }),213 util.makeTest({214 name: 'PropertyPathLeaderCharaterNonPropertyPathTest',215 description: 'Test that a leader character followed by a non property path is ' +216 'not interpreted as a property path',217 doTest: function() {218 let _prototype = {219 a: {220 b: {221 c: 1,222 }223 }224 }225 let object = o({226 _type: _prototype,227 $a: 2228 })229 util.isMatch(object, {230 $a: 2231 })232 }233 }),234 util.makeTest({235 name: 'PropertyPathLeaderCharaterEscapeNonPropertyPathTest',236 description: 'Test that an even number of leader characters (e.g., "$") does not' +237 'does not get interpreted as a property path.',238 doTest: function() {239 let _prototype = {240 a: {241 b: {242 c: 1,243 }244 }245 }246 let object = o({247 _type: _prototype,248 '$$$$a.b.c': 2249 })250 util.isMatch(object, {251 a: {252 b: {253 c: 1254 }255 },256 '$$a.b.c': 2257 })258 }259 }),260 util.makeTest({261 name: 'PropertyPathLeaderCharaterEscapeTest',262 description: 'Test that an odd number of leader characters (e.g., "$") gets ' +263 'interpreted as a property path with trailing leader characters ' +264 'escaped properly.',265 doTest: function() {266 let _prototype = {267 a: {268 b: {269 c: 1,270 }271 }272 }273 let object = o({274 _type: _prototype,275 '$$$$$a.b.c': 2276 })277 util.isMatch(object, {278 a: {279 b: {280 c: 1281 }282 },283 $$a: {284 b: {285 c: 2286 }287 }288 })289 }290 }),291 util.makeTest({292 name: 'PropertyPathLeaderCharaterInPathTreatedLiterallyTest',293 description: 'Test that a property name with leader characters in the ' +294 'property path is treated literally',295 doTest: function() {296 let _prototype = {297 a: {298 b: {299 c: 1,300 }301 }302 }303 let object = o({304 _type: _prototype,305 '$a.b.$c': 2,306 '$a.b.$$c': 3,307 '$a.b.$$$c': 4308 })309 util.isMatch(object, {310 a: {311 b: {312 c: 1,313 $c: 2,314 $$c: 3,315 $$$c: 4316 }317 },318 })319 }320 }),321 ]322 }),323 util.makeTest({324 name: 'MergeTests',325 tests: [326 util.makeTest({327 name: 'SingleLevelMergeTest',328 doTest: function() {329 let _prototype = {330 a: 1,331 b: 2,332 c: {333 d: 3,334 e: 4335 }336 }337 let object = o({338 _type: _prototype,339 g: 5,340 c: {341 $merge: {342 d: 6,343 f: 7344 }345 }346 })347 util.isMatch(object, {348 a: 1,349 b: 2,350 g: 5,351 c: {352 d: 6,353 e: 4,354 f: 7355 }356 })357 }358 }),359 util.makeTest({360 name: 'MultiLevelMergeOverwriteTest',361 doTest: function() {362 let _prototype = {363 a: 1,364 b: 2,365 c: {366 d: {367 e: 3368 }369 }370 }371 let object = o({372 _type: _prototype,373 c: {374 $merge: {375 d: {376 f: 4377 },378 g: 5379 }380 }381 })382 // confirm "c.d.f" is present383 util.isMatch(object, {384 a: 1,385 b: 2,386 c: {387 d: {388 f: 4389 },390 g: 5391 }392 })393 // confirm "c.d.e" is not394 util.notIsMatch(object, {395 c: {396 d: {397 e: 4398 }399 }400 })401 }402 }),403 util.makeTest({404 name: 'InnerUnchainedMergeDoesNotMergeTest',405 description: 'Verify that a nested "$merge" whose parent objects do ' +406 'not contain "$merge" commands does not merge',407 doTest: function() {408 let _prototype = {409 a: 1,410 b: 2,411 c: {412 d: {413 e: 3414 }415 }416 }417 let object = o({418 _type: _prototype,419 c: {420 d: {421 $merge: {422 f: 4423 }424 },425 g: 5426 }427 })428 // confirm "c.d.$merge.f" is present429 util.isMatch(object, {430 a: 1,431 b: 2,432 c: {433 d: {434 $merge: {435 f: 4436 }437 }438 }439 })440 }441 }),442 util.makeTest({443 name: 'ChainMergeTest',444 doTest: function() {445 let _prototype = {446 a: 1,447 b: 2,448 c: {449 d: {450 e: {451 f: 3452 }453 }454 }455 }456 let object = o({457 _type: _prototype,458 c: {459 $merge: {460 d: {461 $merge: {462 e: {463 $merge: {464 g: 4465 }466 }467 }468 }469 }470 }471 })472 util.isMatch(object, {473 a: 1,474 b: 2,475 c: {476 d: {477 e: {478 f: 3,479 g: 4480 }481 }482 }483 })484 }485 }),486 util.makeTest({487 name: 'ChainMergeNonExistentPathTest',488 doTest: function() {489 let _prototype = {490 a: 1,491 b: 2,492 c: {493 d: {494 e: {495 f: 3496 }497 }498 }499 }500 let object = o({501 _type: _prototype,502 g: {503 $merge: {504 h: {505 $merge: {506 i: {507 $merge: {508 j: 4509 }510 }511 }512 }513 }514 }515 })516 util.isMatch(object, {517 a: 1,518 b: 2,519 c: {520 d: {521 e: {522 f: 3,523 }524 }525 },526 g: {527 h: {528 i: {529 j: 4530 }531 }532 }533 })534 }535 }),536 util.makeTest({537 name: 'PropertyPathInnerMergeTest',538 description: 'Test dot notation $merge',539 doTest: function() {540 let _prototype = {541 a: 1,542 b: 2,543 c: {544 d: {545 e: {546 f: 3547 }548 }549 }550 }551 let object = o({552 _type: _prototype,553 '$c.d.e': {554 $merge: {555 g: 4556 }557 }558 })559 util.isMatch(object, {560 a: 1,561 b: 2,562 c: {563 d: {564 e: {565 f: 3,566 g: 4567 }568 }569 }570 })571 }572 }),573 util.makeTest({574 name: 'PropertyPathInnerMergeNonExistentPathTest',575 description: 'Test dot notation $merge on non existent path',576 doTest: function() {577 let _prototype = {578 a: 1,579 b: 2,580 c: {581 d: {582 e: {583 f: 3584 }585 }586 }587 }588 let object = o({589 _type: _prototype,590 '$g.h.i': {591 $merge: {592 j: 4593 }594 }595 })596 util.isMatch(object, {597 a: 1,598 b: 2,599 c: {600 d: {601 e: {602 f: 3603 }604 }605 },606 g: {607 h: {608 i: {609 j: 4610 }611 }612 }613 })614 }615 }),616 util.makeTest({617 name: 'ObjectWithMergeCommandContainsExtraKeysTest',618 description: 'Test dot notation $merge on non existent path',619 doTest: function() {620 let _prototype = {621 a: 1,622 b: 2,623 c: {624 d: {625 e: {626 f: 3627 }628 }629 }630 }631 let object = o({632 _type: _prototype,633 'c.d.e': {634 $merge: {635 g: 4636 },637 h: 5638 }639 })640 util.isMatch(object, {641 a: 1,642 b: 2,643 c: {644 d: {645 e: {646 f: 3647 }648 }649 },650 'c.d.e': {651 $merge: {652 g: 4653 },654 h: 5655 }656 })657 }658 }),659 util.makeTest({660 name: 'MergeWithArrayTest',661 doTest: function() {662 let _prototype = {663 a: {664 b: {665 c: [0]666 }667 }668 }669 let object = o({670 _type: _prototype,671 '$a.b.c': {672 $merge: {673 j: 4674 }675 }676 })677 util.isMatch(object, {678 a: {679 b: {680 c: _.assign([0], {j: 4})681 }682 }683 })684 }685 }),686 util.makeTest({687 name: 'MergeWithArrayElementTest',688 doTest: function() {689 let _prototype = {690 a: {691 b: {692 c: [{693 d: 1694 }]695 }696 }697 }698 let object = o({699 _type: _prototype,700 '$a.b.c[0]': {701 $merge: {702 e: 2703 }704 }705 })706 util.isMatch(object, {707 a: {708 b: {709 c: [{710 d: 1,711 e: 2712 }]713 }714 }715 })716 }717 }),718 util.makeTest({719 name: 'MergeWithNonObjectThrowsTest',720 doTest: function() {721 let _prototype = {722 a: 'foo'723 }724 assert.throws(725 () => {726 let object = o({727 _type: _prototype,728 a: {729 $merge: {730 b: 1731 }732 }733 })734 }, TypeError)735 }736 }),737 ]738 }),739 util.makeTest({740 name: 'PropertyTests',741 tests: [742 util.makeTest({743 name: 'PropertyPathPropertyTest',744 doTest: function() {745 let _prototype = {746 a: {747 b: {748 c: 1749 }750 }751 }752 let object = o({753 _type: _prototype,754 '$a.b.c': {755 $property: {756 enumerable: false,757 configurable: false,758 writable: false,759 value: 2760 }761 }762 })763 util.isMatch(object, {764 a: {765 b: {766 c: 2767 }768 }769 })770 object.a.b.c = 3771 assert.equal(object.a.b.c, 2)772 assert.equal(_.keys(object.a.b).length, 0)773 }774 }),775 util.makeTest({776 name: 'PropertyPathPropertyNonExistentPathTest',777 doTest: function() {778 let _prototype = {779 a: {780 b: {781 c: 1782 }783 }784 }785 let object = o({786 _type: _prototype,787 '$d.e.f': {788 $property: {789 enumerable: false,790 configurable: false,791 writable: false,792 value: 2793 }794 }795 })796 util.isMatch(object, {797 a: {798 b: {799 c: 1800 }801 },802 d: {803 e: {804 f: 2805 }806 }807 })808 object.a.b.c = 3809 assert.equal(object.a.b.c, 3)810 object.d.e.f = 3811 assert.equal(object.d.e.f, 2)812 assert.equal(_.keys(object.a.b).length, 1)813 assert.equal(_.keys(object.d.e).length, 0)814 }815 })816 ]817 }),818 util.makeTest({819 name: 'DeleteTests',820 tests: [821 util.makeTest({822 name: 'SingleLevelDeleteTest',823 doTest: function() {824 let _prototype = {825 a: 1,826 b: 2,827 c: {828 d: 3,829 e: 4830 }831 }832 let object = o({833 _type: _prototype,834 c: {835 $delete: 'e'836 }837 })838 assert.equal(object.c.d, 3)839 assert.ok(_.isNil(object.c.e))840 }841 }),842 util.makeTest({843 name: 'SingleLevelMultiDeleteTest',844 doTest: function() {845 let _prototype = {846 a: 1,847 b: 2,848 c: {849 d: 3,850 e: 4851 }852 }853 let object = o({854 _type: _prototype,855 c: {856 $delete: ['d', 'e']857 }858 })859 assert.ok(_.isNil(object.c.d))860 assert.ok(_.isNil(object.c.e))861 }862 }),863 util.makeTest({864 name: 'PropertyPathDeleteTest',865 doTest: function() {866 let _prototype = {867 a: 1,868 b: 2,869 c: {870 d: {871 e: 3,872 f: 4873 }874 }875 }876 let object = o({877 _type: _prototype,878 '$c.d': {879 $delete: ['f']880 }881 })882 util.isMatch(object, {883 a: 1,884 b: 2,885 c: {886 d: {887 e: 3888 }889 }890 })891 assert.ok(_.isNil(object.c.d.f))892 }893 }),894 ]895 }),896 util.makeTest({897 name: 'MultiOpTests',898 tests: [899 util.makeTest({900 name: 'SingleLevelMultiOpTest',901 doTest: function() {902 let _prototype = {903 a: 1,904 b: 2,905 c: {906 d: 3,907 e: 4908 }909 }910 let object = o({911 _type: _prototype,912 c: {913 $multiop: [914 {$delete: 'e'},915 {$merge: {f: 5, g: 6}}916 ]917 }918 })919 util.isMatch(object, {920 a: 1,921 b: 2,922 c: {923 d: 3,924 f: 5,925 g: 6,926 }927 })928 assert.ok(_.isNil(object.c.e))929 }930 }),931 util.makeTest({932 name: 'SingleLevelMultiOpSetOverrideTest',933 doTest: function() {934 let _prototype = {935 a: 1,936 b: 2,937 c: {938 d: 3,939 e: 4940 }941 }942 let object = o({943 _type: _prototype,944 c: {945 $multiop: [946 {$delete: 'e'},947 {$merge: {f: 5, g: 6}},948 {h: 7}949 ]950 }951 })952 util.isMatch(object, {953 a: 1,954 b: 2,955 c: {956 h: 7957 }958 })959 assert.ok(_.isNil(object.c.d))960 assert.ok(_.isNil(object.c.e))961 assert.ok(_.isNil(object.c.f))962 assert.ok(_.isNil(object.c.g))963 }964 }),965 util.makeTest({966 name: 'PropertyPathMultiOpTest',967 doTest: function() {968 let _prototype = {969 a: 1,970 b: 2,971 c: {972 d: {973 e: 3,974 f: 4975 }976 }977 }978 let object = o({979 _type: _prototype,...

Full Screen

Full Screen

ConstChecker.js

Source:ConstChecker.js Github

copy

Full Screen

...17import {CollectingErrorReporter as ErrorReporter} from '../../../src/util/CollectingErrorReporter.js';18import {validate as validateConst} from '../../../src/semantics/ConstChecker.js';19import {Options} from '../../../src/Options.js';20suite('ConstChecker.js', function() {21 function makeTest(name, code, expectedErrors, mode) {22 test(name, function() {23 var options = new Options();24 options.arrayComprehension = true;25 options.blockBinding = true;26 options.generatorComprehension = true;27 var reporter = new ErrorReporter();28 var parser =29 new Parser(new SourceFile('SOURCE', code), reporter, options);30 var tree = mode === 'script' ?31 parser.parseScript() : parser.parseModule();32 assert.deepEqual(reporter.errors, []);33 validateConst(tree, reporter);34 assert.deepEqual(reporter.errors, expectedErrors);35 });36 }37 makeTest('var', 'var x = 1; x += 1;', []);38 makeTest('const assignment', 'const x = 1; x &= 1;',39 ['SOURCE:1:14: x is read-only']);40 makeTest('const assignment', 'const x = 1; x |= 1;',41 ['SOURCE:1:14: x is read-only']);42 makeTest('const assignment', 'const x = 1; x ^= 1;',43 ['SOURCE:1:14: x is read-only']);44 makeTest('const assignment', 'const x = 1; x = 1;',45 ['SOURCE:1:14: x is read-only']);46 makeTest('const assignment', 'const x = 1; x <<= 1;',47 ['SOURCE:1:14: x is read-only']);48 makeTest('const assignment', 'const x = 1; x -= 1;',49 ['SOURCE:1:14: x is read-only']);50 makeTest('const assignment', 'const x = 1; x %= 1;',51 ['SOURCE:1:14: x is read-only']);52 makeTest('const assignment', 'const x = 1; x += 1;',53 ['SOURCE:1:14: x is read-only']);54 makeTest('const assignment', 'const x = 1; x >>= 1;',55 ['SOURCE:1:14: x is read-only']);56 makeTest('const assignment', 'const x = 1; x /= 1;',57 ['SOURCE:1:14: x is read-only']);58 makeTest('const assignment', 'const x = 1; x *= 1;',59 ['SOURCE:1:14: x is read-only']);60 makeTest('const assignment', 'const x = 1; x >>>= 1;',61 ['SOURCE:1:14: x is read-only']);62 makeTest('const prefix', 'const x = 1; ++x;', ['SOURCE:1:16: x is read-only']);63 makeTest('const prefix', 'const x = 1; --x;', ['SOURCE:1:16: x is read-only']);64 makeTest('const postfix', 'const x = 1; x++;', ['SOURCE:1:14: x is read-only']);65 makeTest('const postfix', 'const x = 1; x--;', ['SOURCE:1:14: x is read-only']);66 makeTest('function expression', '(function f() {\nf = 2;})',67 ['SOURCE:2:1: f is read-only']);68 makeTest('function declaration', 'function f() {\nf = 2;}', []);69 makeTest('import', 'import {x} from "abc";\nx = 1;',70 ['SOURCE:2:1: x is read-only']);71 makeTest('import', 'import {x, y} from "abc";\ny = 1;',72 ['SOURCE:2:1: y is read-only']);73 makeTest('import', 'import {x as z, y} from "abc";\nz = 1;',74 ['SOURCE:2:1: z is read-only']);75 makeTest('import default', 'import x from "abc";\nx = 1;',76 ['SOURCE:2:1: x is read-only']);77 makeTest('function params',78 'const x = 1;\n' +79 'function f(x) {\n' +80 ' x = 2;\n' +81 '}', []);82 makeTest('function params',83 'const x = 1;\n' +84 'function f({x}) {\n' +85 ' x = 2;\n' +86 '}', []);87 makeTest('function params',88 'const x = 1;\n' +89 'function f(y) {\n' +90 ' x = 2;\n' +91 '}', ['SOURCE:3:3: x is read-only']);92 makeTest('function params',93 'const x = 1;\n' +94 'function f(y = (x = 2)) {}',95 ['SOURCE:2:17: x is read-only']);96 makeTest('assign in initializer', 'const x = 1;\nvar y = (x = 2);',97 ['SOURCE:2:10: x is read-only']);98 makeTest('let',99 'const x = 1;\n' +100 '{\n' +101 ' let x;\n' +102 ' x = 2;\n' +103 '}', []);104 makeTest('let',105 'const x = 1;\n' +106 '{\n' +107 ' let y;\n' +108 ' x = 2;\n' +109 '}', ['SOURCE:4:3: x is read-only']);110 makeTest('let',111 'const x = 1;\n' +112 '{\n' +113 ' const x = 2;\n' +114 '}', []);115 makeTest('let',116 'let x;\n' +117 '{\n' +118 ' const x = 1;\n' +119 '}\n' +120 'x = 2;', []);121 makeTest('function expression and let',122 '(function f() { { let f = 1 } })', []);123 makeTest('function expression and let',124 '(function f() { { let f = 1 } f = 2; })',125 ['SOURCE:1:31: f is read-only']);126 makeTest('arrow', 'x => { x = 1 }', []);127 makeTest('arrow', '(x) => { x = 1 }', []);128 makeTest('class declaration',129 'const x = 1;\n' +130 '{\n'+131 ' class x {}\n' +132 ' x = 2;\n' +133 '}',134 []);135 makeTest('class declaration',136 'var m;\n' +137 'class C { m() { m = 2; } }',138 []);139 makeTest('class declaration',140 'class C {\n' +141 ' m() {\n' +142 ' C = 2;\n' +143 ' }\n' +144 '}',145 ['SOURCE:3:5: C is read-only']);146 makeTest('class expression',147 'const x = 1;\n' +148 '{\n'+149 ' (class x {})\n' +150 ' x = 2;\n' +151 '}',152 ['SOURCE:4:3: x is read-only']);153 makeTest('class expression',154 'var m;\n' +155 '(class C { m() { m = 2; } })',156 []);157 makeTest('class expression',158 '(class C {\n' +159 ' m() {\n' +160 ' C = 2;\n' +161 ' }\n' +162 '})',163 ['SOURCE:3:5: C is read-only']);164 makeTest('Duplicate declarations', 'let x; let x;',165 ['SOURCE:1:12: Duplicate declaration, x']);166 makeTest('Duplicate declarations', 'let x; const x = 1;',167 ['SOURCE:1:14: Duplicate declaration, x']);168 makeTest('Duplicate declarations', 'const x = 1; const x = 2;',169 ['SOURCE:1:20: Duplicate declaration, x']);170 makeTest('Duplicate declarations', 'const x = 1; let x;',171 ['SOURCE:1:18: Duplicate declaration, x']);172 makeTest('Duplicate declarations', 'var x; let x;',173 ['SOURCE:1:12: Duplicate declaration, x']);174 makeTest('Duplicate declarations', 'var x; var x;', []);175 makeTest('Duplicate declarations',176 'let x;\n' +177 '{\n' +178 ' var x;\n' +179 '}',180 ['SOURCE:3:7: Duplicate declaration, x']);181 makeTest('let bound function declaration',182 'const x = 1;\n' +183 '{\n' +184 ' function x() {}\n' +185 '}',186 []);187 makeTest('sloppy functions',188 'let x = 1;\n' +189 '{\n' +190 ' function x() {}\n' +191 '}',192 ['SOURCE:3:12: Duplicate declaration, x'],193 'script');194 makeTest('sloppy functions',195 '{\n' +196 ' let x = 1;\n' +197 ' function x() {}\n' +198 '}',199 ['SOURCE:3:12: Duplicate declaration, x'],200 'script');201 makeTest('sloppy functions',202 '{\n' +203 ' function x() {}\n' +204 '}\n' +205 'let x = 1;',206 ['SOURCE:4:5: Duplicate declaration, x'],207 'script');208 makeTest('catch var',209 'try {\n' +210 '} catch (ex) {\n' +211 ' let ex;\n' +212 '}',213 ['SOURCE:3:7: Duplicate declaration, ex']);214 makeTest('catch var',215 'try {\n' +216 '} catch (ex) {\n' +217 '}\n' +218 'let ex;',219 []);220 makeTest('catch var',221 'const ex = 1;\n' +222 'try {\n' +223 '} catch (ex) {\n' +224 ' ex = 2;\n' +225 '}',226 []);227 makeTest('for of loop',228 '{\n' +229 ' let x = 1;\n' +230 ' for (let x of iterable) {\n' +231 ' x;\n' +232 ' }\n' +233 '}',234 []);235 makeTest('for of loop',236 '{\n' +237 ' let x = 1;\n' +238 ' for (let x of iterable) {\n' +239 ' let x;\n' +240 ' }\n' +241 '}',242 []);243 makeTest('for of loop',244 '{\n' +245 ' const x = 1;\n' +246 ' for (const x of iterable) {\n' +247 ' const x = 2;\n' +248 ' }\n' +249 '}',250 []);251 makeTest('for of loop',252 '{\n' +253 ' for (const x of iterable) {\n' +254 ' x = 1;\n' +255 ' }\n' +256 '}',257 ['SOURCE:3:5: x is read-only']);258 makeTest('for in loop',259 '{\n' +260 ' let x = 1;\n' +261 ' for (let x in iterable) {\n' +262 ' x;\n' +263 ' }\n' +264 '}',265 []);266 makeTest('for in loop',267 '{\n' +268 ' let x = 1;\n' +269 ' for (let x in iterable) {\n' +270 ' let x;\n' +271 ' }\n' +272 '}',273 []);274 makeTest('for in loop',275 '{\n' +276 ' const x = 1;\n' +277 ' for (const x in iterable) {\n' +278 ' const x = 2;\n' +279 ' }\n' +280 '}',281 []);282 makeTest('for in loop',283 '{\n' +284 ' for (const x in iterable) {\n' +285 ' x = 1;\n' +286 ' }\n' +287 '}',288 ['SOURCE:3:5: x is read-only']);289 makeTest('for loop',290 '{\n' +291 ' let x = 1;\n' +292 ' for (let x = 2; ;) {\n' +293 ' x;\n' +294 ' }\n' +295 '}',296 []);297 makeTest('for loop',298 '{\n' +299 ' let x = 1;\n' +300 ' for (let x; ;) {\n' +301 ' let x;\n' +302 ' }\n' +303 '}',304 []);305 makeTest('for loop',306 '{\n' +307 ' const x = 1;\n' +308 ' for (const x = 2; ; ) {\n' +309 ' const x = 3;\n' +310 ' }\n' +311 '}',312 []);313 makeTest('for loop',314 '{\n' +315 ' for (const x = 1; ; ) {\n' +316 ' x = 2;\n' +317 ' }\n' +318 '}',319 ['SOURCE:3:5: x is read-only']);320 makeTest('for loop', 'for (;;) {}', []);321 makeTest('Array comprehension',322 'let x;\n' +323 '[for (x of []) x]',324 []);325 makeTest('Array comprehension',326 'let x;\n' +327 '[for (x of []) for (x of []) x]',328 []);329 makeTest('Array comprehension',330 'const x = 1;\n' +331 '[for (x of []) x]',332 []);333 makeTest('Array comprehension',334 'const x = 1;\n' +335 '[for (y of (x = [])) x]',336 ['SOURCE:2:13: x is read-only']);337 makeTest('Array comprehension',338 'const x = 1;\n' +339 '[for (y of []) x = 2]',340 ['SOURCE:2:16: x is read-only']);341 makeTest('Generator comprehension',342 'let x;\n' +343 '(for (x of []) x)',344 []);345 makeTest('Generator comprehension',346 'let x;\n' +347 '(for (x of []) for (x of []) x)',348 []);349 makeTest('Generator comprehension',350 'const x = 1;\n' +351 '(for (x of []) x)',352 []);353 makeTest('Generator comprehension',354 'const x = 1;\n' +355 '(for (y of (x = [])) x)',356 ['SOURCE:2:13: x is read-only']);357 makeTest('Generator comprehension',358 'const x = 1;\n' +359 '(for (y of []) x = 2)',360 ['SOURCE:2:16: x is read-only']);361 makeTest('with',362 'with ({}) {\n' +363 ' let x;\n' +364 ' let x;\n' +365 '}',366 ['SOURCE:3:7: Duplicate declaration, x'],367 'script');368 makeTest('with',369 'const x = 1;\n' +370 'with ({}) {\n' +371 ' x = 2;\n' +372 '}',373 [],374 'script');...

Full Screen

Full Screen

FreeVariableChecker.js

Source:FreeVariableChecker.js Github

copy

Full Screen

...17import {CollectingErrorReporter as ErrorReporter} from '../../../src/util/CollectingErrorReporter.js';18import {validate as validateFreeVars} from '../../../src/semantics/FreeVariableChecker.js';19import {Options} from '../../../src/Options.js';20suite('FreeVariableChecker.js', function() {21 function makeTest(name, code, expectedErrors, global, mode) {22 test(name, function() {23 var options = new Options();24 options.arrayComprehension = true;25 options.blockBinding = true;26 options.generatorComprehension = true;27 var reporter = new ErrorReporter();28 var parser = new Parser(new SourceFile('CODE', code), reporter, options);29 var tree = mode === 'module' ?30 parser.parseModule() : parser.parseScript();31 assert.deepEqual(reporter.errors, []);32 // Make sure we use a global that has not been polluted.33 validateFreeVars(tree, reporter, global || Object.create(null));34 assert.deepEqual(reporter.errors, expectedErrors);35 });36 }37 makeTest('basic', 'x', ['CODE:1:1: x is not defined']);38 makeTest('basic binop', 'x + 1', ['CODE:1:1: x is not defined']);39 makeTest('basic assign', 'x = 1', ['CODE:1:1: x is not defined']);40 makeTest('basic member', 'x.y', ['CODE:1:1: x is not defined']);41 makeTest('basic lookup', 'x[0]', ['CODE:1:1: x is not defined']);42 makeTest('basic unary', '++x', ['CODE:1:3: x is not defined']);43 makeTest('basic postfix', 'x++', ['CODE:1:1: x is not defined']);44 makeTest('basic call', 'x(1, 2)', ['CODE:1:1: x is not defined']);45 makeTest('basic new ', 'new x(1, 2)', ['CODE:1:5: x is not defined']);46 makeTest('var', 'var y = x', ['CODE:1:9: x is not defined']);47 makeTest('let', 'let y = x', ['CODE:1:9: x is not defined']);48 makeTest('const', 'const y = x', ['CODE:1:11: x is not defined']);49 makeTest('globals', 'x', [], {x: 1});50 makeTest('call args', 'f(x, 2);', ['CODE:1:3: x is not defined'], {f: 1});51 makeTest('new args', 'new f(x, 2);', ['CODE:1:7: x is not defined'], {f: 1});52 makeTest('nested function', 'function f() { x }',53 ['CODE:1:16: x is not defined']);54 makeTest('nested function', 'function f() { f }', []);55 makeTest('nested function expression', '(function f() { x })',56 ['CODE:1:17: x is not defined']);57 makeTest('nested function expression', '(function f() { f })', []);58 makeTest('nested class', 'class f { m() { x } }',59 ['CODE:1:17: x is not defined']);60 makeTest('nested class', 'class f { m() { f } }', []);61 makeTest('nested class', 'class f { m() { m } }',62 ['CODE:1:17: m is not defined']);63 makeTest('nested class expression', '(class f { m() { x } })',64 ['CODE:1:18: x is not defined']);65 makeTest('nested class expression', '(class f { m() { f } })', []);66 makeTest('nested class expression', '(class f { m() { m } })',67 ['CODE:1:18: m is not defined']);68 makeTest('arrow function', '() => x', ['CODE:1:7: x is not defined']);69 makeTest('arrow function', 'x => x', []);70 makeTest('arrow function', 'function f() { f }', []);71 makeTest('arrow function', '() => arguments',72 ['CODE:1:7: arguments is not defined']);73 makeTest('arrow function', '() => { arguments }',74 ['CODE:1:9: arguments is not defined']);75 makeTest('arrow function', '() => 1; function f() { arguments }', []);76 makeTest('arrow function', '(x = function() { arguments }) => 42', []);77 makeTest('if', 'if (true) { x; }', ['CODE:1:13: x is not defined']);78 makeTest('if', 'if (true) {} else { x; }', ['CODE:1:21: x is not defined']);79 makeTest('block let', '{ let x = 5; } x', ['CODE:1:16: x is not defined']);80 makeTest('block const', '{ const x = 5; } x',81 ['CODE:1:18: x is not defined']);82 makeTest('block let', '{ var x = 5; } x', []);83 makeTest('block function', '{ function f() {} } f', []);84 makeTest('block function', '"use strict"; { function f() {} } f',85 ['CODE:1:35: f is not defined']);86 makeTest('module', 'import {x} from "x"; x', [], undefined, 'module');87 makeTest('module', 'import x from "x"; x', [], undefined, 'module');88 makeTest('module', 'import * as x from "x"; x', [], undefined, 'module');89 makeTest('module', 'import {y as x} from "x"; x', [], undefined, 'module');90 makeTest('module', 'import {x as y} from "x"; x',91 ['CODE:1:27: x is not defined'], undefined, 'module');92 makeTest('module magic name', '__moduleName', [], undefined, 'module');93 makeTest('array comprehension', '[for (x of []) x]', []);94 makeTest('array comprehension', '[for (y of []) x]',95 ['CODE:1:16: x is not defined']);96 makeTest('generator comprehension', '(for (x of []) x)', []);97 makeTest('generator comprehension', '(for (y of []) x)',98 ['CODE:1:16: x is not defined']);99 makeTest('spread', 'var x = [1, 2]; var y = [0, ...x, 3]', []);100 makeTest('getter',101 '({\n' +102 ' get p() { return x; }\n' +103 '})',104 ['CODE:2:20: x is not defined']);105 makeTest('getter',106 '({\n' +107 ' get x() { return x; }\n' +108 '})',109 ['CODE:2:20: x is not defined']);110 makeTest('setter',111 '({\n' +112 ' set p(_) { x; }\n' +113 '})',114 ['CODE:2:14: x is not defined']);115 makeTest('setter',116 '({\n' +117 ' set x(_) { x; }\n' +118 '})',119 ['CODE:2:14: x is not defined']);...

Full Screen

Full Screen

test.js

Source:test.js Github

copy

Full Screen

...22 str4,23 }24 },25})26function makeTest(obj) {27 var name = JSON.stringify(obj) || 'undefined'28 if (name.length > 100) {29 name = name.slice(0, 97) + '...'30 }31 it(name, function () {32 expect(obj).toMatchParsedOfSelfStringifiedAndSnapshot()33 })34}35describe('URLON', function () {36 describe('Booleans', function () {37 makeTest(true)38 makeTest(false)39 makeTest(null)40 })41 describe('undefined', function () {42 it('stringifies to undefined', function () {43 expect(URLON.stringify(undefined)).toEqual(undefined)44 })45 it('throws to parse', function () {46 expect(function () {47 URLON.parse(undefined)48 }).toThrow()49 })50 })51 describe('Numbers', function () {52 makeTest(1234567890)53 makeTest(0.123456789e-12)54 makeTest(-9876.54321)55 makeTest(23456789012e66)56 makeTest(0)57 makeTest(1)58 makeTest(0.5)59 makeTest(98.6)60 makeTest(99.44)61 makeTest(1066)62 makeTest(1e1)63 makeTest(0.1e1)64 makeTest(1e-1)65 makeTest(1)66 makeTest(2)67 makeTest(2)68 makeTest(-42)69 })70 describe('Strings', function () {71 makeTest('')72 makeTest(';')73 makeTest('@')74 makeTest('/')75 makeTest('|')76 makeTest('&')77 makeTest(' ')78 makeTest('"')79 makeTest('\\')80 makeTest('\b\f\n\r\t')81 makeTest('/ & /')82 makeTest('abcdefghijklmnopqrstuvwyz')83 makeTest('ABCDEFGHIJKLMNOPQRSTUVWYZ')84 makeTest('0123456789')85 makeTest("`1~!@#$%^&*()_+-={':[,]}|;.</>?")86 makeTest('\u0123\u4567\u89AB\uCDEF\uabcd\uef4A')87 makeTest('// /* <!-- --')88 makeTest('# -- --> */')89 makeTest('@:0&@:0&@:0&:0')90 makeTest('{"object with 1 member":["array with 1 element"]}')91 makeTest('&#34; \u0022 %22 0x22 034 &#x22;')92 makeTest(93 '/\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?'94 )95 })96 describe('Array', function () {97 makeTest([])98 makeTest([[0]])99 makeTest([[[[[0]]]]])100 makeTest([[[[[0], 0]], 0]])101 makeTest([0, [0, [0, 0]]])102 makeTest([null])103 makeTest([undefined])104 })105 describe('Object', function () {106 makeTest({})107 makeTest({ '': '' })108 makeTest({ a: { b: 1 }, c: 'x' })109 })110 describe('Complex', function () {111 makeTest([{}, {}])112 makeTest({ foo: [2, { bar: [4, { baz: [6, { 'deep enough': 7 }] }] }] })113 makeTest({114 num: 1,115 alpha: 'abc',116 ignore: 'me',117 change: 'to a function',118 toUpper: true,119 obj: { nested_num: 50, undef: undefined, alpha: 'abc', nullable: null },120 arr: [1, 7, 2],121 })122 makeTest([123 'JSON makeTest Pattern pass1',124 { 'object with 1 member': ['array with 1 element'] },125 {},126 [],127 -42,128 true,129 false,130 null,131 {132 integer: 1234567890,133 real: -9876.54321,134 e: 0.123456789e-12,135 E: 1.23456789e34,136 '': 23456789012e66,137 zero: 0,138 one: 1,139 space: ' ',140 quote: '"',141 backslash: '\\',142 controls: '\b\f\n\r\t',143 slash: '/ & /',144 alpha: 'abcdefghijklmnopqrstuvwyz',145 ALPHA: 'ABCDEFGHIJKLMNOPQRSTUVWYZ',146 digit: '0123456789',147 '0123456789': 'digit',148 special: "`1~!@#$%^&*()_+-={':[,]}|;.</>?",149 hex: '\u0123\u4567\u89AB\uCDEF\uabcd\uef4A',150 true: true,151 false: false,152 null: null,153 array: [],154 object: {},155 address: '50 St. James Street',156 url: 'http://www.JSON.org/',157 comment: '// /* <!-- --',158 '# -- --> */': ' ',159 ' s p a c e d ': [1, 2, 3, 4, 5, 6, 7],160 compact: [1, 2, 3, 4, 5, 6, 7],161 jsontext: '{"object with 1 member":["array with 1 element"]}',162 quotes: '&#34; \u0022 %22 0x22 034 &#x22;',163 '/\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:\',./<>?':164 'A key can be any string',165 },166 0.5,167 98.6,168 99.44,169 1066,170 1e1,171 0.1e1,172 1e-1,173 1,174 2,175 2,176 'rosebud',177 ])178 makeTest(geojson)179 })...

Full Screen

Full Screen

bindingsInDestructuringPattern.js

Source:bindingsInDestructuringPattern.js Github

copy

Full Screen

...15import {Parser} from '../../../src/syntax/Parser.js';16import {SourceFile} from '../../../src/syntax/SourceFile.js';17import bindingsInDestructuringPattern from '../../../src/semantics/bindingsInDestructuringPattern.js';18suite('bindingsInDestructuringPattern.js', function() {19 function makeTest(code, names) {20 test(code, function() {21 const parser = new Parser(new SourceFile('CODE', code));22 const tree = parser.parseScript();23 assert.equal(tree.scriptItemList.length, 1);24 const set = bindingsInDestructuringPattern(tree.scriptItemList[0]);25 assert.deepEqual(set.valuesAsArray(), names);26 });27 }28 makeTest('var x', ['x']);29 makeTest('let x = 1', ['x']);30 makeTest('const {x} = {x: 1}', ['x']);31 makeTest('var {x: y} = {x: 1}', ['y']);32 makeTest('let [x] = [1]', ['x']);33 makeTest('const [...x] = [1]', ['x']);34 makeTest('var x, y', ['x', 'y']);35 makeTest('let x = 1, y = 2', ['x', 'y']);36 makeTest('const {x, y} = {x: 1, y: 2}', ['x', 'y']);37 makeTest('var {x, y: y} = {x: 1, y: 2}', ['x', 'y']);38 makeTest('let [x, y] = [1, 2]', ['x', 'y']);39 makeTest('const [x, ...y] = [1]', ['x', 'y']);40 makeTest('var {x: {y}} = {x: {y: 2}}', ['y']);41 makeTest('let {x: {y: y}} = {x: {y: 2}}', ['y']);42 makeTest('const {x: [y]} = {x: [2]}', ['y']);43 makeTest('var {x: [...y]} = {x: [2]}', ['y']);44 makeTest('var {x = function f() { var z; }} = {x: 1}', ['x']);45 makeTest('let {x: x = function f() { var z; }} = {x: 1}', ['x']);46 makeTest('const [x = function f() { var z; }] = [1]', ['x']);47 makeTest('var {x} = {x: function f() { var z; }}', ['x']);...

Full Screen

Full Screen

calculator.js

Source:calculator.js Github

copy

Full Screen

...8 it(`add(${x},${y}) expected result ${expected} PASS`, ()=>{9 expect.equal(calculator.add(x,y), expected);10 });11 }12 makeTest(5,2)13})14describe("Add", ()=>{15 makeTest = (x,y) =>{16 let expected = x + y;17 it(`add(${x},${y}) expected result 8 Fail`, ()=>{18 expect.equal(calculator.add(x,y), 8);19 });20 }21 makeTest(5,2)22})23describe("sub", ()=>{24 makeTest = (x,y) =>{25 let expected = x - y;26 it(`sub(${x},${y}) expected result ${expected} PASS`, ()=>{27 expect.equal(calculator.sub(x,y), expected);28 });29 }30 makeTest(5,2)31})32describe("sub", ()=>{33 makeTest = (x,y) =>{34 let expected = x - y;35 it(`sub(${x},${y}) expected result 5 Fail`, ()=>{36 expect.equal(calculator.sub(x,y), 8);37 });38 }39 makeTest(5,2)40})41describe("Mul", ()=>{42 makeTest = (x,y) =>{43 let expected = x * y;44 it(`mul(${x},${y}) expected result ${expected} PASS`, ()=>{45 expect.equal(calculator.mul(x,y), expected);46 });47 }48 makeTest(5,2)49})50describe("Mul", ()=>{51 makeTest = (x,y) =>{52 let expected = x * y;53 it(`mul(${x},${y}) expected result 12 Fail`, ()=>{54 expect.equal(calculator.mul(x,y), 8);55 });56 }57 makeTest(5,2)58})59describe("Div", ()=>{60 makeTest = (x,y) =>{61 let expected = x / y;62 it(`div(${x},${y}) expected result ${expected} PASS`, ()=>{63 expect.equal(calculator.div(x,y), expected);64 });65 }66 makeTest(10,2)67})68describe("Div", ()=>{69 makeTest = (x,y) =>{70 let expected = x / y;71 it(`div(${x},${y}) expected result 8 Fail`, ()=>{72 expect.equal(calculator.div(x,y), 2);73 });74 }75 makeTest(10,2)...

Full Screen

Full Screen

vectors.js

Source:vectors.js Github

copy

Full Screen

...46 })47 })48}49if (process.argv[2]) {50 makeTest(process.argv[2], parseInt(process.argv[3], 10), true)51} else {52 vectors.forEach(function (v, i) {53 makeTest('sha', i)54 makeTest('sha1', i)55 makeTest('sha224', i)56 makeTest('sha256', i)57 makeTest('sha384', i)58 makeTest('sha512', i)59 })...

Full Screen

Full Screen

index.spec.js

Source:index.spec.js Github

copy

Full Screen

...8 done()9 })10}11describe('human timeout', () => {12 makeTest('1ns', 1e-6)13 makeTest('1us', 0.001)14 makeTest('1µs', 0.001)15 makeTest('1ms', 1)16 makeTest('1s', 1000)17 makeTest('1m', 60000)18 makeTest('1h', 3.6e+6)19 makeTest('1h30m', 3.6e+6 + 30 * 60000)20 makeTest('1.5h', 1.5 * 3.6e+6)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3mocha.addFile('test1.js');4mocha.run(function(failures){5 process.on('exit', function () {6 });7});8var assert = require('assert');9describe('Array', function() {10 describe('#indexOf()', function() {11 it('should return -1 when the value is not present', function() {12 assert.equal(-1, [1,2,3].indexOf(5));13 assert.equal(-1, [1,2,3].indexOf(0));14 });15 });16});17 #indexOf()18 1 passing (9ms)19 #indexOf()20 1 passing (9ms)21{"stats":{"suites":1,"tests":1,"passes":1,"pending":0,"failures":0,"start":"2017-04-20T06:18:15.164Z","end":"2017-04-20T06:18:15.167Z","duration":3},"tests":[{"title":"Array #indexOf() should return -1 when the value is not present","fullTitle":"Array #indexOf() should return -1 when the value is not present","timedOut":false,"duration":1,"state":"passed","speed":"fast","pass":true,"fail":false,"pending":false,"context":null,"

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3mocha.addFile('test1.js');4mocha.addFile('test2.js');5mocha.run(function(failures){6 process.on('exit', function () {7 });8});9it('should fail', function(){10 throw new Error('failed');11});12it('should pass', function(){13});14var Mocha = require('mocha');15var mocha = new Mocha();16mocha.addFile('test1.js');17mocha.addFile('test2.js');18mocha.run(function(failures){19 process.on('exit', function () {20 });21});22it('should fail', function(){23 throw new Error('failed');24});25it('should pass', function(){26});27 0 passing (1ms)28 at Context.<anonymous> (test1.js:2:9)29 Error: timeout of 2000ms exceeded. Ensure the done() callback is being

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3mocha.addFile('test.js');4mocha.run(function(failures){5 process.on('exit', function () {6 });7});8var Mocha = require('mocha');9var mocha = new Mocha();10mocha.addFile('test.js');11mocha.run(function(failures){12 process.on('exit', function () {13 });14});15var Mocha = require('mocha');16var mocha = new Mocha();17mocha.addFile('test.js');18mocha.run(function(failures){19 process.on('exit', function () {20 });21});22var Mocha = require('mocha');23var mocha = new Mocha();24mocha.addFile('test.js');25mocha.run(function(failures){26 process.on('exit', function () {27 });28});29var Mocha = require('mocha');30var mocha = new Mocha();31mocha.addFile('test.js');32mocha.run(function(failures){33 process.on('exit', function () {34 });35});36var Mocha = require('mocha');37var mocha = new Mocha();38mocha.addFile('test.js');39mocha.run(function(failures){40 process.on('exit', function () {41 });42});43var Mocha = require('mocha');

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3mocha.addFile('./test/test.js');4mocha.run(function(failures) {5 process.on('exit', function() {6 process.exit(failures);7 });8});9var assert = require('assert');10describe('Array', function() {11 describe('#indexOf()', function() {12 it('should return -1 when the value is not present', function() {13 assert.equal(-1, [1, 2, 3].indexOf(4));14 });15 });16});17Your name to display (optional):18Your name to display (optional):19Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require("mocha");2var mocha = new Mocha();3mocha.addFile("test2.js");4mocha.run(function(failures){5 process.on('exit', function () {6 });7});8var assert = require("assert");9describe('Array', function(){10 describe('#indexOf()', function(){11 it('should return -1 when the value is not present', function(){12 assert.equal(-1, [1,2,3].indexOf(5));13 assert.equal(-1, [1,2,3].indexOf(0));14 })15 })16});

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3mocha.addFile('test1.js');4mocha.addFile('test2.js');5mocha.run(function(){6 console.log('done');7});8describe('Test1', function(){9 it('should run test 1', function(done){10 done();11 });12});13describe('Test2', function(){14 it('should run test 2', function(done){15 done();16 });17});18function foo (callback) {19 var bar = 1;20 callback(null, bar);21}22it('should call callback with correct arguments', function (done) {23 var spy = sinon.spy();24 foo(spy);25 expect(spy).to.have.been.calledWith(null, 1);26 done();27});28it('should call callback with correct arguments', function (done) {29 var spy = sinon.spy();30 foo(spy);31 spy.should.have.been.calledWith(null, 1);32 done();33});34it('should call callback with correct arguments', function (done) {35 var spy = sinon.spy();36 foo(spy);37 expect(spy.calledWith(null, 1)).to.be.true;38 done();39});40it('should call callback with correct arguments', function (done) {41 var spy = sinon.spy();42 foo(spy);43 spy.calledWith(null, 1).should.be.true;44 done();45});

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha();3var path = require('path');4var test = require('./test.js');5mocha.addFile(path.join(__dirname, 'test.js'));6mocha.run(function(failures){7 process.on('exit', function () {8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var Mocha = require('mocha');2var mocha = new Mocha({3});4var fs = require('fs');5var path = require('path');6var testDir = 'test';7fs.readdirSync(testDir).filter(function(file){8 return file.substr(-3) === '.js';9}).forEach(function(file){10 mocha.addFile(11 path.join(testDir, file)12 );13});14mocha.run(function(failures){15 process.on('exit', function () {16 });17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var mocha = new Mocha({2});3var test = makeTest('test title', function() {4 console.log('test body');5});6mocha.suite.addTest(test);7mocha.run();8var mocha = new Mocha({9});10var suite = makeSuite('suite title');11var test = makeTest('test title', function() {12 console.log('test body');13});14suite.addTest(test);15mocha.suite.addSuite(suite);16mocha.run();

Full Screen

Using AI Code Generation

copy

Full Screen

1Your name to display (optional):2Your name to display (optional):3var Mocha = require('mocha');4var fs = require('fs');5var path = require('path');6var mocha = new Mocha({7 reporterOptions: {8 }9});10var testDir = 'test';11fs.readdirSync(testDir).filter(function(file) {12 return file.substr(-3) === '.js';13}).forEach(function(file) {14 mocha.addFile(15 path.join(testDir, file)16 );17});18mocha.run(function(failures) {19 process.on('exit', function () {20 });21});22Your name to display (optional):

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mocha automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful