Best JavaScript code snippet using jest-extended
index.test.ts
Source:index.test.ts  
...24          }25          return true;26        };27        for (let _ = 0; _ < iter; _++) {28          expect(random.theta(dim)).toSatisfy(validateTheta);29          if (lambda > 0)30            expect(random.theta(dim, lambda, true)).toSatisfy(validateTheta);31        }32      };33      target.ldRunner(runner)`${''} (${0}D)`;34    });35    describe('phi', () => {36      const runner = (lambda: number, dim: number) => () => {37        const factory = Manifold(dim, lambda);38        const validatePhi = (phi: number[][]) => {39          try {40            factory.Point.validatePhi(phi);41          } catch (e) {42            if (e instanceof RangeError) return false;43            throw e;44          }45          return true;46        };47        for (let _ = 0; _ < iter; _++) {48          expect(random.phi(dim)).toSatisfy(validatePhi);49          expect(random.phi(dim, true)).toSatisfy(validatePhi);50        }51      };52      target.ldRunner(runner)`${''} (${0}D)`;53    });54  });55});56describe('Main module test', () => {57  const max_theta = 2;58  const iter = 32;59  const precision = 2;60  describe('Construction', () => {61    describe('Curvature and dimension', () => {62      {63        const runner_pass = (lambda: number) => () => {64          const p = Manifold(0, lambda);65          expect(p.dim).toBe(0);66          expect(p.lambda).toBe(lambda);67        };68        const runner_fail = (lambda: number) => () => {69          expect(() => Manifold(0, lambda)).toThrow(RangeError);70        };71        target.lambdaRunner(runner_pass, runner_fail)`${''} (${0}D)`;72      }73      const runner_pass = (lambda: number, dim: number) => () => {74        const p = Manifold(dim, lambda);75        expect(p.dim).toBe(dim);76        expect(p.lambda).toBe(lambda);77      };78      target.ldRunner(runner_pass)`${''} (${0}D)`;79      const runner_fail = (dim: number) => {80        const runner = (lambda: number) => () => {81          expect(() => Manifold(dim, lambda)).toThrow(RangeError);82        };83        target.lambdaRunner(runner)`${''} (${dim}D)`;84      };85      [0.5, -1].forEach(runner_fail);86    });87    describe('Identity', () => {88      {89        const runner_pass = (lambda: number) => () => {90          const factory = Manifold(0, lambda);91          const validateMatrix = (matrix: number[][]) => {92            try {93              factory.Point.validateMatrix(Matrix.fromArray(matrix));94            } catch (e) {95              if (e instanceof RangeError) return false;96              throw e;97            }98            return true;99          };100          const p = factory.Point.Identity();101          expect(p.matrix).toSatisfy(validateMatrix);102        };103        target.lambdaRunner(runner_pass, () => () => {104          return;105        })`${''} (${0}D)`;106      }107      const runner = (lambda: number, dim: number) => () => {108        const factory = Manifold(dim, lambda);109        const validateMatrix = (matrix: number[][]) => {110          try {111            factory.Point.validateMatrix(Matrix.fromArray(matrix));112          } catch (e) {113            if (e instanceof RangeError) return false;114            throw e;115          }116          return true;117        };118        const p = factory.Point.Identity();119        expect(p.matrix).toSatisfy(validateMatrix);120      };121      target.ldRunner(runner)`${''} (${0}D)`;122    });123    describe('Reflect', () => {124      {125        const runner_pass = (lambda: number) => () => {126          const factory = Manifold(0, lambda);127          const validateMatrix = (matrix: number[][]) => {128            try {129              factory.Point.validateMatrix(Matrix.fromArray(matrix));130            } catch (e) {131              if (e instanceof RangeError) return false;132              throw e;133            }134            return true;135          };136          const p = factory.Point.Reflect();137          expect(p.matrix).toSatisfy(validateMatrix);138        };139        target.lambdaRunner(runner_pass, () => () => {140          return;141        })`${''} (${0}D)`;142      }143      const runner = (lambda: number, dim: number) => () => {144        const factory = Manifold(dim, lambda);145        const validateMatrix = (matrix: number[][]) => {146          try {147            factory.Point.validateMatrix(Matrix.fromArray(matrix));148          } catch (e) {149            if (e instanceof RangeError) return false;150            throw e;151          }152          return true;153        };154        const p = factory.Point.Reflect();155        expect(p.matrix).toSatisfy(validateMatrix);156      };157      target.ldRunner(runner)`${''} (${0}D)`;158    });159    describe('Position', () => {160      // No test for invalid dimensionality yet.161      const runner = (lambda: number, dim: number) => () => {162        const factory = Manifold(dim, lambda);163        const validateMatrix = (matrix: number[][]) => {164          try {165            factory.Point.validateMatrix(Matrix.fromArray(matrix));166          } catch (e) {167            if (e instanceof RangeError) return false;168            throw e;169          }170          return true;171        };172        for (let _ = 0; _ < iter; _++) {173          const theta = random.theta(dim, max_theta);174          const p = factory.Point.fromPosition(theta);175          expect(p.matrix).toSatisfy(validateMatrix);176        }177      };178      target.ldRunner(runner)`${''} (${0}D)`;179    });180    it.todo('Orientation');181    it.todo('Full configuration');182    it.todo('Translation');183    it.todo('Rotation');184    it.todo('Reflection');185  });186  describe('Projection', () => {187    describe('Origin position', () => {188      const runner = (lambda: number, dim: number) => () => {189        const factory = Manifold(dim, lambda);...L4-ast.test.ts
Source:L4-ast.test.ts  
...6const p = (x: string): Result<Exp> => bind(parseSexp(x), parseL4Exp);7describe("HW3 trace expression", () => {8    it('HW3 trace expressions', () => {9        const traceExp1 = p("(trace foo)");10        expect(traceExp1).toSatisfy(isOkT(isTraceExp));11        if (isOkT(isTraceExp)(traceExp1)) {12            expect(traceExp1.value.var).toSatisfy(isVarRef);13        }14    })15})16describe('L4 Parser', () => {17    it('parses atomic expressions', () => {18        expect(p("1")).toSatisfy(isOkT(isNumExp));19        expect(p("#t")).toSatisfy(isOkT(isBoolExp));20        expect(p("x")).toSatisfy(isOkT(isVarRef));21        expect(p('"a"')).toSatisfy(isOkT(isStrExp));22        expect(p(">")).toSatisfy(isOkT(isPrimOp));23        expect(p("=")).toSatisfy(isOkT(isPrimOp));24        expect(p("string=?")).toSatisfy(isOkT(isPrimOp));25        expect(p("eq?")).toSatisfy(isOkT(isPrimOp));26        expect(p("cons")).toSatisfy(isOkT(isPrimOp));27    });28    it('parses programs', () => {29        expect(parseL4("(L4 (define x 1) (> (+ x 1) (* x x)))")).toSatisfy(isOkT(isProgram));30    });31    it('parses "define" expressions', () => {32        const def = p("(define x 1)");33        expect(def).toSatisfy(isOkT(isDefineExp));34        if (isOkT(isDefineExp)(def)) {35            expect(def.value.var).toSatisfy(isVarDecl);36            expect(def.value.val).toSatisfy(isNumExp);37        }38    });39    it('parses applications', () => {40        expect(p("(> x 1)")).toSatisfy(isOkT(isAppExp));41        expect(p("(> (+ x x) (* x x))")).toSatisfy(isOkT(isAppExp));42    });43    it('parses "if" expressions', () => {44        expect(p("(if #t 1 2)")).toSatisfy(isOkT(isIfExp));45        expect(p("(if (< x 2) x 2)")).toSatisfy(isOkT(isIfExp));46    });47    it('parses procedures', () => {48        expect(p("(lambda () 1)")).toSatisfy(isOkT(isProcExp));49        expect(p("(lambda (x) x x)")).toSatisfy(isOkT(isProcExp));50    });51    it('parses "let" expressions', () => {52        expect(p("(let ((a 1) (b #t)) (if b a (+ a 1)))")).toSatisfy(isOkT(isLetExp));53    });54    it('parses literal expressions', () => {55        expect(p("'a")).toSatisfy(isOkT(isLitExp));56        expect(p("'()")).toSatisfy(isOkT(isLitExp));57        expect(p("'(1)")).toSatisfy(isOkT(isLitExp));58    });59    it('parses "letrec" expressions', () => {60        expect(p("(letrec ((e (lambda (x) x))) (e 2))")).toSatisfy(isOkT(isLetrecExp));61    });62    it('parses "set!" expressions', () => {63        expect(p("(set! x (+ 1 2))")).toSatisfy(isOkT(isSetExp));64    });65    describe("Failures", () => {66        it("returns a Failure when parsing a single-token program", () => {67            expect(parseL4("x")).toSatisfy(isFailure);68        });69        it("returns a Failure when parsing an empty program", () => {70            expect(parseL4("")).toSatisfy(isFailure);71        });72        it("returns a Failure if the program does not start with (L3 ...)", () => {73            expect(parseL4("(+ 1 2)")).toSatisfy(isFailure);74        });75        it("returns a Failure for a program with no Exps", () => {76            expect(parseL4("(L4)")).toSatisfy(isFailure);77        });78    79        it("returns a Failure if a program has an empty Exp", () => {80            expect(parseL4("(L4 ())")).toSatisfy(isFailure);81        });82        it('returns a Failure for an ill-formed "define"', () => {83            expect(p("(define)")).toSatisfy(isFailure);84            expect(p("(define x)")).toSatisfy(isFailure);85            expect(p("(define x y z)")).toSatisfy(isFailure);86            expect(p('(define "1" y)')).toSatisfy(isFailure);87            expect(p('(define 1 y)')).toSatisfy(isFailure);88        });89        it('returns a Failure for an ill-formed "set!"', () => {90            expect(p("(set!)")).toSatisfy(isFailure);91            expect(p("(set! x)")).toSatisfy(isFailure);92            expect(p("(set! x y z)")).toSatisfy(isFailure);93            expect(p('(set! "1" y)')).toSatisfy(isFailure);94            expect(p('(set! 1 y)')).toSatisfy(isFailure);95        });96        it("returns a Failure for an empty CExp", () => {97            expect(p("(+ ())")).toSatisfy(isFailure);98        });99        it("returns a Failure for an ill-formed special form", () => {100            expect(p("(if)")).toSatisfy(isFailure);101            expect(p("(if 1)")).toSatisfy(isFailure);102            expect(p("(lambda x x)")).toSatisfy(isFailure);103            expect(p("(let x x)")).toSatisfy(isFailure);104            expect(p("(let (x y) x)")).toSatisfy(isFailure);105            expect(p("(let ((1 y)) x)")).toSatisfy(isFailure);106        });107    });108});109describe('L4 Unparse', () => {110    const roundTrip = (x: string): Result<string> =>111        bind(p(x), (exp: Exp) => makeOk(unparse(exp)));112    it("doesn't change concrete values", () => {113        const concretes = ["1", "#t", "x", '"a"', ">", "=", "string=?", "eq?", "cons"];114        concretes.forEach(concrete => {115            expect(roundTrip(concrete)).toEqual(makeOk(concrete));116        });117    });118    it('unparses programs', () => {119        const program = "(L4 (define x 1) (> (+ x 1) (* x x)))";...Using AI Code Generation
1const toSatisfy = require('jest-extended').toSatisfy;2test('the data is peanut butter', () => {3  expect('peanut butter').toSatisfy((received) => {4    return received === 'peanut butter';5  });6});7const toSatisfyAll = require('jest-extended').toSatisfyAll;8test('the data is peanut butter', () => {9  expect(['peanut butter', 'jelly']).toSatisfyAll((received) => {10    return received === 'peanut butter';11  });12});13const toSatisfyAny = require('jest-extended').toSatisfyAny;14test('the data is peanut butter', () => {15  expect(['cheese', 'jelly']).toSatisfyAny((received) => {16    return received === 'peanut butter';17  });18});19const toSatisfyAny = require('jest-extended').toSatisfyAny;20test('the data is peanut butter', () => {21  expect(['cheese', 'jelly']).toSatisfyAny((received) => {22    return received === 'peanut butter';23  });24});25const toStartWith = require('jest-extended').toStartWith;26test('the data is peanut butter', () => {27  expect('peanut butter').toStartWith('peanut');28});29const toStartWith = require('jest-extended').toStartWith;30test('the data is peanut butter', () => {31  expect('peanut butter').toStartWith('peanut');32});33const toThrowAnyError = require('jest-extended').toThrowAnyError;34test('the data is peanut butter', () => {35  expect(() => {36    throw new Error('this is an error');37  }).toThrowAnyError();38});39const toThrowErrorOfType = require('jest-extended').toThrowErrorOfType;40test('the data is peanut butter', () =>Using AI Code Generation
1const toSatisfy = require('jest-extended').toSatisfy;2expect.extend({ toSatisfy });3expect.extend({4  toSatisfy: require('jest-extended').toSatisfy,5});6expect.extend({7  toSatisfy: require('jest-extended').toSatisfy,8});9expect.extend({10  toSatisfy: require('jest-extended').toSatisfy,11});12expect.extend({13  toSatisfy: require('jest-extended').toSatisfy,14});15expect.extend({16  toSatisfy: require('jest-extended').toSatisfy,17});18expect.extend({19  toSatisfy: require('jest-extended').toSatisfy,20});21expect.extend({22  toSatisfy: require('jest-extended').toSatisfy,23});24expect.extend({25  toSatisfy: require('jest-extended').toSatisfy,26});27expect.extend({28  toSatisfy: require('jest-extended').toSatisfy,29});30expect.extend({31  toSatisfy: require('jest-extended').toSatisfy,32});33expect.extend({34  toSatisfy: require('jest-extended').toSatisfy,35});36expect.extend({37  toSatisfy: require('jest-extended').toSatisfy,38});39expect.extend({40  toSatisfy: require('jest-extended').toSatisfy,41});42expect.extend({Using AI Code Generation
1const { toSatisfy } = require('jest-extended')2expect.extend({ toSatisfy })3test('toSatisfy', () => {4  expect(1).toSatisfy((value) => value > 0)5  expect(1).not.toSatisfy((value) => value < 0)6})7const { toSatisfyAll } = require('jest-extended')8expect.extend({ toSatisfyAll })9test('toSatisfyAll', () => {10  expect([1, 2, 3]).toSatisfyAll((value) => value > 0)11  expect([1, 2, 3]).not.toSatisfyAll((value) => value < 0)12})13const { toSatisfyAny } = require('jest-extended')14expect.extend({ toSatisfyAny })15test('toSatisfyAny', () => {16  expect([1, 2, 3]).toSatisfyAny((value) => value > 0)17  expect([1, 2, 3]).not.toSatisfyAny((value) => value < 0)18})19const { toSatisfyAnyOf } = require('jest-extended')20expect.extend({ toSatisfyAnyOf })21test('toSatisfyAnyOf', () => {22  expect([1, 2, 3]).toSatisfyAnyOf([1, 2, 3])23  expect([1, 2, 3]).not.toSatisfyAnyOf([4, 5, 6])24})25const { toSatisfyNone } = require('jest-extended')26expect.extend({ toSatisfyNone })27test('toSatisfyNone', () => {28  expect([1, 2, 3]).toSatisfyNone((value) => value < 0)29  expect([1, 2, 3]).not.toSatisfyNone((value) => value > 0)30})Using AI Code Generation
1import 'jest-extended';2import { toSatisfy } from 'jest-extended';3expect.extend({ toSatisfy });4test('toSatisfy', () => {5  expect(2).toSatisfy(x => x > 1);6});7import 'jest-extended';8import { toSatisfy } from 'jest-extended';9expect.extend({ toSatisfy });10test('toSatisfy', () => {11  expect(2).toSatisfy(x => x > 1);12});13import 'jest-extended';14import { toSatisfy } from 'jest-extended';15expect.extend({ toSatisfy });16test('toSatisfy', () => {17  expect(2).toSatisfy(x => x > 1);18});19import 'jest-extended';20import { toSatisfy } from 'jest-extended';21expect.extend({ toSatisfy });22test('toSatisfy', () => {23  expect(2).toSatisfy(x => x > 1);24});25import 'jest-extended';26import { toSatisfy } from 'jest-extended';27expect.extend({ toSatisfy });28test('toSatisfy', () => {29  expect(2).toSatisfy(x => x > 1);30});31import 'jest-extended';32import { toSatisfy } from 'jest-extended';33expect.extend({ toSatisfy });34test('toSatisfy', () => {35  expect(2).toSatisfy(x => x > 1);36});37import 'jest-extended';38import { toSatisfy } from 'jest-extended';39expect.extend({ toSatisfy });40test('toSatisfy', () => {41  expect(2).toSatisfy(x => x > 1);42});Using AI Code Generation
1const { toSatisfy } = require('jest-extended');2expect.extend({ toSatisfy });3expect(2).toSatisfy((n) => n > 1);4expect(1).not.toSatisfy((n) => n > 1);5expect([1, 2]).toSatisfy((arr) => arr.length === 2);6expect([1, 2]).not.toSatisfy((arr) => arr.length === 3);7expect({ foo: 'bar' }).toSatisfy((obj) => obj.foo === 'bar');8expect({ foo: 'bar' }).not.toSatisfy((obj) => obj.foo === 'baz');9expect({ foo: 'bar' }).toSatisfy((obj) => obj.foo === 'bar' && obj.baz === 'qux');10expect({ foo: 'bar' }).not.toSatisfy((obj) => obj.foo === 'bar' && obj.baz === 'qux');11expect({ foo: 'bar' }).toSatisfy((obj) => obj.foo === 'bar' || obj.baz === 'qux');12expect({ foo: 'bar' }).not.toSatisfy((obj) => obj.foo === 'bar' || obj.baz === 'qux');13expect([1, 2, 3]).toSatisfy((arr) => arr.every((n) => n > 0));14expect([1, 2, 3]).not.toSatisfy((arr) => arr.every((n) => n > 1));15expect([1, 2, 3]).toSatisfy((arr) => arr.some((n) => n > 1));16expect([1, 2, 3]).not.toSatisfy((arr) => arr.some((n) => n > 3));17expect([1, 2, 3]).toSatisfy((arr) => arr.includes(2));18expect([1, 2, 3]).not.toSatisfy((arr) => arr.includes(4));19expect('hello').toSatisfy((str) => str.includes('ell'));20expect('hello').not.toSatisfy((str) => str.includes('ELL'));21expect(2).toSatisfy((n) => n > 1, 'custom message');22expect(1).not.toSUsing AI Code Generation
1const { toSatisfy } = require('jest-extended');2const { isEven } = require('lodash');3expect.extend({ toSatisfy });4const { toSatisfyAll } = require('jest-extended');5const { isEven } = require('lodash');6expect.extend({ toSatisfyAll });7const { toSatisfyAny } = require('jest-extended');8const { isEven } = require('lodash');9expect.extend({ toSatisfyAny });10const { toStartWith } = require('jest-extended');11expect.extend({ toStartWith });12const { toStartWithIgnoreCase } = require('jest-extended');13expect.extend({ toStartWithIgnoreCase });14const { toThrowAnyError } = require('jest-extended');15expect.extend({ toThrowAnyError });16expect(() => {17  throw new Error('foo');18expect(() => {19  throw new Error('foo');20expect(() => {21  throw new Error('foo');Using AI Code Generation
1const { toSatisfy } = require('jest-extended');2expect.extend({ toSatisfy });3test('toSatisfy', () => {4    const x = 2;5    const y = 3;6    expect(x + y).toSatisfy(num => num > 5);7});8  ✓ toSatisfy (2ms)Using AI Code Generation
1const { toSatisfy } = require('jest-extended');2expect.extend({ toSatisfy });3expect(data).toSatisfy((value) => {4  return true;5});6expect(data).toSatisfy((value) => {7  return true;8});9expect(data).toSatisfy((value) => {10  return true;11});12expect(data).toSatisfy((value) => {13  return true;14});15expect(data).toSatisfy((value) => {16  return true;17});18expect(data).toSatisfy((value) => {19  return true;20});21expect(data).toSatisfy((value) => {22  return true;23});24expect(data).toSatisfy((value) => {25  return true;26});27expect(data).toSatisfy((value) => {28  return true;29});30expect(data).toSatisfy((value) => {31  return true;32});33expect(data).toSatisfy((value) => {34  return true;35});36expect(data).toSatisfy((value) => {37  return true;38});39expect(data).toSatisfy((value) => {40  return true;41});42expect(data).toSatisfy((value) => {43  return true;44});45expect(data).toSatisfy((value) => {46  return true;47});48expect(data).toSatisfy((value) => {Using AI Code Generation
1const toSatisfy = require("jest-extended").toSatisfy;2const expect = require("expect");3describe("toSatisfy", () => {4  it("should pass", () => {5    const person = {6      address: {7      }8    };9    expect(person).toSatisfy(10    );11    expect(person).toSatisfy(12    );13  });14});15const toSatisfy = require("jest-extended").toSatisfy;16const expect = require("expect");17expect.extend({ toSatisfy });18describe("toSatisfy", () => {19  it("should pass", () => {20    const person = {21      address: {22      }23    };24    expect(person).toSatisfy(25    );26    expect(person).toSatisfy(27    );28  });29});30const { toSatisfy } = require("jest-extended");31const expect = require("expect");32expect.extend({ toSatisfy });33describe("toSatisfy", () => {34  it("should pass", () => {35    const person = {36      address: {37      }38    };39    expect(person).toSatisfy(40    );41    expect(person).toSatisfy(Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
