How to use Thrower method in Cypress

Best JavaScript code snippet using cypress

context-sensitivity.js

Source:context-sensitivity.js Github

copy

Full Screen

1// Copyright 2018 the V8 project authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4// Flags: --allow-natives-syntax5const object1 = {[Symbol.toPrimitive]() { return 1; }};6const thrower = {[Symbol.toPrimitive]() { throw new Error(); }};7// Test that JSAdd is not context-sensitive.8(function() {9 function bar(fn) {10 return fn(1);11 }12 function foo(x) {13 return bar(y => y + x);14 }15 assertEquals(1, foo(0));16 assertEquals(2, foo(object1));17 assertThrows(() => foo(thrower));18 %OptimizeFunctionOnNextCall(foo);19 assertEquals(1, foo(0));20 assertEquals(2, foo(object1));21 assertThrows(() => foo(thrower));22})();23// Test that JSSubtract is not context-sensitive.24(function() {25 function bar(fn) {26 return fn(1);27 }28 function foo(x) {29 return bar(y => y - x);30 }31 assertEquals(1, foo(0));32 assertEquals(0, foo(object1));33 assertThrows(() => foo(thrower));34 %OptimizeFunctionOnNextCall(foo);35 assertEquals(1, foo(0));36 assertEquals(0, foo(object1));37 assertThrows(() => foo(thrower));38})();39// Test that JSMultiply is not context-sensitive.40(function() {41 function bar(fn) {42 return fn(1);43 }44 function foo(x) {45 return bar(y => y * x);46 }47 assertEquals(1, foo(1));48 assertEquals(1, foo(object1));49 assertThrows(() => foo(thrower));50 %OptimizeFunctionOnNextCall(foo);51 assertEquals(1, foo(1));52 assertEquals(1, foo(object1));53 assertThrows(() => foo(thrower));54})();55// Test that JSDivide is not context-sensitive.56(function() {57 function bar(fn) {58 return fn(1);59 }60 function foo(x) {61 return bar(y => y / x);62 }63 assertEquals(1, foo(1));64 assertEquals(1, foo(object1));65 assertThrows(() => foo(thrower));66 %OptimizeFunctionOnNextCall(foo);67 assertEquals(1, foo(1));68 assertEquals(1, foo(object1));69 assertThrows(() => foo(thrower));70})();71// Test that JSModulus is not context-sensitive.72(function() {73 function bar(fn) {74 return fn(1);75 }76 function foo(x) {77 return bar(y => y % x);78 }79 assertEquals(0, foo(1));80 assertEquals(0, foo(object1));81 assertThrows(() => foo(thrower));82 %OptimizeFunctionOnNextCall(foo);83 assertEquals(0, foo(1));84 assertEquals(0, foo(object1));85 assertThrows(() => foo(thrower));86})();87// Test that JSExponentiate is not context-sensitive.88(function() {89 function bar(fn) {90 return fn(1);91 }92 function foo(x) {93 return bar(y => y ** x);94 }95 assertEquals(1, foo(1));96 assertEquals(1, foo(object1));97 assertThrows(() => foo(thrower));98 %OptimizeFunctionOnNextCall(foo);99 assertEquals(1, foo(1));100 assertEquals(1, foo(object1));101 assertThrows(() => foo(thrower));102})();103// Test that JSBitwiseOr is not context-sensitive.104(function() {105 function bar(fn) {106 return fn(1);107 }108 function foo(x) {109 return bar(y => y | x);110 }111 assertEquals(1, foo(1));112 assertEquals(1, foo(object1));113 assertThrows(() => foo(thrower));114 %OptimizeFunctionOnNextCall(foo);115 assertEquals(1, foo(1));116 assertEquals(1, foo(object1));117 assertThrows(() => foo(thrower));118})();119// Test that JSBitwiseAnd is not context-sensitive.120(function() {121 function bar(fn) {122 return fn(1);123 }124 function foo(x) {125 return bar(y => y & x);126 }127 assertEquals(1, foo(1));128 assertEquals(1, foo(object1));129 assertThrows(() => foo(thrower));130 %OptimizeFunctionOnNextCall(foo);131 assertEquals(1, foo(1));132 assertEquals(1, foo(object1));133 assertThrows(() => foo(thrower));134})();135// Test that JSBitwiseXor is not context-sensitive.136(function() {137 function bar(fn) {138 return fn(1);139 }140 function foo(x) {141 return bar(y => y ^ x);142 }143 assertEquals(0, foo(1));144 assertEquals(0, foo(object1));145 assertThrows(() => foo(thrower));146 %OptimizeFunctionOnNextCall(foo);147 assertEquals(0, foo(1));148 assertEquals(0, foo(object1));149 assertThrows(() => foo(thrower));150})();151// Test that JSShiftLeft is not context-sensitive.152(function() {153 function bar(fn) {154 return fn(1);155 }156 function foo(x) {157 return bar(y => y << x);158 }159 assertEquals(2, foo(1));160 assertEquals(2, foo(object1));161 assertThrows(() => foo(thrower));162 %OptimizeFunctionOnNextCall(foo);163 assertEquals(2, foo(1));164 assertEquals(2, foo(object1));165 assertThrows(() => foo(thrower));166})();167// Test that JSShiftRight is not context-sensitive.168(function() {169 function bar(fn) {170 return fn(1);171 }172 function foo(x) {173 return bar(y => y >> x);174 }175 assertEquals(0, foo(1));176 assertEquals(0, foo(object1));177 assertThrows(() => foo(thrower));178 %OptimizeFunctionOnNextCall(foo);179 assertEquals(0, foo(1));180 assertEquals(0, foo(object1));181 assertThrows(() => foo(thrower));182})();183// Test that JSShiftRightLogical is not context-sensitive.184(function() {185 function bar(fn) {186 return fn(1);187 }188 function foo(x) {189 return bar(y => y >>> x);190 }191 assertEquals(0, foo(1));192 assertEquals(0, foo(object1));193 assertThrows(() => foo(thrower));194 %OptimizeFunctionOnNextCall(foo);195 assertEquals(0, foo(1));196 assertEquals(0, foo(object1));197 assertThrows(() => foo(thrower));198})();199// Test that JSEqual is not context-sensitive.200(function() {201 function bar(fn) {202 return fn(1);203 }204 function foo(x) {205 return bar(y => y == x);206 }207 assertFalse(foo(0));208 assertTrue(foo(object1));209 assertThrows(() => foo(thrower));210 %OptimizeFunctionOnNextCall(foo);211 assertFalse(foo(0));212 assertTrue(foo(object1));213 assertThrows(() => foo(thrower));214})();215// Test that JSLessThan is not context-sensitive.216(function() {217 function bar(fn) {218 return fn(1);219 }220 function foo(x) {221 return bar(y => y < x);222 }223 assertFalse(foo(0));224 assertFalse(foo(object1));225 assertThrows(() => foo(thrower));226 %OptimizeFunctionOnNextCall(foo);227 assertFalse(foo(0));228 assertFalse(foo(object1));229 assertThrows(() => foo(thrower));230})();231// Test that JSGreaterThan is not context-sensitive.232(function() {233 function bar(fn) {234 return fn(1);235 }236 function foo(x) {237 return bar(y => x > y);238 }239 assertFalse(foo(0));240 assertFalse(foo(object1));241 assertThrows(() => foo(thrower));242 %OptimizeFunctionOnNextCall(foo);243 assertFalse(foo(0));244 assertFalse(foo(object1));245 assertThrows(() => foo(thrower));246})();247// Test that JSLessThanOrEqual is not context-sensitive.248(function() {249 function bar(fn) {250 return fn(1);251 }252 function foo(x) {253 return bar(y => y <= x);254 }255 assertFalse(foo(0));256 assertTrue(foo(object1));257 assertThrows(() => foo(thrower));258 %OptimizeFunctionOnNextCall(foo);259 assertFalse(foo(0));260 assertTrue(foo(object1));261 assertThrows(() => foo(thrower));262})();263// Test that JSGreaterThanOrEqual is not context-sensitive.264(function() {265 function bar(fn) {266 return fn(1);267 }268 function foo(x) {269 return bar(y => x >= y);270 }271 assertFalse(foo(0));272 assertTrue(foo(object1));273 assertThrows(() => foo(thrower));274 %OptimizeFunctionOnNextCall(foo);275 assertFalse(foo(0));276 assertTrue(foo(object1));277 assertThrows(() => foo(thrower));278})();279// Test that JSInstanceOf is not context-sensitive.280(function() {281 function bar(fn) {282 return fn({});283 }284 function foo(c) {285 return bar(o => o instanceof c);286 }287 assertTrue(foo(Object));288 assertFalse(foo(Array));289 assertThrows(() => foo({[Symbol.hasInstance]() { throw new Error(); }}));290 %OptimizeFunctionOnNextCall(foo);291 assertTrue(foo(Object));292 assertFalse(foo(Array));293 assertThrows(() => foo({[Symbol.hasInstance]() { throw new Error(); }}));294})();295// Test that JSBitwiseNot is not context-sensitive.296(function() {297 function bar(fn) {298 return fn();299 }300 function foo(x) {301 return bar(() => ~x);302 }303 assertEquals(0, foo(-1));304 assertEquals(~1, foo(object1));305 assertThrows(() => foo(thrower));306 %OptimizeFunctionOnNextCall(foo);307 assertEquals(0, foo(-1));308 assertEquals(~1, foo(object1));309 assertThrows(() => foo(thrower));310})();311// Test that JSNegate is not context-sensitive.312(function() {313 function bar(fn) {314 return fn();315 }316 function foo(x) {317 return bar(() => -x);318 }319 assertEquals(1, foo(-1));320 assertEquals(-1, foo(object1));321 assertThrows(() => foo(thrower));322 %OptimizeFunctionOnNextCall(foo);323 assertEquals(1, foo(-1));324 assertEquals(-1, foo(object1));325 assertThrows(() => foo(thrower));326})();327// Test that JSIncrement is not context-sensitive.328(function() {329 function bar(fn) {330 return fn();331 }332 function foo(x) {333 return bar(() => ++x);334 }335 assertEquals(1, foo(0));336 assertEquals(2, foo(object1));337 assertThrows(() => foo(thrower));338 %OptimizeFunctionOnNextCall(foo);339 assertEquals(1, foo(0));340 assertEquals(2, foo(object1));341 assertThrows(() => foo(thrower));342})();343// Test that JSDecrement is not context-sensitive.344(function() {345 function bar(fn) {346 return fn();347 }348 function foo(x) {349 return bar(() => --x);350 }351 assertEquals(1, foo(2));352 assertEquals(0, foo(object1));353 assertThrows(() => foo(thrower));354 %OptimizeFunctionOnNextCall(foo);355 assertEquals(1, foo(2));356 assertEquals(0, foo(object1));357 assertThrows(() => foo(thrower));358})();359// Test that JSCreateArguments[UnmappedArguments] is not context-sensitive.360(function() {361 function bar(fn) {362 return fn();363 }364 function foo() {365 "use strict";366 return bar(() => arguments)[0];367 }368 assertEquals(0, foo(0, 1));369 assertEquals(1, foo(1, 2));370 assertEquals(undefined, foo());371 %OptimizeFunctionOnNextCall(foo);372 assertEquals(0, foo(0, 1));373 assertEquals(1, foo(1, 2));374 assertEquals(undefined, foo());375})();376// Test that JSCreateArguments[RestParameters] is not context-sensitive.377(function() {378 function bar(fn) {379 return fn();380 }381 function foo(...args) {382 return bar(() => args)[0];383 }384 assertEquals(0, foo(0, 1));385 assertEquals(1, foo(1, 2));386 assertEquals(undefined, foo());387 %OptimizeFunctionOnNextCall(foo);388 assertEquals(0, foo(0, 1));389 assertEquals(1, foo(1, 2));390 assertEquals(undefined, foo());391})();392// Test that JSLoadGlobal/JSStoreGlobal are not context-sensitive.393(function(global) {394 var actualValue = 'Some value';395 Object.defineProperty(global, 'globalValue', {396 configurable: true,397 enumerable: true,398 get: function() {399 return actualValue;400 },401 set: function(v) {402 actualValue = v;403 }404 });405 function bar(fn) {406 return fn();407 }408 function foo(v) {409 return bar(() => {410 const o = globalValue;411 globalValue = v;412 return o;413 });414 }415 assertEquals('Some value', foo('Another value'));416 assertEquals('Another value', actualValue);417 assertEquals('Another value', foo('Some value'));418 assertEquals('Some value', actualValue);419 %OptimizeFunctionOnNextCall(foo);420 assertEquals('Some value', foo('Another value'));421 assertEquals('Another value', actualValue);422 assertEquals('Another value', foo('Some value'));423 assertEquals('Some value', actualValue);424})(this);425// Test that for..in is not context-sensitive.426(function() {427 function bar(fn) {428 return fn();429 }430 function foo(o) {431 return bar(() => {432 var s = "";433 for (var k in o) { s += k; }434 return s;435 });436 }437 assertEquals('abc', foo({a: 1, b: 2, c: 3}));438 assertEquals('ab', foo(Object.create({a: 1, b: 2})));439 %OptimizeFunctionOnNextCall(foo);440 assertEquals('abc', foo({a: 1, b: 2, c: 3}));441 assertEquals("ab", foo(Object.create({a:1, b:2})));442})();443// Test that most generator operations are not context-sensitive.444(function() {445 function bar(fn) {446 let s = undefined;447 for (const x of fn()) {448 if (s === undefined) s = x;449 else s += x;450 }451 return s;452 }453 function foo(x, y, z) {454 return bar(function*() {455 yield x;456 yield y;457 yield z;458 });459 }460 assertEquals(6, foo(1, 2, 3));461 assertEquals("abc", foo("a", "b", "c"));462 %OptimizeFunctionOnNextCall(foo);463 assertEquals(6, foo(1, 2, 3));464 assertEquals("abc", foo("a", "b", "c"));...

