Best JavaScript code snippet using cypress
expect.js
Source:expect.js
1describe('expect', function () {2 var expect = chai.expect;3 it('chai.version', function() {4 expect(chai).to.have.property('version');5 });6 it('assertion', function(){7 expect('test').to.be.a('string');8 expect('foo').to.equal('foo');9 });10 it('true', function(){11 expect(true).to.be.true;12 expect(false).to.not.be.true;13 expect(1).to.not.be.true;14 err(function(){15 expect('test').to.be.true;16 }, "expected 'test' to be true")17 });18 it('ok', function(){19 expect(true).to.be.ok;20 expect(false).to.not.be.ok;21 expect(1).to.be.ok;22 expect(0).to.not.be.ok;23 err(function(){24 expect('').to.be.ok;25 }, "expected '' to be truthy");26 err(function(){27 expect('test').to.not.be.ok;28 }, "expected 'test' to be falsy");29 });30 it('false', function(){31 expect(false).to.be.false;32 expect(true).to.not.be.false;33 expect(0).to.not.be.false;34 err(function(){35 expect('').to.be.false;36 }, "expected '' to be false")37 });38 it('null', function(){39 expect(null).to.be.null;40 expect(false).to.not.be.null;41 err(function(){42 expect('').to.be.null;43 }, "expected '' to be null")44 });45 it('undefined', function(){46 expect(undefined).to.be.undefined;47 expect(null).to.not.be.undefined;48 err(function(){49 expect('').to.be.undefined;50 }, "expected '' to be undefined")51 });52 it('exist', function(){53 var foo = 'bar'54 , bar;55 expect(foo).to.exist;56 expect(bar).to.not.exist;57 });58 it('arguments', function(){59 var args = (function(){ return arguments; })(1,2,3);60 expect(args).to.be.arguments;61 expect([]).to.not.be.arguments;62 expect(args).to.be.an('arguments').and.be.arguments;63 expect([]).to.be.an('array').and.not.be.Arguments;64 });65 it('.equal()', function(){66 var foo;67 expect(undefined).to.equal(foo);68 });69 it('typeof', function(){70 expect('test').to.be.a('string');71 err(function(){72 expect('test').to.not.be.a('string');73 }, "expected 'test' not to be a string");74 (function () {75 expect(arguments).to.be.an('arguments');76 })(1, 2);77 expect(5).to.be.a('number');78 expect(new Number(1)).to.be.a('number');79 expect(Number(1)).to.be.a('number');80 expect(true).to.be.a('boolean');81 expect(new Array()).to.be.a('array');82 expect(new Object()).to.be.a('object');83 expect({}).to.be.a('object');84 expect([]).to.be.a('array');85 expect(function() {}).to.be.a('function');86 expect(null).to.be.a('null');87 err(function(){88 expect(5).to.not.be.a('number', 'blah');89 }, "blah: expected 5 not to be a number");90 });91 it('instanceof', function(){92 function Foo(){}93 expect(new Foo()).to.be.an.instanceof(Foo);94 err(function(){95 expect(3).to.an.instanceof(Foo, 'blah');96 }, "blah: expected 3 to be an instance of Foo");97 });98 it('within(start, finish)', function(){99 expect(5).to.be.within(5, 10);100 expect(5).to.be.within(3,6);101 expect(5).to.be.within(3,5);102 expect(5).to.not.be.within(1,3);103 expect('foo').to.have.length.within(2,4);104 expect([ 1, 2, 3 ]).to.have.length.within(2,4);105 err(function(){106 expect(5).to.not.be.within(4,6, 'blah');107 }, "blah: expected 5 to not be within 4..6", 'blah');108 err(function(){109 expect(10).to.be.within(50,100, 'blah');110 }, "blah: expected 10 to be within 50..100");111 err(function () {112 expect('foo').to.have.length.within(5,7, 'blah');113 }, "blah: expected \'foo\' to have a length within 5..7");114 err(function () {115 expect([ 1, 2, 3 ]).to.have.length.within(5,7, 'blah');116 }, "blah: expected [ 1, 2, 3 ] to have a length within 5..7");117 });118 it('above(n)', function(){119 expect(5).to.be.above(2);120 expect(5).to.be.greaterThan(2);121 expect(5).to.not.be.above(5);122 expect(5).to.not.be.above(6);123 expect('foo').to.have.length.above(2);124 expect([ 1, 2, 3 ]).to.have.length.above(2);125 err(function(){126 expect(5).to.be.above(6, 'blah');127 }, "blah: expected 5 to be above 6", 'blah');128 err(function(){129 expect(10).to.not.be.above(6, 'blah');130 }, "blah: expected 10 to be at most 6");131 err(function () {132 expect('foo').to.have.length.above(4, 'blah');133 }, "blah: expected \'foo\' to have a length above 4 but got 3");134 err(function () {135 expect([ 1, 2, 3 ]).to.have.length.above(4, 'blah');136 }, "blah: expected [ 1, 2, 3 ] to have a length above 4 but got 3");137 });138 it('least(n)', function(){139 expect(5).to.be.at.least(2);140 expect(5).to.be.at.least(5);141 expect(5).to.not.be.at.least(6);142 expect('foo').to.have.length.of.at.least(2);143 expect([ 1, 2, 3 ]).to.have.length.of.at.least(2);144 err(function(){145 expect(5).to.be.at.least(6, 'blah');146 }, "blah: expected 5 to be at least 6", 'blah');147 err(function(){148 expect(10).to.not.be.at.least(6, 'blah');149 }, "blah: expected 10 to be below 6");150 err(function () {151 expect('foo').to.have.length.of.at.least(4, 'blah');152 }, "blah: expected \'foo\' to have a length at least 4 but got 3");153 err(function () {154 expect([ 1, 2, 3 ]).to.have.length.of.at.least(4, 'blah');155 }, "blah: expected [ 1, 2, 3 ] to have a length at least 4 but got 3");156 err(function () {157 expect([ 1, 2, 3, 4 ]).to.not.have.length.of.at.least(4, 'blah');158 }, "blah: expected [ 1, 2, 3, 4 ] to have a length below 4");159 });160 it('below(n)', function(){161 expect(2).to.be.below(5);162 expect(2).to.be.lessThan(5);163 expect(2).to.not.be.below(2);164 expect(2).to.not.be.below(1);165 expect('foo').to.have.length.below(4);166 expect([ 1, 2, 3 ]).to.have.length.below(4);167 err(function(){168 expect(6).to.be.below(5, 'blah');169 }, "blah: expected 6 to be below 5");170 err(function(){171 expect(6).to.not.be.below(10, 'blah');172 }, "blah: expected 6 to be at least 10");173 err(function () {174 expect('foo').to.have.length.below(2, 'blah');175 }, "blah: expected \'foo\' to have a length below 2 but got 3");176 err(function () {177 expect([ 1, 2, 3 ]).to.have.length.below(2, 'blah');178 }, "blah: expected [ 1, 2, 3 ] to have a length below 2 but got 3");179 });180 it('most(n)', function(){181 expect(2).to.be.at.most(5);182 expect(2).to.be.at.most(2);183 expect(2).to.not.be.at.most(1);184 expect(2).to.not.be.at.most(1);185 expect('foo').to.have.length.of.at.most(4);186 expect([ 1, 2, 3 ]).to.have.length.of.at.most(4);187 err(function(){188 expect(6).to.be.at.most(5, 'blah');189 }, "blah: expected 6 to be at most 5");190 err(function(){191 expect(6).to.not.be.at.most(10, 'blah');192 }, "blah: expected 6 to be above 10");193 err(function () {194 expect('foo').to.have.length.of.at.most(2, 'blah');195 }, "blah: expected \'foo\' to have a length at most 2 but got 3");196 err(function () {197 expect([ 1, 2, 3 ]).to.have.length.of.at.most(2, 'blah');198 }, "blah: expected [ 1, 2, 3 ] to have a length at most 2 but got 3");199 err(function () {200 expect([ 1, 2 ]).to.not.have.length.of.at.most(2, 'blah');201 }, "blah: expected [ 1, 2 ] to have a length above 2");202 });203 it('match(regexp)', function(){204 expect('foobar').to.match(/^foo/)205 expect('foobar').to.not.match(/^bar/)206 err(function(){207 expect('foobar').to.match(/^bar/i, 'blah')208 }, "blah: expected 'foobar' to match /^bar/i");209 err(function(){210 expect('foobar').to.not.match(/^foo/i, 'blah')211 }, "blah: expected 'foobar' not to match /^foo/i");212 });213 it('length(n)', function(){214 expect('test').to.have.length(4);215 expect('test').to.not.have.length(3);216 expect([1,2,3]).to.have.length(3);217 err(function(){218 expect(4).to.have.length(3, 'blah');219 }, 'blah: expected 4 to have a property \'length\'');220 err(function(){221 expect('asd').to.not.have.length(3, 'blah');222 }, "blah: expected 'asd' to not have a length of 3");223 });224 it('eql(val)', function(){225 expect('test').to.eql('test');226 expect({ foo: 'bar' }).to.eql({ foo: 'bar' });227 expect(1).to.eql(1);228 expect('4').to.not.eql(4);229 err(function(){230 expect(4).to.eql(3, 'blah');231 }, 'blah: expected 4 to deeply equal 3');232 });233 if ('undefined' !== typeof Buffer) {234 it('Buffer eql()', function () {235 expect(new Buffer([ 1 ])).to.eql(new Buffer([ 1 ]));236 err(function () {237 expect(new Buffer([ 0 ])).to.eql(new Buffer([ 1 ]));238 }, 'expected <Buffer 00> to deeply equal <Buffer 01>');239 });240 }241 it('equal(val)', function(){242 expect('test').to.equal('test');243 expect(1).to.equal(1);244 err(function(){245 expect(4).to.equal(3, 'blah');246 }, 'blah: expected 4 to equal 3');247 err(function(){248 expect('4').to.equal(4, 'blah');249 }, "blah: expected '4' to equal 4");250 });251 it('deep.equal(val)', function(){252 expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });253 expect({ foo: 'bar' }).not.to.deep.equal({ foo: 'baz' });254 });255 it('deep.equal(/regexp/)', function(){256 expect(/a/).to.deep.equal(/a/);257 expect(/a/).not.to.deep.equal(/b/);258 expect(/a/).not.to.deep.equal({});259 expect(/a/g).to.deep.equal(/a/g);260 expect(/a/g).not.to.deep.equal(/b/g);261 expect(/a/i).to.deep.equal(/a/i);262 expect(/a/i).not.to.deep.equal(/b/i);263 expect(/a/m).to.deep.equal(/a/m);264 expect(/a/m).not.to.deep.equal(/b/m);265 });266 it('deep.equal(Date)', function(){267 var a = new Date(1, 2, 3)268 , b = new Date(4, 5, 6);269 expect(a).to.deep.equal(a);270 expect(a).not.to.deep.equal(b);271 expect(a).not.to.deep.equal({});272 });273 it('empty', function(){274 function FakeArgs() {};275 FakeArgs.prototype.length = 0;276 expect('').to.be.empty;277 expect('foo').not.to.be.empty;278 expect([]).to.be.empty;279 expect(['foo']).not.to.be.empty;280 expect(new FakeArgs).to.be.empty;281 expect({arguments: 0}).not.to.be.empty;282 expect({}).to.be.empty;283 expect({foo: 'bar'}).not.to.be.empty;284 err(function(){285 expect('').not.to.be.empty;286 }, "expected \'\' not to be empty");287 err(function(){288 expect('foo').to.be.empty;289 }, "expected \'foo\' to be empty");290 err(function(){291 expect([]).not.to.be.empty;292 }, "expected [] not to be empty");293 err(function(){294 expect(['foo']).to.be.empty;295 }, "expected [ \'foo\' ] to be empty");296 err(function(){297 expect(new FakeArgs).not.to.be.empty;298 }, "expected { length: 0 } not to be empty");299 err(function(){300 expect({arguments: 0}).to.be.empty;301 }, "expected { arguments: 0 } to be empty");302 err(function(){303 expect({}).not.to.be.empty;304 }, "expected {} not to be empty");305 err(function(){306 expect({foo: 'bar'}).to.be.empty;307 }, "expected { foo: \'bar\' } to be empty");308 });309 it('property(name)', function(){310 expect('test').to.have.property('length');311 expect(4).to.not.have.property('length');312 expect({ 'foo.bar': 'baz' })313 .to.have.property('foo.bar');314 expect({ foo: { bar: 'baz' } })315 .to.not.have.property('foo.bar');316 err(function(){317 expect('asd').to.have.property('foo');318 }, "expected 'asd' to have a property 'foo'");319 err(function(){320 expect({ foo: { bar: 'baz' } })321 .to.have.property('foo.bar');322 }, "expected { foo: { bar: 'baz' } } to have a property 'foo.bar'");323 });324 it('deep.property(name)', function(){325 expect({ 'foo.bar': 'baz'})326 .to.not.have.deep.property('foo.bar');327 expect({ foo: { bar: 'baz' } })328 .to.have.deep.property('foo.bar');329 err(function(){330 expect({ 'foo.bar': 'baz' })331 .to.have.deep.property('foo.bar');332 }, "expected { 'foo.bar': 'baz' } to have a deep property 'foo.bar'");333 });334 it('property(name, val)', function(){335 expect('test').to.have.property('length', 4);336 expect('asd').to.have.property('constructor', String);337 err(function(){338 expect('asd').to.have.property('length', 4, 'blah');339 }, "blah: expected 'asd' to have a property 'length' of 4, but got 3");340 err(function(){341 expect('asd').to.not.have.property('length', 3, 'blah');342 }, "blah: expected 'asd' to not have a property 'length' of 3");343 err(function(){344 expect('asd').to.not.have.property('foo', 3, 'blah');345 }, "blah: 'asd' has no property 'foo'");346 err(function(){347 expect('asd').to.have.property('constructor', Number, 'blah');348 }, "blah: expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]");349 });350 it('deep.property(name, val)', function(){351 expect({ foo: { bar: 'baz' } })352 .to.have.deep.property('foo.bar', 'baz');353 err(function(){354 expect({ foo: { bar: 'baz' } })355 .to.have.deep.property('foo.bar', 'quux', 'blah');356 }, "blah: expected { foo: { bar: 'baz' } } to have a deep property 'foo.bar' of 'quux', but got 'baz'");357 err(function(){358 expect({ foo: { bar: 'baz' } })359 .to.not.have.deep.property('foo.bar', 'baz', 'blah');360 }, "blah: expected { foo: { bar: 'baz' } } to not have a deep property 'foo.bar' of 'baz'");361 err(function(){362 expect({ foo: 5 })363 .to.not.have.deep.property('foo.bar', 'baz', 'blah');364 }, "blah: { foo: 5 } has no deep property 'foo.bar'");365 });366 it('ownProperty(name)', function(){367 expect('test').to.have.ownProperty('length');368 expect('test').to.haveOwnProperty('length');369 expect({ length: 12 }).to.have.ownProperty('length');370 err(function(){371 expect({ length: 12 }).to.not.have.ownProperty('length', 'blah');372 }, "blah: expected { length: 12 } to not have own property 'length'");373 });374 it('string()', function(){375 expect('foobar').to.have.string('bar');376 expect('foobar').to.have.string('foo');377 expect('foobar').to.not.have.string('baz');378 err(function(){379 expect(3).to.have.string('baz');380 }, "expected 3 to be a string");381 err(function(){382 expect('foobar').to.have.string('baz', 'blah');383 }, "blah: expected 'foobar' to contain 'baz'");384 err(function(){385 expect('foobar').to.not.have.string('bar', 'blah');386 }, "blah: expected 'foobar' to not contain 'bar'");387 });388 it('include()', function(){389 expect(['foo', 'bar']).to.include('foo');390 expect(['foo', 'bar']).to.include('foo');391 expect(['foo', 'bar']).to.include('bar');392 expect([1,2]).to.include(1);393 expect(['foo', 'bar']).to.not.include('baz');394 expect(['foo', 'bar']).to.not.include(1);395 expect({a:1,b:2}).to.include({b:2});396 expect({a:1,b:2}).to.not.include({b:3});397 expect({a:1,b:2}).to.include({a:1,b:2});398 expect({a:1,b:2}).to.not.include({a:1,c:2});399 err(function(){400 expect(['foo']).to.include('bar', 'blah');401 }, "blah: expected [ 'foo' ] to include 'bar'");402 err(function(){403 expect(['bar', 'foo']).to.not.include('foo', 'blah');404 }, "blah: expected [ 'bar', 'foo' ] to not include 'foo'");405 err(function(){406 expect({a:1}).to.include({b:2});407 }, "expected { a: 1 } to have a property 'b'");408 err(function(){409 expect({a:1,b:2}).to.not.include({b:2});410 }, "expected { a: 1, b: 2 } to not include { b: 2 }");411 });412 it('keys(array)', function(){413 expect({ foo: 1 }).to.have.keys(['foo']);414 expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);415 expect({ foo: 1, bar: 2 }).to.have.keys('foo', 'bar');416 expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');417 expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('bar', 'foo');418 expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('baz');419 expect({ foo: 1, bar: 2 }).to.contain.keys('foo');420 expect({ foo: 1, bar: 2 }).to.contain.keys('bar', 'foo');421 expect({ foo: 1, bar: 2 }).to.contain.keys(['foo']);422 expect({ foo: 1, bar: 2 }).to.contain.keys(['bar']);423 expect({ foo: 1, bar: 2 }).to.contain.keys(['bar', 'foo']);424 expect({ foo: 1, bar: 2 }).to.not.have.keys('baz');425 expect({ foo: 1, bar: 2 }).to.not.have.keys('foo', 'baz');426 expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz');427 expect({ foo: 1, bar: 2 }).to.not.contain.keys('foo', 'baz');428 expect({ foo: 1, bar: 2 }).to.not.contain.keys('baz', 'foo');429 err(function(){430 expect({ foo: 1 }).to.have.keys();431 }, "keys required");432 err(function(){433 expect({ foo: 1 }).to.have.keys([]);434 }, "keys required");435 err(function(){436 expect({ foo: 1 }).to.not.have.keys([]);437 }, "keys required");438 err(function(){439 expect({ foo: 1 }).to.contain.keys([]);440 }, "keys required");441 err(function(){442 expect({ foo: 1 }).to.have.keys(['bar']);443 }, "expected { foo: 1 } to have key 'bar'");444 err(function(){445 expect({ foo: 1 }).to.have.keys(['bar', 'baz']);446 }, "expected { foo: 1 } to have keys 'bar', and 'baz'");447 err(function(){448 expect({ foo: 1 }).to.have.keys(['foo', 'bar', 'baz']);449 }, "expected { foo: 1 } to have keys 'foo', 'bar', and 'baz'");450 err(function(){451 expect({ foo: 1 }).to.not.have.keys(['foo']);452 }, "expected { foo: 1 } to not have key 'foo'");453 err(function(){454 expect({ foo: 1 }).to.not.have.keys(['foo']);455 }, "expected { foo: 1 } to not have key 'foo'");456 err(function(){457 expect({ foo: 1, bar: 2 }).to.not.have.keys(['foo', 'bar']);458 }, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");459 err(function(){460 expect({ foo: 1 }).to.not.contain.keys(['foo']);461 }, "expected { foo: 1 } to not contain key 'foo'");462 err(function(){463 expect({ foo: 1 }).to.contain.keys('foo', 'bar');464 }, "expected { foo: 1 } to contain keys 'foo', and 'bar'");465 });466 it('chaining', function(){467 var tea = { name: 'chai', extras: ['milk', 'sugar', 'smile'] };468 expect(tea).to.have.property('extras').with.lengthOf(3);469 err(function(){470 expect(tea).to.have.property('extras').with.lengthOf(4);471 }, "expected [ 'milk', 'sugar', 'smile' ] to have a length of 4 but got 3");472 expect(tea).to.be.a('object').and.have.property('name', 'chai');473 var badFn = function () { throw new Error('testing'); };474 expect(badFn).to.throw(Error).with.property('message', 'testing');475 });476 it('throw', function () {477 // See GH-45: some poorly-constructed custom errors don't have useful names478 // on either their constructor or their constructor prototype, but instead479 // only set the name inside the constructor itself.480 var PoorlyConstructedError = function () {481 this.name = 'PoorlyConstructedError';482 };483 PoorlyConstructedError.prototype = Object.create(Error.prototype);484 function CustomError(message) {485 this.name = 'CustomError';486 this.message = message;487 }488 CustomError.prototype = Error.prototype;489 var specificError = new RangeError('boo');490 var goodFn = function () { 1==1; }491 , badFn = function () { throw new Error('testing'); }492 , refErrFn = function () { throw new ReferenceError('hello'); }493 , ickyErrFn = function () { throw new PoorlyConstructedError(); }494 , specificErrFn = function () { throw specificError; }495 , customErrFn = function() { throw new CustomError('foo'); };496 expect(goodFn).to.not.throw();497 expect(goodFn).to.not.throw(Error);498 expect(goodFn).to.not.throw(specificError);499 expect(badFn).to.throw();500 expect(badFn).to.throw(Error);501 expect(badFn).to.not.throw(ReferenceError);502 expect(badFn).to.not.throw(specificError);503 expect(refErrFn).to.throw();504 expect(refErrFn).to.throw(ReferenceError);505 expect(refErrFn).to.throw(Error);506 expect(refErrFn).to.not.throw(TypeError);507 expect(refErrFn).to.not.throw(specificError);508 expect(ickyErrFn).to.throw();509 expect(ickyErrFn).to.throw(PoorlyConstructedError);510 expect(ickyErrFn).to.throw(Error);511 expect(ickyErrFn).to.not.throw(specificError);512 expect(specificErrFn).to.throw(specificError);513 expect(badFn).to.throw(/testing/);514 expect(badFn).to.not.throw(/hello/);515 expect(badFn).to.throw('testing');516 expect(badFn).to.not.throw('hello');517 expect(badFn).to.throw(Error, /testing/);518 expect(badFn).to.throw(Error, 'testing');519 err(function(){520 expect(goodFn).to.throw();521 }, "expected [Function] to throw an error");522 err(function(){523 expect(goodFn).to.throw(ReferenceError);524 }, "expected [Function] to throw ReferenceError");525 err(function(){526 expect(goodFn).to.throw(specificError);527 }, "expected [Function] to throw 'RangeError: boo'");528 err(function(){529 expect(badFn).to.not.throw();530 }, "expected [Function] to not throw an error but 'Error: testing' was thrown");531 err(function(){532 expect(badFn).to.throw(ReferenceError);533 }, "expected [Function] to throw 'ReferenceError' but 'Error: testing' was thrown");534 err(function(){535 expect(badFn).to.throw(specificError);536 }, "expected [Function] to throw 'RangeError: boo' but 'Error: testing' was thrown");537 err(function(){538 expect(badFn).to.not.throw(Error);539 }, "expected [Function] to not throw 'Error' but 'Error: testing' was thrown");540 err(function(){541 expect(refErrFn).to.not.throw(ReferenceError);542 }, "expected [Function] to not throw 'ReferenceError' but 'ReferenceError: hello' was thrown");543 err(function(){544 expect(badFn).to.throw(PoorlyConstructedError);545 }, "expected [Function] to throw 'PoorlyConstructedError' but 'Error: testing' was thrown");546 err(function(){547 expect(ickyErrFn).to.not.throw(PoorlyConstructedError);548 }, /^(expected \[Function\] to not throw 'PoorlyConstructedError' but)(.*)(PoorlyConstructedError|\{ Object \()(.*)(was thrown)$/);549 err(function(){550 expect(ickyErrFn).to.throw(ReferenceError);551 }, /^(expected \[Function\] to throw 'ReferenceError' but)(.*)(PoorlyConstructedError|\{ Object \()(.*)(was thrown)$/);552 err(function(){553 expect(specificErrFn).to.throw(new ReferenceError('eek'));554 }, "expected [Function] to throw 'ReferenceError: eek' but 'RangeError: boo' was thrown");555 err(function(){556 expect(specificErrFn).to.not.throw(specificError);557 }, "expected [Function] to not throw 'RangeError: boo'");558 err(function (){559 expect(badFn).to.not.throw(/testing/);560 }, "expected [Function] to throw error not matching /testing/");561 err(function () {562 expect(badFn).to.throw(/hello/);563 }, "expected [Function] to throw error matching /hello/ but got 'testing'");564 err(function () {565 expect(badFn).to.throw(Error, /hello/, 'blah');566 }, "blah: expected [Function] to throw error matching /hello/ but got 'testing'");567 err(function () {568 expect(badFn).to.throw(Error, 'hello', 'blah');569 }, "blah: expected [Function] to throw error including 'hello' but got 'testing'");570 err(function () {571 (customErrFn).should.not.throw();572 }, "expected [Function] to not throw an error but 'CustomError: foo' was thrown");573 });574 it('respondTo', function(){575 function Foo(){};576 Foo.prototype.bar = function(){};577 Foo.func = function() {};578 var bar = {};579 bar.foo = function(){};580 expect(Foo).to.respondTo('bar');581 expect(Foo).to.not.respondTo('foo');582 expect(Foo).itself.to.respondTo('func');583 expect(Foo).itself.not.to.respondTo('bar');584 expect(bar).to.respondTo('foo');585 err(function(){586 expect(Foo).to.respondTo('baz', 'constructor');587 }, /^(constructor: expected)(.*)(\[Function: Foo\])(.*)(to respond to \'baz\')$/);588 err(function(){589 expect(bar).to.respondTo('baz', 'object');590 }, /^(object: expected)(.*)(\{ foo: \[Function\] \}|\{ Object \()(.*)(to respond to \'baz\')$/);591 });592 it('satisfy', function(){593 var matcher = function (num) {594 return num === 1;595 };596 expect(1).to.satisfy(matcher);597 err(function(){598 expect(2).to.satisfy(matcher, 'blah');599 }, "blah: expected 2 to satisfy [Function]");600 });601 it('closeTo', function(){602 expect(1.5).to.be.closeTo(1.0, 0.5);603 expect(10).to.be.closeTo(20, 20);604 expect(-10).to.be.closeTo(20, 30);605 err(function(){606 expect(2).to.be.closeTo(1.0, 0.5, 'blah');607 }, "blah: expected 2 to be close to 1 +/- 0.5");608 err(function(){609 expect(-10).to.be.closeTo(20, 29, 'blah');610 }, "blah: expected -10 to be close to 20 +/- 29");611 });612 it('include.members', function() {613 expect([1, 2, 3]).to.include.members([]);614 expect([1, 2, 3]).to.include.members([3, 2]);615 expect([1, 2, 3]).to.not.include.members([8, 4]);616 expect([1, 2, 3]).to.not.include.members([1, 2, 3, 4]);617 });618 it('same.members', function() {619 expect([5, 4]).to.have.same.members([4, 5]);620 expect([5, 4]).to.have.same.members([5, 4]);621 expect([5, 4]).to.not.have.same.members([]);622 expect([5, 4]).to.not.have.same.members([6, 3]);623 expect([5, 4]).to.not.have.same.members([5, 4, 2]);624 });625 it('members', function() {626 expect([5, 4]).members([4, 5]);627 expect([5, 4]).members([5, 4]);628 expect([5, 4]).not.members([]);629 expect([5, 4]).not.members([6, 3]);630 expect([5, 4]).not.members([5, 4, 2]);631 })...
should.js
Source:should.js
1suite('should', function() {2 var should = chai.Should();3 test('assertion', function(){4 'test'.should.be.a('string');5 should.equal('foo', 'foo');6 should.not.equal('foo', 'bar');7 });8 test('root exist', function () {9 var foo = 'foo'10 , bar = undefined;11 should.exist(foo);12 should.not.exist(bar);13 err(function () {14 should.exist(bar, 'blah');15 }, "blah: expected undefined to exist");16 err(function () {17 should.not.exist(foo, 'blah');18 }, "blah: expected 'foo' to not exist")19 });20 test('root equal', function () {21 var value1 = 'value'22 , value2 = 'value'23 , foo = 'foo';24 should.equal(value1, value2);25 should.not.equal(value1, foo);26 err(function () {27 should.equal(value1, foo, 'blah');28 }, "blah: expected 'value' to equal 'foo'");29 err(function () {30 should.not.equal(value1, value2, 'blah');31 }, "blah: expected 'value' to not equal 'value'")32 });33 test('root Throw', function () {34 should.Throw(function() { throw new Error('error!') }, Error, 'error!');35 should.not.Throw(function () { });36 err(function () {37 should.Throw(function () { throw new Error('error!') }, Error, 'needed user!', 'blah');38 }, "blah: expected [Function] to throw error including 'needed user!' but got 'error!'");39 err(function () {40 should.not.Throw(function () { throw new Error('error!') }, Error, 'error!', 'blah');41 }, "blah: expected [Function] to not throw Error but [Error: error!] was thrown");42 });43 test('true', function(){44 (true).should.be.true;45 false.should.not.be.true;46 (1).should.not.be.true;false47 false.should.have.been.false;48 err(function(){49 'test'.should.be.true;50 }, "expected 'test' to be true")51 });52 test('ok', function(){53 true.should.be.ok;54 false.should.not.be.ok;55 (1).should.be.ok;56 (0).should.not.be.ok;57 err(function(){58 ''.should.be.ok;59 }, "expected '' to be truthy");60 err(function(){61 'test'.should.not.be.ok;62 }, "expected 'test' to be falsy");63 });64 test('false', function(){65 false.should.be.false;66 true.should.not.be.false;67 (0).should.not.be.false;68 err(function(){69 ''.should.be.false;70 }, "expected '' to be false")71 });72 test('null', function(){73 (0).should.not.be.null;74 err(function(){75 ''.should.be.null;76 }, "expected '' to be null")77 });78 test('undefined', function(){79 (0).should.not.be.undefined;80 err(function(){81 ''.should.be.undefined;82 }, "expected '' to be undefined")83 });84 test('arguments', function(){85 var args = (function(){ return arguments; })(1,2,3);86 args.should.be.arguments;87 [].should.not.be.arguments;88 });89 test('.equal()', function(){90 var foo;91 should.equal(undefined, foo);92 });93 test('typeof', function(){94 'test'.should.be.a('string');95 err(function(){96 'test'.should.not.be.a('string');97 }, "expected 'test' not to be a string");98 (5).should.be.a('number');99 (new Number(1)).should.be.a('number');100 Number(1).should.be.a('number');101 (true).should.be.a('boolean');102 (new Array()).should.be.a('array');103 (new Object()).should.be.a('object');104 ({}).should.be.a('object');105 ([]).should.be.a('array');106 (function() {}).should.be.a('function');107 (5).should.be.a('number');108 err(function(){109 (5).should.not.be.a('number');110 }, "expected 5 not to be a number");111 });112 test('instanceof', function(){113 function Foo(){}114 new Foo().should.be.an.instanceof(Foo);115 err(function(){116 (3).should.an.instanceof(Foo, 'blah');117 }, "blah: expected 3 to be an instance of Foo");118 });119 test('within(start, finish)', function(){120 (5).should.be.within(5, 10);121 (5).should.be.within(3,6);122 (5).should.be.within(3,5);123 (5).should.not.be.within(1,3);124 err(function(){125 (5).should.not.be.within(4,6, 'blah');126 }, "blah: expected 5 to not be within 4..6");127 err(function(){128 (10).should.be.within(50,100, 'blah');129 }, "blah: expected 10 to be within 50..100");130 err(function(){131 ({ foo: 1 }).should.have.length.within(50,100, 'blah');132 }, "blah: expected { foo: 1 } to have a property 'length'");133 });134 test('above(n)', function(){135 (5).should.be.above(2);136 (5).should.be.greaterThan(2);137 (5).should.not.be.above(5);138 (5).should.not.be.above(6);139 err(function(){140 (5).should.be.above(6, 'blah');141 }, "blah: expected 5 to be above 6");142 err(function(){143 (10).should.not.be.above(6, 'blah');144 }, "blah: expected 10 to be at most 6");145 err(function(){146 ({foo: 1}).should.have.length.above(3, 'blah');147 }, "blah: expected { foo: 1 } to have a property 'length'");148 });149 test('least(n)', function(){150 (5).should.be.at.least(5);151 (5).should.not.be.at.least(6);152 err(function(){153 (5).should.be.at.least(6, 'blah');154 }, "blah: expected 5 to be at least 6");155 err(function(){156 (10).should.not.be.at.least(6, 'blah');157 }, "blah: expected 10 to be below 6");158 err(function(){159 ({foo: 1}).should.have.length.of.at.least(3, 'blah');160 }, "blah: expected { foo: 1 } to have a property 'length'");161 });162 test('below(n)', function(){163 (2).should.be.below(5);164 (2).should.be.lessThan(5);165 (2).should.not.be.below(2);166 (2).should.not.be.below(1);167 err(function(){168 (6).should.be.below(5, 'blah');169 }, "blah: expected 6 to be below 5");170 err(function(){171 (6).should.not.be.below(10, 'blah');172 }, "blah: expected 6 to be at least 10");173 err(function(){174 ({foo: 1}).should.have.length.below(3, 'blah');175 }, "blah: expected { foo: 1 } to have a property 'length'");176 });177 test('most(n)', function(){178 (2).should.be.at.most(2);179 (2).should.not.be.at.most(1);180 err(function(){181 (6).should.be.at.most(5, 'blah');182 }, "blah: expected 6 to be at most 5");183 err(function(){184 (6).should.not.be.at.most(10, 'blah');185 }, "blah: expected 6 to be above 10");186 err(function(){187 ({foo: 1}).should.have.length.of.at.most(3, 'blah');188 }, "blah: expected { foo: 1 } to have a property 'length'");189 });190 test('match(regexp)', function(){191 'foobar'.should.match(/^foo/)192 'foobar'.should.not.match(/^bar/)193 err(function(){194 'foobar'.should.match(/^bar/i, 'blah')195 }, "blah: expected 'foobar' to match /^bar/i");196 err(function(){197 'foobar'.should.not.match(/^foo/i, 'blah')198 }, "blah: expected 'foobar' not to match /^foo/i");199 });200 test('length(n)', function(){201 'test'.should.have.length(4);202 'test'.should.not.have.length(3);203 [1,2,3].should.have.length(3);204 err(function(){205 (4).should.have.length(3, 'blah');206 }, 'blah: expected 4 to have a property \'length\'');207 err(function(){208 'asd'.should.not.have.length(3, 'blah');209 }, "blah: expected 'asd' to not have a length of 3");210 });211 test('eql(val)', function(){212 'test'.should.eql('test');213 ({ foo: 'bar' }).should.eql({ foo: 'bar' });214 (1).should.eql(1);215 '4'.should.not.eql(4);216 err(function(){217 (4).should.eql(3, 'blah');218 }, 'blah: expected 4 to deeply equal 3');219 });220 test('equal(val)', function(){221 'test'.should.equal('test');222 (1).should.equal(1);223 err(function(){224 (4).should.equal(3, 'blah');225 }, 'blah: expected 4 to equal 3');226 err(function(){227 '4'.should.equal(4, 'blah');228 }, "blah: expected '4' to equal 4");229 });230 test('empty', function(){231 function FakeArgs() {};232 FakeArgs.prototype.length = 0;233 ''.should.be.empty;234 'foo'.should.not.be.empty;235 ([]).should.be.empty;236 (['foo']).should.not.be.empty;237 (new FakeArgs).should.be.empty;238 ({arguments: 0}).should.not.be.empty;239 ({}).should.be.empty;240 ({foo: 'bar'}).should.not.be.empty;241 err(function(){242 ''.should.not.be.empty;243 }, "expected \'\' not to be empty");244 err(function(){245 'foo'.should.be.empty;246 }, "expected \'foo\' to be empty");247 err(function(){248 ([]).should.not.be.empty;249 }, "expected [] not to be empty");250 err(function(){251 (['foo']).should.be.empty;252 }, "expected [ \'foo\' ] to be empty");253 err(function(){254 (new FakeArgs).should.not.be.empty;255 }, "expected {} not to be empty");256 err(function(){257 ({arguments: 0}).should.be.empty;258 }, "expected { arguments: 0 } to be empty");259 err(function(){260 ({}).should.not.be.empty;261 }, "expected {} not to be empty");262 err(function(){263 ({foo: 'bar'}).should.be.empty;264 }, "expected { foo: \'bar\' } to be empty");265 });266 test('property(name)', function(){267 'test'.should.have.property('length');268 (4).should.not.have.property('length');269 err(function(){270 'asd'.should.have.property('foo');271 }, "expected 'asd' to have a property 'foo'");272 });273 test('property(name, val)', function(){274 'test'.should.have.property('length', 4);275 'asd'.should.have.property('constructor', String);276 err(function(){277 'asd'.should.have.property('length', 4, 'blah');278 }, "blah: expected 'asd' to have a property 'length' of 4, but got 3");279 err(function(){280 'asd'.should.not.have.property('length', 3, 'blah');281 }, "blah: expected 'asd' to not have a property 'length' of 3");282 err(function(){283 'asd'.should.not.have.property('foo', 3, 'blah');284 }, "blah: 'asd' has no property 'foo'");285 err(function(){286 'asd'.should.have.property('constructor', Number, 'blah');287 }, "blah: expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]");288 });289 test('ownProperty(name)', function(){290 'test'.should.have.ownProperty('length');291 'test'.should.haveOwnProperty('length');292 ({ length: 12 }).should.have.ownProperty('length');293 err(function(){294 ({ length: 12 }).should.not.have.ownProperty('length', 'blah');295 }, "blah: expected { length: 12 } to not have own property 'length'");296 });297 test('string()', function(){298 'foobar'.should.contain.string('bar');299 'foobar'.should.contain.string('foo');300 'foobar'.should.not.contain.string('baz');301 err(function(){302 (3).should.contain.string('baz', 'blah');303 }, "blah: expected 3 to be a string");304 err(function(){305 'foobar'.should.contain.string('baz', 'blah');306 }, "blah: expected 'foobar' to contain 'baz'");307 err(function(){308 'foobar'.should.not.contain.string('bar', 'blah');309 }, "blah: expected 'foobar' to not contain 'bar'");310 });311 test('include()', function(){312 ['foo', 'bar'].should.include('foo');313 ['foo', 'bar'].should.contain('foo');314 ['foo', 'bar'].should.include('bar');315 [1,2].should.include(1);316 ['foo', 'bar'].should.not.include('baz');317 ['foo', 'bar'].should.not.include(1);318 err(function(){319 ['foo'].should.include('bar', 'blah');320 }, "blah: expected [ 'foo' ] to include 'bar'");321 err(function(){322 ['bar', 'foo'].should.not.include('foo', 'blah');323 }, "blah: expected [ 'bar', 'foo' ] to not include 'foo'");324 });325 test('keys(array)', function(){326 ({ foo: 1 }).should.have.keys(['foo']);327 ({ foo: 1, bar: 2 }).should.have.keys(['foo', 'bar']);328 ({ foo: 1, bar: 2 }).should.have.keys('foo', 'bar');329 ({ foo: 1, bar: 2, baz: 3 }).should.include.keys('foo', 'bar');330 ({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('bar', 'foo');331 ({ foo: 1, bar: 2, baz: 3 }).should.contain.keys('baz');332 ({ foo: 1, bar: 2 }).should.contain.keys('foo');333 ({ foo: 1, bar: 2 }).should.contain.keys('bar', 'foo');334 ({ foo: 1, bar: 2 }).should.contain.keys(['foo']);335 ({ foo: 1, bar: 2 }).should.contain.keys(['bar']);336 ({ foo: 1, bar: 2 }).should.contain.keys(['bar', 'foo']);337 ({ foo: 1, bar: 2 }).should.not.have.keys('baz');338 ({ foo: 1, bar: 2 }).should.not.have.keys('foo', 'baz');339 ({ foo: 1, bar: 2 }).should.not.contain.keys('baz');340 ({ foo: 1, bar: 2 }).should.not.contain.keys('foo', 'baz');341 ({ foo: 1, bar: 2 }).should.not.contain.keys('baz', 'foo');342 err(function(){343 ({ foo: 1 }).should.have.keys();344 }, "keys required");345 err(function(){346 ({ foo: 1 }).should.have.keys([]);347 }, "keys required");348 err(function(){349 ({ foo: 1 }).should.not.have.keys([]);350 }, "keys required");351 err(function(){352 ({ foo: 1 }).should.contain.keys([]);353 }, "keys required");354 err(function(){355 ({ foo: 1 }).should.have.keys(['bar']);356 }, "expected { foo: 1 } to have key 'bar'");357 err(function(){358 ({ foo: 1 }).should.have.keys(['bar', 'baz']);359 }, "expected { foo: 1 } to have keys 'bar', and 'baz'");360 err(function(){361 ({ foo: 1 }).should.have.keys(['foo', 'bar', 'baz']);362 }, "expected { foo: 1 } to have keys 'foo', 'bar', and 'baz'");363 err(function(){364 ({ foo: 1 }).should.not.have.keys(['foo']);365 }, "expected { foo: 1 } to not have key 'foo'");366 err(function(){367 ({ foo: 1 }).should.not.have.keys(['foo']);368 }, "expected { foo: 1 } to not have key 'foo'");369 err(function(){370 ({ foo: 1, bar: 2 }).should.not.have.keys(['foo', 'bar']);371 }, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");372 err(function(){373 ({ foo: 1 }).should.not.contain.keys(['foo']);374 }, "expected { foo: 1 } to not contain key 'foo'");375 err(function(){376 ({ foo: 1 }).should.contain.keys('foo', 'bar');377 }, "expected { foo: 1 } to contain keys 'foo', and 'bar'");378 });379 test('throw', function () {380 // See GH-45: some poorly-constructed custom errors don't have useful names381 // on either their constructor or their constructor prototype, but instead382 // only set the name inside the constructor itself.383 var PoorlyConstructedError = function () {384 this.name = 'PoorlyConstructedError';385 };386 PoorlyConstructedError.prototype = Object.create(Error.prototype);387 var specificError = new RangeError('boo');388 var goodFn = function () { 1==1; }389 , badFn = function () { throw new Error('testing'); }390 , refErrFn = function () { throw new ReferenceError('hello'); }391 , ickyErrFn = function () { throw new PoorlyConstructedError(); }392 , specificErrFn = function () { throw specificError; };393 (goodFn).should.not.throw();394 (goodFn).should.not.throw(Error);395 (goodFn).should.not.throw(specificError);396 (badFn).should.throw();397 (badFn).should.throw(Error);398 (badFn).should.not.throw(ReferenceError);399 (badFn).should.not.throw(specificError);400 (refErrFn).should.throw();401 (refErrFn).should.throw(ReferenceError);402 (refErrFn).should.throw(Error);403 (refErrFn).should.not.throw(TypeError);404 (refErrFn).should.not.throw(specificError);405 (ickyErrFn).should.throw();406 (ickyErrFn).should.throw(PoorlyConstructedError);407 (ickyErrFn).should.throw(Error);408 (ickyErrFn).should.not.throw(specificError);409 (specificErrFn).should.throw(specificError);410 (badFn).should.throw(/testing/);411 (badFn).should.throw('testing');412 (badFn).should.not.throw(/hello/);413 (badFn).should.throw(Error, /testing/);414 (badFn).should.throw(Error, 'testing');415 should.throw(badFn);416 should.throw(refErrFn, ReferenceError);417 should.throw(refErrFn, Error);418 should.throw(ickyErrFn, PoorlyConstructedError);419 should.throw(specificErrFn, specificError);420 should.not.throw(goodFn);421 should.not.throw(badFn, ReferenceError);422 should.not.throw(badFn, specificError);423 should.throw(badFn, Error, /testing/);424 should.throw(badFn, Error, 'testing');425 err(function(){426 (goodFn).should.throw();427 }, "expected [Function] to throw an error");428 err(function(){429 (goodFn).should.throw(ReferenceError);430 }, "expected [Function] to throw ReferenceError");431 err(function(){432 (goodFn).should.throw(specificError);433 }, "expected [Function] to throw [RangeError: boo]");434 err(function(){435 (badFn).should.not.throw();436 }, "expected [Function] to not throw an error but [Error: testing] was thrown");437 err(function(){438 (badFn).should.throw(ReferenceError);439 }, "expected [Function] to throw ReferenceError but [Error: testing] was thrown");440 err(function(){441 (badFn).should.throw(specificError);442 }, "expected [Function] to throw [RangeError: boo] but [Error: testing] was thrown");443 err(function(){444 (badFn).should.not.throw(Error);445 }, "expected [Function] to not throw Error but [Error: testing] was thrown");446 err(function(){447 (refErrFn).should.not.throw(ReferenceError);448 }, "expected [Function] to not throw ReferenceError but [ReferenceError: hello] was thrown");449 err(function(){450 (badFn).should.throw(PoorlyConstructedError);451 }, "expected [Function] to throw PoorlyConstructedError but [Error: testing] was thrown");452 err(function(){453 (ickyErrFn).should.not.throw(PoorlyConstructedError);454 }, "expected [Function] to not throw PoorlyConstructedError but { name: 'PoorlyConstructedError' } was thrown");455 err(function(){456 (ickyErrFn).should.throw(ReferenceError);457 }, "expected [Function] to throw ReferenceError but { name: 'PoorlyConstructedError' } was thrown");458 err(function(){459 (specificErrFn).should.throw(new ReferenceError('eek'));460 }, "expected [Function] to throw [ReferenceError: eek] but [RangeError: boo] was thrown");461 err(function(){462 (specificErrFn).should.not.throw(specificError);463 }, "expected [Function] to not throw [RangeError: boo]");464 err(function (){465 (badFn).should.not.throw(/testing/);466 }, "expected [Function] to throw error not matching /testing/");467 err(function () {468 (badFn).should.throw(/hello/);469 }, "expected [Function] to throw error matching /hello/ but got \'testing\'");470 err(function () {471 (badFn).should.throw(Error, /hello/, 'blah');472 }, "blah: expected [Function] to throw error matching /hello/ but got 'testing'");473 err(function () {474 (badFn).should.throw(Error, 'hello', 'blah');475 }, "blah: expected [Function] to throw error including 'hello' but got 'testing'");476 });477 test('respondTo', function(){478 function Foo(){};479 Foo.prototype.bar = function(){};480 Foo.func = function(){};481 var bar = {};482 bar.foo = function(){};483 Foo.should.respondTo('bar');484 Foo.should.not.respondTo('foo');485 Foo.should.itself.respondTo('func');486 Foo.should.itself.not.respondTo('bar');487 bar.should.respondTo('foo');488 err(function(){489 Foo.should.respondTo('baz', 'blah');490 }, "blah: expected { [Function: Foo] func: [Function] } to respond to \'baz\'");491 err(function(){492 bar.should.respondTo('baz', 'blah');493 }, "blah: expected { foo: [Function] } to respond to \'baz\'");494 });495 test('satisfy', function(){496 var matcher = function(num){497 return num === 1;498 };499 (1).should.satisfy(matcher);500 err(function(){501 (2).should.satisfy(matcher, 'blah');502 }, "blah: expected 2 to satisfy [Function]");503 });504 test('closeTo', function(){505 (1.5).should.be.closeTo(1.0, 0.5);506 err(function(){507 (2).should.be.closeTo(1.0, 0.5, 'blah');508 }, "blah: expected 2 to be close to 1 +/- 0.5");509 });...
parse-css.test.js
Source:parse-css.test.js
1// Dependencies2// =============================================================================3import parseCss from '../src/parse-css';4import { expect } from 'chai';5// Suite6// =============================================================================7describe('parse-css', function() {8 const fixtures = window.__FIXTURES__;9 // Tests: Parsing10 // -------------------------------------------------------------------------11 describe('Parsing', function() {12 it('parses CSS to an AST (object)', function() {13 const css = fixtures['test-parse.css'];14 const ast = parseCss(css);15 expect(ast instanceof Object).to.be.true;16 expect(ast).to.have.property('type', 'stylesheet');17 });18 });19 // Tests: Errors20 // -------------------------------------------------------------------------21 describe('Errors', function() {22 it('throws an error when parsing missing opening bracket', function() {23 const css = 'p color: red; }';24 const badFn = function() {25 parseCss(css);26 };27 expect(badFn).to.throw(Error, 'missing \'{\'');28 });29 it('throws an error when parsing missing @rule opening bracket', function() {30 const css = '@media screen p color: red; }';31 const badFn = function() {32 parseCss(css);33 };34 expect(badFn).to.throw(Error, 'missing \'{\'');35 });36 it('throws an error when parsing missing closing bracket', function() {37 const css = 'p { color: red;';38 const badFn = function() {39 parseCss(css);40 };41 expect(badFn).to.throw(Error, 'missing \'}\'');42 });43 it('throws an error when parsing missing @rule closing bracket', function() {44 const css = '@media screen { p { color: red; }';45 const badFn = function() {46 parseCss(css);47 };48 expect(badFn).to.throw(Error, 'missing \'}\'');49 });50 it('throws an error when parsing missing end of comment', function() {51 const css = '/* Comment *';52 const badFn = function() {53 parseCss(css);54 };55 expect(badFn).to.throw(Error, 'end of comment');56 });57 it('throws an error when parsing extra closing bracket', function() {58 const css = 'p { color: red; }}';59 const badFn = function() {60 parseCss(css);61 };62 expect(badFn).to.throw(Error, 'closing bracket');63 });64 it('throws an error when parsing property missing colon', function() {65 const css = 'p { color red; }';66 const badFn = function() {67 parseCss(css);68 };69 expect(badFn).to.throw(Error, 'property missing \':\'');70 });71 it('throws an error when parsing missing selector', function() {72 const css = '{ color: red; }';73 const badFn = function() {74 parseCss(css);75 };76 expect(badFn).to.throw(Error, 'selector missing');77 });78 it('throws an error when parsing @keyframes with missing name', function() {79 const css = '@keyframes { from { opacity: 0; } to { opacity: 1; } }';80 const badFn = function() {81 parseCss(css);82 };83 expect(badFn).to.throw(Error, '@keyframes missing name');84 });85 it('throws an error when parsing @keyframes with missing open bracket', function() {86 const css = '@keyframes test from { opacity: 0; } to { opacity: 1; } }';87 const badFn = function() {88 parseCss(css);89 };90 expect(badFn).to.throw(Error, '@keyframes missing \'{\'');91 });92 it('throws an error when parsing @keyframes with missing closing bracket', function() {93 const css = '@keyframes test { from { opacity: 0; } to { opacity: 1; }';94 const badFn = function() {95 parseCss(css);96 };97 expect(badFn).to.throw(Error, '@keyframes missing \'}\'');98 });99 });100 // Tests: Options101 // -------------------------------------------------------------------------102 describe('Options', function() {103 describe('preserveStatic', function() {104 const cssVarDecl = `105 :root {106 --color: red;107 background: white;108 }109 `;110 const cssVarFunc = `111 p {112 color: var(--color);113 background: white;114 }115 `;116 it('false (keeps all :root declarations)', function() {117 const ast = parseCss(cssVarDecl);118 expect(ast.stylesheet.rules[0].declarations).to.have.lengthOf(2);119 });120 it('false (keeps all declarations)', function() {121 const ast = parseCss(cssVarFunc);122 expect(ast.stylesheet.rules[0].declarations).to.have.lengthOf(2);123 });124 it('true (keeps only :root variable declaration)', function() {125 const ast = parseCss(cssVarDecl, {126 preserveStatic: false127 });128 expect(ast.stylesheet.rules[0].declarations).to.have.lengthOf(1);129 });130 it('true (keeps only variable function declarations)', function() {131 const ast = parseCss(cssVarFunc, {132 preserveStatic: false133 });134 expect(ast.stylesheet.rules[0].declarations).to.have.lengthOf(1);135 });136 it('true (keeps all @font-face declarations)', function() {137 const css = `138 @font-face {139 test: var(--test);140 font-family: system;141 font-style: normal;142 }143 `;144 const ast = parseCss(css, {145 preserveStatic: false146 });147 expect(ast.stylesheet.rules[0].declarations).to.have.lengthOf(3);148 });149 it('true (remove @font-face rule)', function() {150 const css = `151 @font-face {152 font-family: system;153 font-style: normal;154 }155 `;156 const ast = parseCss(css, {157 preserveStatic: false158 });159 expect(ast.stylesheet.rules).to.have.lengthOf(0);160 });161 it('true (keeps all @keyframes declarations)', function() {162 const css = `163 @keyframes slidein {164 from {165 test: var(--test);166 height: 50%;167 width: 50%;168 }169 to {170 height: 100%;171 width: 100%;172 }173 }174 `;175 const ast = parseCss(css, {176 preserveStatic: false177 });178 expect(ast.stylesheet.rules[0].keyframes[0].declarations).to.have.lengthOf(3);179 expect(ast.stylesheet.rules[0].keyframes[1].declarations).to.have.lengthOf(2);180 });181 it('true (remove @keyframes rule)', function() {182 const css = `183 @keyframes slidein {184 from {185 height: 50%;186 width: 50%;187 }188 to {189 height: 100%;190 width: 100%;191 }192 }193 `;194 const ast = parseCss(css, {195 preserveStatic: false196 });197 expect(ast.stylesheet.rules).to.have.lengthOf(0);198 });199 it('true (keeps all @media declarations)', function() {200 const css = `201 @media screen {202 p {203 color: var(--color);204 background: white;205 }206 }207 `;208 const ast = parseCss(css, {209 preserveStatic: false210 });211 expect(ast.stylesheet.rules[0].rules[0].declarations).to.have.lengthOf(1);212 });213 it('true (remove @media rule)', function() {214 const css = `215 @media screen {216 p {217 background: white;218 }219 }220 `;221 const ast = parseCss(css, {222 preserveStatic: false223 });224 expect(ast.stylesheet.rules).to.have.lengthOf(0);225 });226 it('true (remove unrecognized @ rule)', function() {227 const css = `228 @-ms-viewport {229 background: white;230 }231 `;232 const ast = parseCss(css, {233 preserveStatic: false234 });235 expect(ast.stylesheet.rules).to.have.lengthOf(0);236 });237 });238 describe('removeComments', function() {239 const css = `240 /* COMMENT1 */241 p {242 color: red;243 }244 /* COMMENT2 */245 `;246 it('false', function() {247 const ast = parseCss(css);248 expect(ast.stylesheet.rules).to.have.lengthOf(3);249 });250 it('true', function() {251 const ast = parseCss(css, {252 removeComments: true253 });254 expect(ast.stylesheet.rules).to.have.lengthOf(1);255 });256 });257 });258 // Tests: Performance259 // -------------------------------------------------------------------------260 // describe.only('Performance', function() {261 // it('Handles large block of CSS using onlyVars option', function() {262 // const css = `263 // :root { --color: red; }264 // p { color: var(--color); }265 // ${'div { color: red; }'.repeat(10000)}266 // `;267 // console.time('Performance Test');268 // const ast = parseCss(css, {269 // preserveStatic: false270 // });271 // console.timeEnd('Performance Test');272 // console.log('CSS:', css.length);273 // console.log('rules:', ast.stylesheet.rules.length);274 // expect(ast instanceof Object).to.be.true;275 // });276 // });...
index.spec.js
Source:index.spec.js
1// Userland modules2var chai = require('chai');3// Local modules4var addon = require('../');5// Local variales6var expect = chai.expect;7describe('addon', function() {8 it('should have all expected keys', function() {9 expect(addon).to.contain.all.keys(['add']);10 });11 describe('.add', function() {12 it('should be a function', function() {13 expect(addon.add).to.be.a('function');14 });15 it('should expect 3 parameters', function() {16 expect(() => { addon.add(); }).to.throw(TypeError, 'Invalid argument count');17 expect(() => { addon.add(1); }).to.throw(TypeError, 'Invalid argument count');18 expect(() => { addon.add(1, 2); }).to.throw(TypeError, 'Invalid argument count');19 expect(() => { addon.add(1, 2, function() {}, 3); }).to.throw(TypeError, 'Invalid argument count');20 });21 it('should expect valid parameters', function(done) {22 var badFn = () => { done(new Error('callback should not have been invoked')); };23 // Invalid param 124 expect(() => { addon.add('a', 2, badFn); }).to.throw(TypeError, 'Invalid argument types');25 expect(() => { addon.add(false, 2, badFn); }).to.throw(TypeError, 'Invalid argument types');26 expect(() => { addon.add(true, 2, badFn); }).to.throw(TypeError, 'Invalid argument types');27 expect(() => { addon.add({}, 2, badFn); }).to.throw(TypeError, 'Invalid argument types');28 expect(() => { addon.add([], 2, badFn); }).to.throw(TypeError, 'Invalid argument types');29 expect(() => { addon.add([1], 2, badFn); }).to.throw(TypeError, 'Invalid argument types');30 expect(() => { addon.add(() => { 1 }, 2, badFn); }).to.throw(TypeError, 'Invalid argument types');31 // Invalid param 232 expect(() => { addon.add(1, 'b', badFn); }).to.throw(TypeError, 'Invalid argument types');33 expect(() => { addon.add(1, false, badFn); }).to.throw(TypeError, 'Invalid argument types');34 expect(() => { addon.add(1, true, badFn); }).to.throw(TypeError, 'Invalid argument types');35 expect(() => { addon.add(1, {}, badFn); }).to.throw(TypeError, 'Invalid argument types');36 expect(() => { addon.add(1, [], badFn); }).to.throw(TypeError, 'Invalid argument types');37 expect(() => { addon.add(1, [2], badFn); }).to.throw(TypeError, 'Invalid argument types');38 expect(() => { addon.add(1, () => { 2 }, badFn); }).to.throw(TypeError, 'Invalid argument types');39 // Invalid param 340 expect(() => { addon.add(1, 2, 'c'); }).to.throw(TypeError, 'Invalid argument types');41 expect(() => { addon.add(1, 2, false); }).to.throw(TypeError, 'Invalid argument types');42 expect(() => { addon.add(1, 2, true); }).to.throw(TypeError, 'Invalid argument types');43 expect(() => { addon.add(1, 2, {}); }).to.throw(TypeError, 'Invalid argument types');44 expect(() => { addon.add(1, 2, []); }).to.throw(TypeError, 'Invalid argument types');45 expect(() => { addon.add(1, 2, [3]); }).to.throw(TypeError, 'Invalid argument types');46 expect(() => { addon.add(1, 2, 3); }).to.throw(TypeError, 'Invalid argument types');47 // Invalid params 1 + 248 expect(() => { addon.add('a', 'b', badFn); }).to.throw(TypeError, 'Invalid argument types');49 expect(() => { addon.add(false, false, badFn); }).to.throw(TypeError, 'Invalid argument types');50 expect(() => { addon.add(true, true, badFn); }).to.throw(TypeError, 'Invalid argument types');51 expect(() => { addon.add({}, {}, badFn); }).to.throw(TypeError, 'Invalid argument types');52 expect(() => { addon.add([], [], badFn); }).to.throw(TypeError, 'Invalid argument types');53 expect(() => { addon.add([1], [2], badFn); }).to.throw(TypeError, 'Invalid argument types');54 expect(() => { addon.add(() => { 1 }, () => { 2 }, badFn); }).to.throw(TypeError, 'Invalid argument types');55 // Invalid params 1 + 356 expect(() => { addon.add('a', 2, 'c'); }).to.throw(TypeError, 'Invalid argument types');57 expect(() => { addon.add(false, 2, false); }).to.throw(TypeError, 'Invalid argument types');58 expect(() => { addon.add(true, 2, true); }).to.throw(TypeError, 'Invalid argument types');59 expect(() => { addon.add({}, 2, {}); }).to.throw(TypeError, 'Invalid argument types');60 expect(() => { addon.add([], 2, []); }).to.throw(TypeError, 'Invalid argument types');61 expect(() => { addon.add([1], 2, [3]); }).to.throw(TypeError, 'Invalid argument types');62 expect(() => { addon.add(() => { 1 }, 2, 3); }).to.throw(TypeError, 'Invalid argument types');63 // Invalid params 2 + 364 expect(() => { addon.add(1, 'b', 'c'); }).to.throw(TypeError, 'Invalid argument types');65 expect(() => { addon.add(1, false, false); }).to.throw(TypeError, 'Invalid argument types');66 expect(() => { addon.add(1, true, true); }).to.throw(TypeError, 'Invalid argument types');67 expect(() => { addon.add(1, {}, {}); }).to.throw(TypeError, 'Invalid argument types');68 expect(() => { addon.add(1, [], []); }).to.throw(TypeError, 'Invalid argument types');69 expect(() => { addon.add(1, [2], [3]); }).to.throw(TypeError, 'Invalid argument types');70 expect(() => { addon.add(1, () => { 2 }, 3); }).to.throw(TypeError, 'Invalid argument types');71 // Invalid params 1 + 2 + 372 expect(() => { addon.add('a', 'b', 'c'); }).to.throw(TypeError, 'Invalid argument types');73 expect(() => { addon.add(false, false, false); }).to.throw(TypeError, 'Invalid argument types');74 expect(() => { addon.add(true, true, true); }).to.throw(TypeError, 'Invalid argument types');75 expect(() => { addon.add({}, {}, {}); }).to.throw(TypeError, 'Invalid argument types');76 expect(() => { addon.add([], [], []); }).to.throw(TypeError, 'Invalid argument types');77 expect(() => { addon.add([1], [2], [3]); }).to.throw(TypeError, 'Invalid argument types');78 expect(() => { addon.add(() => { 1 }, () => { 2 }, 3); }).to.throw(TypeError, 'Invalid argument types');79 done();80 });81 it('should return `undefined`', function(done) {82 expect(addon.add(1, 2, function(err, sum) { done(err); })).to.equal(undefined);83 });84 it('should execute callback', function(done) {85 addon.add(86 1, 2,87 function(err, sum) {88 expect(err).to.not.exist;89 expect(sum).to.equal(3);90 done();91 }92 );93 });94 it('should execute callback synchronously', function() {95 // Arrange96 var step = 0;97 // Act98 addon.add(99 1, 2,100 function(err, sum) {101 // Assert more102 expect(err).to.not.exist;103 expect(sum).to.equal(3);104 expect(step).to.equal(0);105 step++;106 }107 );108 // Assert109 expect(step).to.equal(1);110 });111 it('should add numbers together', function(done) {112 var timerId,113 expectedCount = 0,114 actualCount = 0,115 sumCheckerFn = function(sumExpected) {116 expectedCount++;117 return function(err, sum) {118 if (timerId) {119 clearTimeout(timerId);120 timerId = null;121 }122 actualCount++;123 expect(err).to.not.exist;124 expect(sum).to.equal(sumExpected);125 expect(actualCount).to.be.within(0, expectedCount);126 timerId = setTimeout(127 function() {128 if (actualCount === expectedCount) {129 done();130 }131 },132 25133 );134 };135 };136 // zeroes137 addon.add(0, 0, sumCheckerFn(0));138 // zeroes + positives139 addon.add(0, 1, sumCheckerFn(1));140 addon.add(1, 0, sumCheckerFn(1));141 // zeroes + negatives142 addon.add(0, -1, sumCheckerFn(-1));143 addon.add(-1, 0, sumCheckerFn(-1));144 // positives145 addon.add(2, 3, sumCheckerFn(5));146 addon.add(3, 2, sumCheckerFn(5));147 // negatives148 addon.add(-2, -3, sumCheckerFn(-5));149 addon.add(-3, -2, sumCheckerFn(-5));150 // postives + negatives151 addon.add(2, -3, sumCheckerFn(-1));152 addon.add(-3, 2, sumCheckerFn(-1));153 addon.add(-2, 3, sumCheckerFn(1));154 addon.add(3, -2, sumCheckerFn(1));155 });156 });...
myPolyfills.test.js
Source:myPolyfills.test.js
...5 myPolyfills();6 });7 describe('Testing myMap', () => {8 it('Check â wrong type', () => {9 function badFn() {10 Array.prototype.myMap.call(true, (value) => value)11 };12 expect(badFn).to.throw(TypeError);13 });14 it('Check â no callback', () => {15 function badFn() {16 [1,2,3].myMap();17 };18 expect(badFn).to.throw(TypeError);19 });20 it('Check â simple loop', () => {21 expect(22 [1, 2, 3, 4].myMap((item) => item + 10)23 ).to.deep.equal(24 [1, 2, 3, 4].map((item) => item + 10)25 );26 });27 it('Check â string', () => {28 expect(29 Array.prototype.myMap.call('test', (value) => `${value},`)30 ).to.deep.equal(31 Array.prototype.map.call('test', (value) => `${value},`)32 );33 });34 it('Check â properties', () => {35 const arr = [1, 2, 3, 4];36 expect(arr.myMap((item, index, arr) => [item, index, arr])).to.deep.equal(37 arr.map((item, index, arr) => [item, index, arr])38 );39 });40 });41 describe('Testing myReduce', () => {42 it('Check â wrong type', () => {43 function badFn() {44 Array.prototype.myReduce.call(true, (acc, value) => acc + value)45 };46 expect(badFn).to.throw(TypeError);47 });48 it('Check â no callback', () => {49 function badFn() {50 [1,2,3].myreduce();51 };52 expect(badFn).to.throw(TypeError);53 });54 it('Check â sum', () => {55 const arr = [1, 2, 3, 4];56 expect(57 arr.myReduce((acc, value) => acc + value)58 ).to.equal(59 arr.reduce((acc, value) => acc + value)60 );61 });62 it('Check â string', () => {63 expect(64 Array.prototype.myReduce.call('test', (acc, value) => {65 acc[value] = value + 1;66 return acc;67 }, {})68 ).to.deep.equal(69 Array.prototype.reduce.call('test', (acc, value) => {70 acc[value] = value + 1;71 return acc;72 }, {})73 );74 });75 it('Check â properties', () => {76 expect(77 [1,2,3,4].myReduce((acc, value, index, arr) => {78 acc.push([value, index, arr]);79 return acc;80 }, [])81 ).to.deep.equal(82 [1,2,3,4].reduce((acc, value, index, arr) => {83 acc.push([value, index, arr]);84 return acc;85 }, [])86 );87 });88 });89 describe('Testing myFlat', () => {90 it('Check â wrong type', () => {91 function badFn() {92 Array.prototype.myFlat.call('asdfsd');93 };94 expect(badFn).to.throw(TypeError);95 });96 it('Check â without depth', () => {97 const arr = [1, 2, [3, 4, [9]]];98 expect(99 arr.myFlat()100 ).to.deep.equal(101 arr.flat()102 );103 });104 it('Check â depth 1', () => {105 const arr = [1, 2, [3, 4, [5, [6]], [9, 10]]];...
path-rewriter.spec.js
Source:path-rewriter.spec.js
...95 }96 }97 })98 it('should return undefined when no config is provided', function () {99 expect((badFn())()).to.equal(undefined)100 expect((badFn(null)())).to.equal(undefined)101 expect((badFn(undefined)())).to.equal(undefined)102 })103 it('should throw when bad config is provided', function () {104 expect(badFn(123)).to.throw(Error)105 expect(badFn('abc')).to.throw(Error)106 expect(badFn([])).to.throw(Error)107 expect(badFn([1, 2, 3])).to.throw(Error)108 })109 it('should not throw when empty Object config is provided', function () {110 expect(badFn({})).to.not.throw(Error)111 })112 it('should not throw when function config is provided', function () {113 expect(badFn(function () {})).to.not.throw(Error)114 })115 })...
stringBuilder.spec.js
Source:stringBuilder.spec.js
1const describe = require('mocha').describe;2const should = require('chai').should();3const StringBuilder = require('./../stringBuilder');4describe('String Builder tests', function () {5 let sb;6 beforeEach(function () {7 sb = new StringBuilder.StringBuilder();8 });9 describe('Constructor tests', function () {10 it('Should init StringBuilder properly without args', function () {11 sb._stringArray.should.be.a('array');12 });13 it('Should init StringBuilder properly with args', function () {14 sb = new StringBuilder.StringBuilder('Hellooo');15 sb._stringArray.should.be.a('array');16 });17 it('Should throw TyperError when arg is not a string', function () {18 const badFn = function () {19 new StringBuilder.StringBuilder([1, 2, 3]);20 };21 badFn.should.throw(TypeError);22 });23 });24 describe('Append tests', function () {25 it('Should append string to arr when empty', function () {26 sb.append('test');27 sb.toString().should.equal('test');28 });29 it('Should append string to end of arr when full', function () {30 sb.append('sth');31 sb.append('test');32 sb.toString().should.equal('sthtest');33 });34 it('Should throw TyperError when arg is not a string', function () {35 const badFn = function () {36 sb.append([1, 2, 3]);37 };38 badFn.should.throw(TypeError);39 });40 });41 describe('Prepend tests', function () {42 it('Should append string to arr', function () {43 sb.prepend('test');44 sb.toString().should.equal('test');45 });46 it('Should append string to start of arr', function () {47 sb.prepend('test');48 sb.prepend('asd');49 sb.toString().should.equal('asdtest');50 });51 it('Should throw TyperError when arg is not a string', function () {52 const badFn = function () {53 sb.append([1, 2, 3]);54 };55 badFn.should.throw(TypeError);56 });57 });58 describe('insertAt tests', function () {59 it('Should insert string to arr when empty', function () {60 sb.insertAt('test', 0);61 sb.toString().should.equal('test');62 });63 it('Should insert string to index of arr', function () {64 sb.insertAt('test', 0);65 sb.insertAt('asd', 1);66 sb.toString().should.equal('tasdest');67 });68 it('Should throw TyperError when arg is not a string', function () {69 const badFn = function () {70 sb.prepend([1, 2, 3]);71 };72 badFn.should.throw(TypeError);73 });74 });75 describe('Remove tests', function () {76 it('Should remove nothing when length 0 string', function () {77 sb.insertAt('test', 0);78 sb.remove(0, 0);79 sb.toString().should.equal('test');80 });81 it('Should remove string when length is > 0', function () {82 sb.insertAt('test', 0);83 sb.remove(0, 2);84 sb.toString().should.equal('st');85 });86 it('Should throw TyperError when arg is not a string', function () {87 const badFn = function () {88 sb.prepend([1, 2, 3]);89 };90 badFn.should.throw(TypeError);91 });92 });93 describe('toString tests', function () {94 it('Should join arr correctly', function () {95 sb.insertAt('test', 0);96 sb.toString().should.be.a('string');97 sb.toString().should.equal('test');98 });99 });...
chai2.js
Source:chai2.js
1const { expect } = require('chai')2describe('Throw Test', () => {3 const badFn = function () {4 throw new TypeError('Illegal type')5 }6 it('TypeError test', () => {7 //equal8 expect(badFn).to.throw(TypeError)9 })10 it('TypeError with Message test', () => {11 //equal12 expect(badFn).to.throw(TypeError, 'Illegal type')13 })14 it('TypeError trick', () => {15 //equal16 expect(badFn).to.throw('Illegal')17 })...
Using AI Code Generation
1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('
Using AI Code Generation
1cy.badFn();2Cypress.badFn();3cy.badFn();4Cypress.badFn();5cy.badFn();6Cypress.badFn();7cy.badFn();8Cypress.badFn();9cy.badFn();10Cypress.badFn();11cy.badFn();12Cypress.badFn();13cy.badFn();14Cypress.badFn();15cy.badFn();16Cypress.badFn();17cy.badFn();18Cypress.badFn();19cy.badFn();20Cypress.badFn();21cy.badFn();22Cypress.badFn();23cy.badFn();24Cypress.badFn();25cy.badFn();
Using AI Code Generation
1badFn();2Cypress.Commands.add('badFn', () => {3 cy.log('badFn');4});5describe('test', () => {6 it('test', () => {7 });8});9{10 "env": {11 },12 "testFiles": "**/*.{js,jsx}",13 "env": {},
Using AI Code Generation
1describe('Test', () => {2 it('should work', () => {3 cy.get('button').click()4 cy.get('h1').should('have.text', 'Hello World')5 })6})7describe('Test', () => {8 it('should work', () => {9 cy.get('button').click()10 cy.get('h1').should('have.text', 'Hello World')11 })12})13describe('Test', () => {14 it('should work', () => {15 cy.get('button').click()16 cy.get('h1').should('have.text', 'Hello World')17 })18})19describe('Test', () => {20 it('should work', () => {21 cy.get('button').click()22 cy.get('h1').should('have.text', 'Hello World')23 })24})25describe('Test', () => {26 it('should work', () => {27 cy.get('button').click()28 cy.get('h1').should('have.text', 'Hello World')29 })30})31describe('Test', () => {32 it('should work', () => {33 cy.get('button').click()34 cy.get('h1').should('have.text', 'Hello World')35 })36})37describe('Test', () => {38 it('should work', () => {39 cy.get('button').click()40 cy.get('h1').should('have.text', 'Hello World')41 })42})43describe('Test', () => {44 it('should work', () =>
Using AI Code Generation
1require('cypress-xpath')2require('cypress-xpath')3Cypress.Commands.add('badFn', (selector, value) => {4 cy.get(selector).type(value, { force: true })5})6describe('test', () => {7 it('test', () => {8 })9})10require('cypress-xpath')11Cypress.Commands.add('badFn', (selector, value) => {12 cy.get(selector).should('be.visible')13 cy.get(selector).type(value, { force: true })14})15describe('test', () => {16 it('test', () => {17 })18})19require('cypress-xpath')20Cypress.Commands.add('badFn', (selector, value) => {21 cy.get(selector).should('be.visible')22 cy.get(selector).type(value, { force: true })23})24describe('test', () => {25 it('test', () => {26 })27})
Using AI Code Generation
1Cypress.Promise.try(badFn).then(() => {2});3Cypress.Promise.try = (fn) => {4 try {5 return fn();6 } catch (err) {7 return Cypress.Promise.reject(err);8 }9};10Cypress.Promise.try(fn).then(() => {11});12Cypress.Promise.resolve(fn).then(() => {13});14Cypress.Promise.try(fn).then(() => {15});16Cypress.Promise.method(fn).then(() => {17});18Cypress.Promise.all([Cypress.Promise.try(fn), Cypress.Promise.try(fn)]).then(() => {19});20Cypress.Promise.try(fn).then(() => {21});
Using AI Code Generation
1const badFn = () => {2 return cy.wrap('badFn')3}4describe('Bad Test', () => {5 it('should fail', () => {6 cy.wrap('test').then(badFn)7 })8})9 at badFn (test.js:2)10 at Object.then (test.js:8)11const badFn = function() {12 return cy.wrap('badFn')13}14describe('Bad Test', () => {15 it('should fail', () => {16 cy.wrap('test').then(badFn)17 })18})19The Cypress.automation() method is used to send a message to the Cypress automation server. The Cypress.automation() method is used to
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.
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.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!