Full Screen

Full Screen

exception-sequencing-binops.js

Source:exception-sequencing-binops.js Github

copy

Full Screen

1if (this.layoutTestController)2 layoutTestController.dumpAsText();3if (this.document) {4 log = function(msg) {document.getElementById("log").innerHTML += msg + "<br />";};5 fail = function(msg) {log("<span style='color: red'>FAIL: </span>" + msg) };6 pass = function(msg) { passCount++; log("<span style='color: green'>PASS: </span>" + msg) };7} else {8 log = print;9 fail = function(msg) {log("FAIL: " + msg) };10 pass = function(msg) { passCount++; log("PASS: " + msg); };11}12var unaryOps = ['~', '+', '-', '++', '--'];13var binaryOps;14if (!binaryOps) 15 binaryOps = ['-', '+', '*', '/', '%', '|', '&', '^', '<', '<=', '>=', '>', '==', '!=', '<<', '>>'];16var valueOfThrower = { valueOf: function() { throw "throw from valueOf"; } }17var toStringThrower = { toString: function() { throw "throw from toString"; } }18var testCount = 0;19var passCount = 0;20function id(){}21function createTest(expr) {22 // For reasons i don't quite understand these tests aren't expected to throw23 if (expr == "valueOfThrower == rhsNonZeroNum") return id;24 if (expr == "toStringThrower == rhsNonZeroNum") return id;25 if (expr == "valueOfThrower != rhsNonZeroNum") return id;26 if (expr == "toStringThrower != rhsNonZeroNum") return id;27 if (expr == "valueOfThrower == rhsToStringThrower") return id;28 if (expr == "toStringThrower == rhsToStringThrower") return id;29 if (expr == "valueOfThrower != rhsToStringThrower") return id;30 if (expr == "toStringThrower != rhsToStringThrower") return id;31 // This creates a test case that ensures that a binary operand will execute the left hand expression first,32 // and will not execute the right hand side if the left hand side throws.33 var functionPrefix = "(function(){ executedRHS = false; var result = 'PASS'; try { result = ";34 var functionPostfix = "; fail('Did not throw exception with \"' + expr + '\"') } catch (e) { " +35 " if (result != 'PASS' && executedRHS) { fail('\"'+expr+'\" threw exception, but modified assignment target and executed RHS'); " +36 " } else if (result != 'PASS') { fail('\"'+expr+'\" threw exception, but modified assignment target'); " +37 " } else if (executedRHS) { fail('\"'+expr+'\" threw exception, but executed right hand half of expression')" +38 " } else { pass('Handled \"'+ expr +'\" correctly.') } } })";39 testCount++;40 try {41 return eval(functionPrefix + expr + functionPostfix);42 } catch(e) {43 throw new String(expr);44 }45}46function createTestWithRHSExec(expr) {47 // This tests that we evaluate the right hand side of a binary expression before we48 // do any type conversion with toString and/or valueOf which may throw.49 var functionPrefix = "(function(){ executedRHS = false; var result = 'PASS'; try { result = ";50 var functionPostfix = "; fail('Did not throw exception with \"' + expr + '\"') } catch (e) { " +51 " if (result != 'PASS') { fail('\"'+expr+'\" threw exception, but modified assignment target'); " +52 " } else if (!executedRHS) { fail('\"'+expr+'\" threw exception, and failed to execute RHS when expected')" +53 " } else { pass('Handled \"'+ expr +'\" correctly.') } } })";54 testCount++;55 try {56 return eval(functionPrefix + expr + functionPostfix);57 } catch(e) {58 throw new String(expr);59 }60}61__defineGetter__('throwingProperty', function(){ throw "throwing resolve"; });62var throwingPropStr = 'throwingProperty';63var valueOfThrowerStr = 'valueOfThrower';64var toStringThrowerStr = 'toStringThrower';65var throwingObjGetter = '({get throwingProperty(){ throw "throwing property" }}).throwingProperty';66rhsNonZeroNum = { valueOf: function(){ executedRHS = true; return 1; } };67rhsZeroNum = { valueOf: function(){ executedRHS = true; return 0; } };68rhsToStringThrower = { toString: function(){ executedRHS = true; return 'string'; }};69getterThrower = { get value() { throw "throwing in getter"; }};70var getterThrowerStr = "getterThrower.value";71rhsGetterTester = { get value() { executedRHS = true; return 'string'; }};72var rhsGetterTesterStr = "rhsGetterTester.value";73for (var i = 0; i < binaryOps.length; i++) {74 var currentOp = binaryOps[i];75 var numVal = currentOp == '||' ? '0' : '1';76 createTest(numVal + " " + currentOp + " " + valueOfThrowerStr )();77 createTest(numVal + " " + currentOp + " " + toStringThrowerStr)();78 createTest(numVal + " " + currentOp + " " + throwingPropStr )();79 createTest(numVal + " " + currentOp + " " + throwingObjGetter )();80 createTest(numVal + " " + currentOp + " " + getterThrowerStr )();81 createTest("'string' " + currentOp + " " + valueOfThrowerStr )();82 createTest("'string' " + currentOp + " " + toStringThrowerStr)();83 createTest("'string' " + currentOp + " " + throwingPropStr )();84 createTest("'string' " + currentOp + " " + throwingObjGetter )();85 createTest("'string' " + currentOp + " " + getterThrowerStr )();86 87 numVal = currentOp == '||' ? 'rhsZeroNum' : 'rhsNonZeroNum';88 createTest(valueOfThrowerStr + " " + currentOp + " " + numVal)();89 createTest(toStringThrowerStr + " " + currentOp + " " + numVal)();90 createTest(throwingPropStr + " " + currentOp + " " + numVal)();91 createTest(throwingObjGetter + " " + currentOp + " " + numVal)();92 createTest(getterThrowerStr + " " + currentOp + " " + numVal)();93 createTest(valueOfThrowerStr + " " + currentOp + " rhsToStringThrower")();94 createTest(toStringThrowerStr + " " + currentOp + " rhsToStringThrower")();95 createTest(throwingPropStr + " " + currentOp + " rhsToStringThrower")();96 createTest(throwingObjGetter + " " + currentOp + " rhsToStringThrower")();97 createTest(getterThrowerStr + " " + currentOp + " rhsToStringThrower")();98 createTestWithRHSExec(valueOfThrowerStr + " " + currentOp + " " + rhsGetterTesterStr)();99 createTestWithRHSExec(toStringThrowerStr + " " + currentOp + " " + rhsGetterTesterStr)();100}...

Full Screen

Full Screen

stack-traces.js

Source:stack-traces.js Github

copy

Full Screen

1loadAsset("assert.js");2function nestedThrower(msg) {3 throw new Error(msg);4}5function parentThrower(msg) {6 nestedThrower(msg);7}8function grandparentThrower(msg) {9 parentThrower(msg);10}11function ObjectThrower(msg) {12 nestedThrower(msg);13}14function nestedCapture(o, f) {15 Error.captureStackTrace(o, f);16}17function parentCapture(o, f) {18 nestedCapture(o, f);19}20function grandParentCapture(o, f) {21 parentCapture(o, f);22}23function countLines(msg) {24 if (!msg) {25 return 0;26 }27 // Subtract one for the error line, one for the newline at the end28 return msg.split('\n').length - 2;29}30// Test that toString contains the error but not the stack31// and test that the stack contains the file name32try {33 throw new Error('Test 1');34} catch (e) {35 assertFalse(e.stack == undefined);36 assertTrue(/Test 1/.test(e.toString()));37 assertFalse(/stack-traces.js/.test(e.toString()));38 assertTrue(/Test 1/.test(e.stack));39 assertTrue(/stack-traces.js/.test(e.stack));40}41// Assert that the function name is nested inside a nested stack trace42try {43 nestedThrower('Nested 1');44} catch (e) {45 assertTrue(/Nested 1/.test(e.stack));46 assertTrue(/nestedThrower/.test(e.stack));47}48// Do the same for a second level of nesting49try {50 parentThrower('Nested 2');51} catch (e) {52 assertTrue(/Nested 2/.test(e.stack));53 assertTrue(/nestedThrower/.test(e.stack));54 assertTrue(/parentThrower/.test(e.stack));55}56// Do the same for a constructor57try {58 new ObjectThrower('Nested 3');59} catch (e) {60 assertTrue(/Nested 3/.test(e.stack));61 assertTrue(/nestedThrower/.test(e.stack));62 assertTrue(/ObjectThrower/.test(e.stack));63}64// Count stack lines before and after changing limit65try {66 grandparentThrower('Count 1');67} catch (e) {68 assertTrue(countLines(e.stack) >= 3);69}70assertTrue(Error.stackTraceLimit != undefined);71Error.stackTraceLimit = 2;72assertEquals(2, Error.stackTraceLimit);73try {74 grandparentThrower('Count 2');75} catch (e) {76 assertEquals(2, countLines(e.stack));77}78Error.stackTraceLimit = 0;79assertEquals(0, Error.stackTraceLimit);80try {81 grandparentThrower('Count 3');82} catch (e) {83 assertEquals(0, countLines(e.stack));84}85Error.stackTraceLimit = Infinity;86assertEquals(Infinity, Error.stackTraceLimit);87try {88 grandparentThrower('Count 1');89} catch (e) {90 assertTrue(countLines(e.stack) >= 3);91}92// Test captureStackTrace93var o = {};94grandParentCapture(o);95assertTrue(/nestedCapture/.test(o.stack));96assertTrue(/parentCapture/.test(o.stack));97assertTrue(/grandParentCapture/.test(o.stack));98// Put in a function to be hidden from the stack99var m = {};100grandParentCapture(m, parentCapture);101assertTrue(/grandParentCapture/.test(m.stack));102assertFalse(/parentCapture/.test(m.stack));103assertFalse(/nestedCapture/.test(m.stack));104// Put in a function not in the stack105var n = {};106grandParentCapture(n, print);107assertFalse(/nestedCapture/.test(n.stack));108assertFalse(/parentCapture/.test(n.stack));109assertFalse(/grandParentCapture/.test(n.stack));110// Test prepareStackTrace111assertEquals(undefined, Error.prepareStackTrace);112var prepareCalled = false;113function diagnoseStack(err, stack) {114 var s = '';115 prepareCalled = true;116 stack.forEach(function (e) {117 assertEquals('object', typeof e);118 s += e.getFunctionName() + ' ';119 s += e.getMethodName() + ' ';120 s += e.getFileName() + ' ';121 s += e.getLineNumber() + ' ';122 s += '\n';123 });124 return s;125}126Error.prepareStackTrace = diagnoseStack;127var s1 = {};128grandParentCapture(s1);129assertTrue(/nestedCapture/.test(s1.stack));130assertTrue(/parentCapture/.test(s1.stack));131assertTrue(/grandParentCapture/.test(s1.stack));132assertTrue(prepareCalled);133// Test that it is limited by the function flag as above134var s2 = {};135grandParentCapture(s2, parentCapture);136assertFalse(/nestedCapture/.test(s2.stack));137assertFalse(/parentCapture/.test(s2.stack));138assertTrue(/grandParentCapture/.test(s2.stack));139// Test that it all works on a throw. Note that the error text isn't included.140try {141 grandparentThrower('Custom 1');142} catch (e) {143 assertTrue(/nestedThrower/.test(e.stack));144 assertTrue(/parentThrower/.test(e.stack));145}146// And test that it works the old way when we format it back147Error.prepareStackTrace = undefined;148try {149 grandparentThrower('Custom 2');150} catch (e) {151 assertTrue(/Custom 2/.test(e.stack));152 assertTrue(/nestedThrower/.test(e.stack));153 assertTrue(/parentThrower/.test(e.stack));154}155// test that all the functions on a stack frame work156function printFrame(l, f) {157 var o =158 {typeofThis: typeof f.getThis(),159 typeName: f.getTypeName(),160 function: f.getFunction(),161 functionName: f.getFunctionName(),162 methodName: f.getMethodName(),163 fileName: f.getFileName(),164 lineNumber: f.getLineNumber(),165 columnNumber: f.getColumnNumber(),166 evalOrigin: f.getEvalOrigin(),167 topLevel: f.isToplevel(),168 eval: f.isEval(),169 native: f.isNative(),170 constructor: f.isConstructor()171 };172 l.push(o);173 return l;174}175Error.prepareStackTrace = function (e, frames) {176 return frames.reduce(printFrame, []);177};178try {179 grandparentThrower('testing stack');180} catch (e) {181 e.stack.forEach(function (f) {182 verifyFrame(f);183 });184}185function verifyFrame(f) {186 assertEquals(typeof f.fileName, 'string');187 assertEquals(typeof f.lineNumber, 'number');188 assertEquals(typeof f.topLevel, 'boolean');189 assertEquals(typeof f.eval, 'boolean');190 assertEquals(typeof f.native, 'boolean');191 assertEquals(typeof f.constructor, 'boolean');...

Full Screen

Full Screen

ThrowerHandler.js

Source:ThrowerHandler.js Github

copy

Full Screen

...16 this.baseSpecialSpawn = 100;17 }18 update(speedScreen) {19 if (this.rockBlockList.length < 1) {20 this.appendThrower();21 }22 if (this.rockBlockList.length > 0 && this.rockBlockList.slice(-1)[0].posX < (this.canvas.width - this.distanceBetweenX)) {23 this.appendThrower();24 }25 this.largeEggList.forEach(largeEgg => {26 largeEgg.update(speedScreen);27 });28 this.rockBlockList.forEach(rockBlock => {29 rockBlock.update(speedScreen);30 });31 this.throwerList.forEach(thrower => {32 thrower.update(speedScreen);33 if (!thrower.fireUp && (thrower.posX < randomIntFromInterval((this.canvas.width * 0.6), (this.canvas.width * 0.8)) || (this.isVerticalScreen() && thrower.posX < this.canvas.width))) {34 thrower.startFire();35 }36 });37 this.removeFirstThrower();38 this.removeEggOutScreen();39 }40 render() {41 this.largeEggList.forEach(largeEgg => {42 largeEgg.render();43 });44 this.rockBlockList.forEach(rockBlock => {45 rockBlock.render();46 });47 this.throwerList.forEach(thrower => {48 thrower.render();49 });50 }51 reset() {52 this.throwerList = [];53 this.rockBlockList = [];54 this.largeEggList = [];55 this.rateSpecialSpawn = 1;56 this.distanceBetweenX = this.canvas.width;57 }58 appendThrower() {59 let largeEgg = this.getLargeEgg();60 let rockBlock = new RockBlock(this.canvas, this.debugMode);61 let thrower = new Thrower(this.canvas, largeEgg, this.debugMode);62 rockBlock.posX = this.canvas.width;63 this.setRockBlockPosY(rockBlock);64 this.setThrowerPos(thrower, rockBlock);65 this.largeEggList.push(largeEgg);66 this.rockBlockList.push(rockBlock);67 this.throwerList.push(thrower);68 }69 removeFirstThrower() {70 if (this.rockBlockList[0].getEndPosX() < 0) {71 this.rockBlockList.shift();72 this.throwerList.shift();73 }74 }75 removeEggOutScreen() {76 this.largeEggList = this.largeEggList.filter(function (value, index, arr) {77 let result = true;78 if (value.getEndPosX() < 0 || value.getEndPosY() < 0 || value.posY > value.canvas.height) {79 result = false;80 }81 return result;82 });83 }...

Full Screen

Full Screen

stack-traces-class-fields.js

Source:stack-traces-class-fields.js Github

copy

Full Screen

1// Copyright 2018 the V8 project authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// Flags: --harmony-class-fields6// Utility function for testing that the expected strings occur7// in the stack trace produced when running the given function.8function testTrace(name, fun, expected, unexpected) {9 var threw = false;10 try {11 fun();12 } catch (e) {13 for (var i = 0; i < expected.length; i++) {14 assertTrue(15 e.stack.indexOf(expected[i]) != -1,16 name + " doesn't contain expected[" + i + "] stack = " + e.stack17 );18 }19 if (unexpected) {20 for (var i = 0; i < unexpected.length; i++) {21 assertEquals(22 e.stack.indexOf(unexpected[i]),23 -1,24 name + " contains unexpected[" + i + "]"25 );26 }27 }28 threw = true;29 }30 assertTrue(threw, name + " didn't throw");31}32function thrower() {33 FAIL;34}35function testClassConstruction() {36 class X {37 static x = thrower();38 }39}40// ReferenceError: FAIL is not defined41// at thrower42// at <static_fields_initializer>43// at testClassConstruction44// at testTrace45testTrace(46 "during class construction",47 testClassConstruction,48 ["thrower", "<static_fields_initializer>"],49 ["anonymous"]50);51function testClassConstruction2() {52 class X {53 [thrower()];54 }55}56// ReferenceError: FAIL is not defined57// at thrower58// at testClassConstruction259// at testTrace60testTrace("during class construction2", testClassConstruction2, ["thrower"]);61function testClassInstantiation() {62 class X {63 x = thrower();64 }65 new X();66}67// ReferenceError: FAIL is not defined68// at thrower69// at X.<instance_members_initializer>70// at new X71// at testClassInstantiation72// at testTrace73testTrace(74 "during class instantiation",75 testClassInstantiation,76 ["thrower", "X.<instance_members_initializer>", "new X"],77 ["anonymous"]78);79function testClassInstantiationWithSuper() {80 class Base {}81 class X extends Base {82 x = thrower();83 }84 new X();85}86// ReferenceError: FAIL is not defined87// at thrower88// at X.<instance_members_initializer>89// at new X90// at testClassInstantiation91// at testTrace92testTrace(93 "during class instantiation with super",94 testClassInstantiationWithSuper,95 ["thrower", "X.<instance_members_initializer>", "new X"],96 ["Base", "anonymous"]97);98function testClassInstantiationWithSuper2() {99 class Base {}100 class X extends Base {101 constructor() {102 super();103 }104 x = thrower();105 }106 new X();107}108// ReferenceError: FAIL is not defined109// at thrower110// at X.<instance_members_initializer>111// at new X112// at testClassInstantiation113// at testTrace114testTrace(115 "during class instantiation with super2",116 testClassInstantiationWithSuper2,117 ["thrower", "X.<instance_members_initializer>", "new X"],118 ["Base", "anonymous"]119);120function testClassInstantiationWithSuper3() {121 class Base {122 x = thrower();123 }124 class X extends Base {125 constructor() {126 super();127 }128 }129 new X();130}131// ReferenceError: FAIL is not defined132// at thrower133// at X.<instance_members_initializer>134// at new Base135// at new X136// at testClassInstantiationWithSuper3137// at testTrace138testTrace(139 "during class instantiation with super3",140 testClassInstantiationWithSuper3,141 ["thrower", "X.<instance_members_initializer>", "new Base", "new X"],142 ["anonymous"]143);144function testClassFieldCall() {145 class X {146 x = thrower;147 }148 let x = new X();149 x.x();150}151// ReferenceError: FAIL is not defined152// at X.thrower [as x]153// at testClassFieldCall154// at testTrace155testTrace(156 "during class field call",157 testClassFieldCall,158 ["X.thrower"],159 ["anonymous"]160);161function testStaticClassFieldCall() {162 class X {163 static x = thrower;164 }165 X.x();166}167// ReferenceError: FAIL is not defined168// at Function.thrower [as x]169// at testStaticClassFieldCall170// at testTrace171testTrace(172 "during static class field call",173 testStaticClassFieldCall,174 ["Function.thrower"],175 ["anonymous"]176);177function testClassFieldCallWithFNI() {178 class X {179 x = function() {180 FAIL;181 };182 }183 let x = new X();184 x.x();185}186// ReferenceError: FAIL is not defined187// at X.x188// at testClassFieldCallWithFNI189// at testTrace190testTrace(191 "during class field call with FNI",192 testClassFieldCallWithFNI,193 ["X.x"],194 ["anonymous"]195);196function testStaticClassFieldCallWithFNI() {197 class X {198 static x = function() {199 FAIL;200 };201 }202 X.x();203}204// ReferenceError: FAIL is not defined205// at Function.x206// at testStaticClassFieldCallWithFNI207// at testTrace208testTrace(209 "during static class field call with FNI",210 testStaticClassFieldCallWithFNI,211 ["Function.x"],212 ["anonymous"]...

Full Screen

Full Screen

exception_throwers.js

Source:exception_throwers.js Github

copy

Full Screen

1Scoped.define("module:Exceptions.ExceptionThrower", [2 "module:Class"3], function(Class, scoped) {4 return Class.extend({5 scoped: scoped6 }, function(inherited) {7 /**8 * Abstract Exception Thrower Class9 * 10 * @class BetaJS.Exceptions.ExceptionThrower11 */12 return {13 /**14 * Throws an exception.15 * 16 * @param {exception} e exception to be thrown17 */18 throwException: function(e) {19 this._throwException(e);20 return this;21 },22 _throwException: function(e) {23 throw e;24 }25 };26 });27});28Scoped.define("module:Exceptions.NullExceptionThrower", [29 "module:Exceptions.ExceptionThrower"30], function(ExceptionThrower, scoped) {31 return ExceptionThrower.extend({32 scoped: scoped33 }, function(inherited) {34 /**35 * Silentely forgets about the exception.36 * 37 * @class BetaJS.Exceptions.NullExceptionThrower38 */39 return {40 /**41 * @override42 */43 _throwException: function(e) {}44 };45 });46});47Scoped.define("module:Exceptions.AsyncExceptionThrower", [48 "module:Exceptions.ExceptionThrower",49 "module:Async"50], function(ExceptionThrower, Async, scoped) {51 return ExceptionThrower.extend({52 scoped: scoped53 }, function(inherited) {54 /**55 * Throws an exception asynchronously.56 * 57 * @class BetaJS.Exceptions.AsyncExceptionThrower58 */59 return {60 /**61 * @override62 */63 _throwException: function(e) {64 Async.eventually(function() {65 throw e;66 });67 }68 };69 });70});71Scoped.define("module:Exceptions.ConsoleExceptionThrower", [72 "module:Exceptions.ExceptionThrower",73 "module:Exceptions.NativeException"74], function(ExceptionThrower, NativeException, scoped) {75 return ExceptionThrower.extend({76 scoped: scoped77 }, function(inherited) {78 /**79 * Throws execption by console-logging it.80 * 81 * @class BetaJS.Exceptions.ConsoleExceptionThrower82 */83 return {84 /**85 * @override86 */87 _throwException: function(e) {88 console.warn(e.toString());89 }90 };91 });92});93Scoped.define("module:Exceptions.EventExceptionThrower", [94 "module:Exceptions.ExceptionThrower",95 "module:Events.EventsMixin"96], function(ExceptionThrower, EventsMixin, scoped) {97 return ExceptionThrower.extend({98 scoped: scoped99 }, [EventsMixin, function(inherited) {100 /**101 * Throws exception by triggering an exception event.102 * 103 * @class BetaJS.Exceptions.EventExceptionThrower104 */105 return {106 /**107 * @override108 * @fires BetaJS.Exceptions.EventExceptionThrower#exception109 */110 _throwException: function(e) {111 /**112 * @event BetaJS.Exceptions.EventExceptionThrower#exception113 */114 this.trigger("exception", e);115 }116 };117 }]);...

Full Screen

Full Screen

stone_thrower.js

Source:stone_thrower.js Github

copy

Full Screen

1import { Unit } from './unit.js';2import { Building } from '../buildings/building.js';3import { Sprites } from '../../sprites.js';4import { Actions } from '../actions.js';5import { Stone } from '../projectiles.js';6import { UNIT_TYPES, FPS } from '../../utils.js';7class StoneThrower extends Unit {8 constructor() {9 super(...arguments);10 this.lastShot = 0;11 }12 getProjectileType() {13 return Stone14 }15 getProjectileOffset() {16 return { x: 22, y: -63 }17 }18 getProjectileZOffset() {19 return 4;20 }21 get ACTIONS() {22 return [Actions.StandGround, Actions.Stop];23 }24}25StoneThrower.prototype.SUBTILE_WIDTH = 3;26StoneThrower.prototype.NAME = ["Stone Thrower"];27StoneThrower.prototype.AVATAR = [Sprites.Sprite("img/interface/avatars/stone_thrower.png")];28StoneThrower.prototype.TYPE = UNIT_TYPES.SIEGE;29StoneThrower.prototype.MAX_HP = [75];30StoneThrower.prototype.SPEED = 0.72;31StoneThrower.prototype.CREATION_TIME = 60 * FPS;32StoneThrower.prototype.ATTACK_RATE = 3 * 3;33StoneThrower.prototype.SHOT_DELAY = FPS * 5;34StoneThrower.prototype.ATTACKS_FROM_DISTANCE = true;35StoneThrower.prototype.ACTION_KEY = "C";36StoneThrower.prototype.COST = {37 food: 0, wood: 180, stone: 0, gold: 8038}39StoneThrower.prototype.ATTRIBUTES = {40 ATTACK: [50],41 ARMOR: [0],42 RANGE: [10],43}44StoneThrower.prototype.FRAME_RATE = {45 ...Unit.prototype.FRAME_RATE,46 [StoneThrower.prototype.STATE.MOVING]: 8,47 [StoneThrower.prototype.STATE.ATTACK]: 3,48 [StoneThrower.prototype.STATE.DYING]: 449}50StoneThrower.prototype.IMAGES = {51 [StoneThrower.prototype.STATE.IDLE]: [Sprites.DirectionSprites("img/units/stone_thrower/idle/", 1)],52 [StoneThrower.prototype.STATE.MOVING]: [Sprites.DirectionSprites("img/units/stone_thrower/moving/", 4)],53 [StoneThrower.prototype.STATE.ATTACK]: [Sprites.DirectionSprites("img/units/stone_thrower/attack/", 8)],54 [StoneThrower.prototype.STATE.DYING]: [Sprites.DirectionSprites("img/units/stone_thrower/dying/", 4)],55 [StoneThrower.prototype.STATE.DEAD]: [Sprites.DirectionSprites("img/units/stone_thrower/dead/", 3)],56};57StoneThrower.prototype.IMAGE_OFFSETS = {58 [StoneThrower.prototype.STATE.IDLE]: [{ x: -4, y: 52 }],59 [StoneThrower.prototype.STATE.MOVING]: [{ x: -5, y: 52 }],60 [StoneThrower.prototype.STATE.ATTACK]: [{ x: 18, y: 78 }],61 [StoneThrower.prototype.STATE.DYING]: [{ x: 23, y: 52 }],62 [StoneThrower.prototype.STATE.DEAD]: [{ x: 19, y: 44 }],63};...

Full Screen

Full Screen

metadata.test.js

Source:metadata.test.js Github

copy

Full Screen

1import metadata from '../metadata.min.json'23import Metadata, { validateMetadata, getExtPrefix, isSupportedCountry } from './metadata'45describe('metadata', () => {6 it('should return undefined for non-defined types', () => {7 const FR = new Metadata(metadata).country('FR')8 type(FR.type('FIXED_LINE')).should.equal('undefined')9 })1011 it('should validate country', () => {12 const thrower = () => new Metadata(metadata).country('RUS')13 thrower.should.throw('Unknown country')14 })1516 it('should tell if a country is supported', () => {17 isSupportedCountry('RU', metadata).should.equal(true)18 isSupportedCountry('XX', metadata).should.equal(false)19 })2021 it('should return ext prefix for a country', () => {22 getExtPrefix('US', metadata).should.equal(' ext. ')23 getExtPrefix('CA', metadata).should.equal(' ext. ')24 getExtPrefix('GB', metadata).should.equal(' x')25 // expect(getExtPrefix('XX', metadata)).to.equal(undefined)26 getExtPrefix('XX', metadata).should.equal(' ext. ')27 })2829 it('should validate metadata', () => {30 let thrower = () => validateMetadata()31 thrower.should.throw('`metadata` argument not passed')3233 thrower = () => validateMetadata(123)34 thrower.should.throw('Got a number: 123.')3536 thrower = () => validateMetadata('abc')37 thrower.should.throw('Got a string: abc.')3839 thrower = () => validateMetadata({ a: true, b: 2 })40 thrower.should.throw('Got an object of shape: { a, b }.')4142 thrower = () => validateMetadata({ a: true, countries: 2 })43 thrower.should.throw('Got an object of shape: { a, countries }.')4445 thrower = () => validateMetadata({ country_calling_codes: true, countries: 2 })46 thrower.should.throw('Got an object of shape')4748 thrower = () => validateMetadata({ country_calling_codes: {}, countries: 2 })49 thrower.should.throw('Got an object of shape')5051 thrower = () => validateMetadata({ country_calling_codes: 1, countries: {} })52 thrower.should.throw('Got an object of shape')5354 validateMetadata({ country_calling_codes: {}, countries: {}, b: 3 })55 })56})5758function type(something) {59 return typeof something ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('Thrower', (message) => {2 throw new Error(message)3})4Cypress.Commands.add('Thrower', (message) => {5 throw new Error(message)6})7Cypress.Commands.add('Thrower', (message) => {8 throw new Error(message)9})10Cypress.Commands.add('Thrower', (message) => {11 throw new Error(message)12})13Cypress.Commands.add('Thrower', (message) => {14 throw new Error(message)15})16Cypress.Commands.add('Thrower', (message) => {17 throw new Error(message)18})19Cypress.Commands.add('Thrower', (message) => {20 throw new Error(message)21})22Cypress.Commands.add('Thrower', (message) => {23 throw new Error(message)24})25Cypress.Commands.add('Thrower', (message) => {26 throw new Error(message)27})28Cypress.Commands.add('Thrower', (message) => {29 throw new Error(message)30})31Cypress.Commands.add('Thrower', (message) => {32 throw new Error(message)33})

Full Screen

Using AI Code Generation

copy

Full Screen

1const thrower = require('cypress-thrower');2describe('My First Test', function() {3 it('Does not do much!', function() {4 thrower.throw('This is a test');5 })6})

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.on('uncaught:exception', (err, runnable) => {2 })3it('should throw an error', () => {4 cy.visit('/');5 cy.get('input').type('test');6 cy.get('button').click();7});8Cypress.on('uncaught:exception', (err, runnable) => {9 })10it('should throw an error', () => {11 cy.visit('/');12 cy.get('input').type('test');13 cy.get('button').click();14});15Cypress.on('uncaught:exception', (err, runnable) => {16 })17it('should throw an error', () => {18 cy.visit('/');19 cy.get('input').type('test');20 cy.get('button').click();21});22Cypress.on('uncaught:exception', (err, runnable) => {23 })24it('should throw an error', () => {25 cy.visit('/');26 cy.get('input').type('test');27 cy.get('button').click();28});29Cypress.on('uncaught:exception', (err, runnable) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1throw new Error('This is an error');2throw new Error('This is an error');3throw new Error('This is an error');4throw new Error('This is an error');5throw new Error('This is an error');6throw new Error('This is an error');7throw new Error('This is an error');8throw new Error('This is an error');9throw new Error('This is an error');10throw new Error('This is an error');11throw new Error('This is an error');12throw new Error('This is an error');13throw new Error('This is an error');14throw new Error('This is an error');15throw new Error('This is an error');16throw new Error('This is an error');17throw new Error('This is an error');18throw new Error('This is an error');19throw new Error('This is an error');

Full Screen

Using AI Code Generation

copy

Full Screen

1const thrower = require('cypress-thrower');2it('should throw an error', () => {3 thrower.throwError('Error Message');4});5{6 "reporterOptions": {7 },8 "throwErrors": {9 }10}11{12 "mochawesomeReporterOptions": {13 },14 "mochaJunitReporterReporterOptions": {15 }16}17const thrower = require('cypress-thrower');18it('should throw an error', () => {19 thrower.throwError('Error Message');20});21{

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress 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