How to use toBeEmpty method in jest-extended

Best JavaScript code snippet using jest-extended

iterable.test.js

Source:iterable.test.js Github

copy

Full Screen

1'use strict';2const iterable = require('../dist/iterable');3expect.extend({4 toBeEmpty(received) {5 for (const item in received) {6 return {7 message: () => `${received} is iterable, but it is not empty. First value: ${item}`,8 pass: false9 };10 }11 return {12 pass: true13 };14 },15 toYield(received, expectedValues, elementsEqual) {16 if (elementsEqual === undefined) {17 elementsEqual = (a, b) => a === b;18 }19 const actual = Array.from(received);20 if (actual.length > expectedValues.length) {21 return {22 message: () => `${actual} has more elements (${actual.length}) than ${expectedValues} (${expectedValues.length})`,23 pass: false24 };25 } else if (actual.length < expectedValues.length) {26 return {27 message: () => `${actual} has fewer elements (${actual.length}) than ${expectedValues} (${expectedValues.length})`,28 pass: false29 };30 }31 // `actual` and `expectedValues` have the same length32 for (let i = 0; i < actual.length; i++) {33 if (!elementsEqual(actual[i], expectedValues[i])) {34 return {35 message: () => `${actual} and ${expectedValues} differ at index ${i} (${actual[i]} != ${expectedValues[i]})`,36 pass: false37 };38 }39 }40 return {41 pass: true42 };43 }44});45function pairsStrictEqual(lhs, rhs) {46 return lhs[0] === rhs[0]47 && lhs[1] === rhs[1];48}49describe('iterable.isIterable', () => {50 function* generatorFunction() {51 yield true;52 }53 const areIterable = [54 [],55 [0],56 [0, 1, 2],57 'hello',58 generatorFunction()59 ];60 test.each(areIterable)('is true for %p', (obj) => {61 expect(iterable.isIterable(obj)).toBe(true);62 });63 const notIterable = [64 1,65 { a: 1 },66 generatorFunction67 ];68 test.each(notIterable)('is false for %p', (obj) => {69 expect(iterable.isIterable(obj)).toBe(false);70 });71});72describe('iterable.concat', () => {73 test('returns an empty iterable when nothing is chained', () => {74 expect(iterable.concat()).toBeEmpty();75 });76 test('passes through a single argument', () => {77 expect(iterable.concat([1, 2])).toYield([1, 2]);78 });79 test('joins multiple arguments', () => {80 expect(iterable.concat([1, 2], (function* () { yield 3; yield 4; })(), [5])).toYield([1, 2, 3, 4, 5]);81 });82});83describe('iterable.range', () => {84 test('returns an empty iterable for an empty range', () => {85 expect(iterable.range(1, 0)).toBeEmpty();86 expect(iterable.range(0, 0)).toBeEmpty();87 expect(iterable.range(0, 0, 4)).toBeEmpty();88 });89 test('returns a range for integer bounds', () => {90 expect(iterable.range(0, 1)).toYield([0]);91 expect(iterable.range(0, 5)).toYield([0, 1, 2, 3, 4]);92 expect(iterable.range(3, 6)).toYield([3, 4, 5]);93 expect(iterable.range(-2, 0)).toYield([-2, -1]);94 });95 test('returns a range with a step size for integer bounds', () => {96 expect(iterable.range(0, 1, 3)).toYield([0]);97 expect(iterable.range(0, 5, 1)).toYield([0, 1, 2, 3, 4]);98 expect(iterable.range(3, 6, 2)).toYield([3, 5]);99 });100 test('rejects a nonpositive step size', () => {101 expect(() => [...iterable.range(0, 1, -1)]).toThrow(RangeError);102 expect(() => [...iterable.range(0, 5, 0)]).toThrow(RangeError);103 });104 test('returns a range for floating-point bounds', () => {105 // Checking equality with floats is bad, but using literals and adding integers should be predictable.106 // If this becomes flaky, pass an approximate equality function to `toYield`.107 expect(iterable.range(0.5, 3.6)).toYield([0.5, 1.5, 2.5, 3.5]);108 });109});110describe('iterable.enumerate', () => {111 test('returns an empty iterable when passed an empty iterable', () => {112 expect(iterable.enumerate([])).toBeEmpty();113 });114 test('enumerates a nonempty iterable', () => {115 expect(iterable.enumerate(['a', 'b', 'c'])).toYield([116 [0, 'a'], [1, 'b'], [2, 'c']117 ], pairsStrictEqual);118 });119});120describe('iterable.map', () => {121 test('returns an empty iterable when passed an empty iterable', () => {122 expect(iterable.map([], x => x)).toBeEmpty();123 });124 test('invokes a function on a nonempty iterable', () => {125 expect(iterable.map([1, 2, 3], x => 2 * x)).toYield([2, 4, 6]);126 });127});128describe('iterable.filter', () => {129 test('returns an empty iterable when passed an empty iterable', () => {130 expect(iterable.filter([], x => x)).toBeEmpty();131 });132 test('invokes a predicate on elements from a nonempty iterable', () => {133 const isEven = x => x % 2 === 0;134 expect(iterable.filter([0, 1, 2, 3, 4], isEven)).toYield([0, 2, 4]);135 });136});137describe('iterable.reduce', () => {138 test('throws a TypeError when reducing an empty iterable with no initial value', () => {139 expect(() => iterable.reduce([], x => x)).toThrow(TypeError);140 });141 test('returns the initial value when called on an empty iterable', () => {142 expect(iterable.reduce([], x => 2 * x, 1)).toBe(1);143 });144 test('returns the first element when called with the identity function on a nonempty iterable', () => {145 expect(iterable.reduce([1, 2, 3], x => x)).toBe(1);146 });147 // Some accumulator functions148 const sum = (a, b) => a + b;149 const and = (a, b) => a && b;150 const or = (a, b) => a || b;151 test('accumulates the elements in a nonempty iterable', () => {152 expect(iterable.reduce([0, 1, 2, 3, 4], sum)).toBe(10);153 expect(iterable.reduce(['hello', ' ', 'world'], sum)).toBe('hello world');154 expect(iterable.reduce([true, true, true], and)).toBe(true);155 expect(iterable.reduce([true, true, true], or)).toBe(true);156 expect(iterable.reduce([true, false, true], and)).toBe(false);157 expect(iterable.reduce([true, false, true], or)).toBe(true);158 });159 test('accumulates the elements in a nonempty iterable with an initial value', () => {160 expect(iterable.reduce([0, 1, 2, 3, 4], sum, 10)).toBe(20);161 });162});163describe('iterable.take', () => {164 test('returns an empty iterable when the input iterable is empty', () => {165 expect(iterable.take(5, [])).toBeEmpty();166 });167 test('returns the first elements of an iterable', () => {168 expect(iterable.take(2, [1, 2, 3, 4])).toYield([1, 2]);169 });170 test('returns an empty iterable when `n < 1`', () => {171 expect(iterable.take(-1, [1, 2, 3, 4])).toBeEmpty();172 expect(iterable.take(0, [1, 2, 3, 4])).toBeEmpty();173 expect(iterable.take(0.8, [1, 2, 3, 4])).toBeEmpty();174 });175 test('can be called multiple times', () => {176 // Use a generator since they can't be iterated multiple times.177 function* generatorFunction() {178 yield 1;179 yield 2;180 yield 3;181 yield 4;182 yield 5;183 }184 const generator = generatorFunction();185 expect(iterable.take(2, generator)).toYield([1, 2]);186 expect(iterable.take(1, generator)).toYield([3]);187 expect(iterable.take(3, generator)).toYield([4, 5]);188 });189});190describe('iterable.skip', () => {191 test('returns an empty iterable when the input iterable is empty', () => {192 expect(iterable.skip(5, [])).toBeEmpty();193 });194 test('returns the last elements of an iterable', () => {195 expect(iterable.skip(2, [1, 2, 3, 4])).toYield([3, 4]);196 });197 test('returns the whole iterable when `n <= 0`', () => {198 expect(iterable.skip(-1, [1, 2, 3, 4])).toYield([1, 2, 3, 4]);199 expect(iterable.skip(0, [1, 2, 3, 4])).toYield([1, 2, 3, 4]);200 });201 test('can be called multiple times', () => {202 // Use a generator since they can't be iterated multiple times.203 function* generatorFunction() {204 yield 1;205 yield 2;206 yield 3;207 yield 4;208 yield 5;209 }210 let generator = generatorFunction();211 const multipleSkips = iterable.skip(1, iterable.skip(2, generator));212 expect(multipleSkips).toYield([4, 5]);213 generator = generatorFunction();214 generator = iterable.skip(2, generator)215 expect(iterable.take(1, generator)).toYield([3]);216 expect(iterable.skip(1, generator)).toYield([5]);217 });218});219describe('iterable.slice', () => {220 test('returns an empty iterable when the input iterable is empty', () => {221 expect(iterable.slice([], 2, 5)).toBeEmpty();222 });223 test('returns the last elements of an iterable when only `start` is given', () => {224 expect(iterable.slice([1, 2, 3, 4], 2)).toYield([3, 4]);225 });226 test('returns the elements between `start` and `end`', () => {227 expect(iterable.slice([1, 2, 3, 4, 5, 6], 2, 3)).toYield([3]);228 expect(iterable.slice([1, 2, 3, 4, 5, 6], 2, 4)).toYield([3, 4]);229 });230 test('works when `start` or `end` are at the boundaries of the iterable', () => {231 expect(iterable.slice([1, 2, 3, 4, 5, 6], 0, 3)).toYield([1, 2, 3]);232 expect(iterable.slice([1, 2, 3, 4, 5, 6], 2, 5)).toYield([3, 4, 5]);233 expect(iterable.slice([1, 2, 3, 4, 5, 6], 0, 5)).toYield([1, 2, 3, 4, 5]);234 });235 test('works when `start` or `end` are outside the boundaries of the iterable', () => {236 expect(iterable.slice([1, 2, 3, 4, 5, 6], -1, 3)).toYield([1, 2, 3]);237 expect(iterable.slice([1, 2, 3, 4, 5, 6], 2, 6)).toYield([3, 4, 5, 6]);238 expect(iterable.slice([1, 2, 3, 4, 5, 6], 0, 6)).toYield([1, 2, 3, 4, 5, 6]);239 expect(iterable.slice([1, 2, 3, 4, 5, 6], -1, 7)).toYield([1, 2, 3, 4, 5, 6]);240 });241 test('works with floating-point bounds', () => {242 expect(iterable.slice([1, 2, 3, 4, 5, 6], 0.2, 3.8)).toYield([1, 2, 3]);243 });244 test('returns an empty iterable when `start <= end`', () => {245 expect(iterable.slice([1, 2, 3, 4], 2, 1)).toBeEmpty();246 expect(iterable.slice([1, 2, 3, 4], 2, 2)).toBeEmpty();247 });248});249describe('iterable.flat', () => {250 test('returns an empty iterable when the input is empty', () => {251 expect(iterable.flat([])).toBeEmpty();252 });253 test('flattens 1-D arrays', () => {254 expect(iterable.flat([1, 2, 3, 4])).toYield([1, 2, 3, 4]);255 });256 test('flattens 2-D arrays', () => {257 const array2d = [258 ['a', 1], ['b', 2],259 ['c', 3], ['d', 4]260 ];261 expect(iterable.flat(array2d)).toYield(['a', 1, 'b', 2, 'c', 3, 'd', 4]);262 });263 test('flattens mixed-dimension arrays', () => {264 // Need to use `Array.from` + `toEqual` here.265 // `toYield` can't handle deep equality.266 expect(Array.from(iterable.flat([1, [2, 3, 4]]))).toEqual([1, 2, 3, 4]);267 expect(Array.from(iterable.flat([1, [2, [3, 4]]]))).toEqual([1, 2, [3, 4]]);268 expect(Array.from(iterable.flat([1, [2, [3, [4]]]]))).toEqual([1, 2, [3, [4]]]);269 });270 test('flattens up to `depth`', () => {271 expect(Array.from(iterable.flat([1, [2, [3, 4]]], 2))).toEqual([1, 2, 3, 4]);272 expect(Array.from(iterable.flat([1, [2, [3, [4]]]], 2))).toEqual([1, 2, 3, [4]]);273 expect(Array.from(iterable.flat([1, [2, [3, [4]]]], 3))).toEqual([1, 2, 3, 4]);274 });275 test('handles `depth` greater than the actual depth', () => {276 expect(Array.from(iterable.flat([1, 2, 3, 4], 2))).toEqual([1, 2, 3, 4]);277 expect(Array.from(iterable.flat([1, [2, 3, 4]], 2))).toEqual([1, 2, 3, 4]);278 expect(Array.from(iterable.flat([1, [2, [3, 4]]], 3))).toEqual([1, 2, 3, 4]);279 });280 test('treats nonpositive `depth` as a no-op', () => {281 expect(Array.from(iterable.flat([1, [2, 3, 4]], 0))).toEqual([1, [2, 3, 4]]);282 expect(Array.from(iterable.flat([1, [2, 3, 4]], -1))).toEqual([1, [2, 3, 4]]);283 expect(iterable.flat([], 0)).toBeEmpty();284 });285 test('rounds floating-point `depth` down', () => {286 expect(Array.from(iterable.flat([1, [2, 3, 4]], 0.1))).toEqual([1, [2, 3, 4]]);287 expect(Array.from(iterable.flat([1, [2, 3, 4]], 1.8))).toEqual([1, 2, 3, 4]);288 });289});290describe('iterable.flatMap', () => {291 test('returns an empty iterable when passed an empty iterable', () => {292 expect(iterable.flatMap([], x => x)).toBeEmpty();293 });294 test('invokes a function on a nonempty iterable', () => {295 // Need to use `Array.from` + `toEqual` here.296 // `toYield` can't handle deep equality.297 expect(Array.from(iterable.flatMap([1, 2, 3], x => [...new Array(x).keys()])))298 .toEqual([ 0, 0, 1, 0, 1, 2 ]);299 });300 test('is equivalent to `flat` when mapping the identity function', () => {301 expect(Array.from(iterable.flatMap([1, [2, 3, 4]], x => x))).toEqual([1, 2, 3, 4]);302 expect(Array.from(iterable.flatMap([1, [2, [3, 4]]], x => x))).toEqual([1, 2, [3, 4]]);303 expect(Array.from(iterable.flatMap([1, [2, [3, [4]]]], x => x))).toEqual([1, 2, [3, [4]]]);304 });305});306describe('iterable.product', () => {307 test('returns an empty iterable when one of the iterables is empty', () => {308 expect(iterable.product([], [])).toBeEmpty();309 expect(iterable.product(['a'], [])).toBeEmpty();310 expect(iterable.product([], ['a'])).toBeEmpty();311 });312 test('returns all permutations of nonempty iterables', () => {313 expect(iterable.product(['a', 'b', 'c'], [1, 2])).toYield([314 ['a', 1], ['a', 2],315 ['b', 1], ['b', 2],316 ['c', 1], ['c', 2]317 ], pairsStrictEqual);318 expect(iterable.product([1, 2], ['a', 'b', 'c'])).toYield([319 [1, 'a'], [1, 'b'], [1, 'c'],320 [2, 'a'], [2, 'b'], [2, 'c']321 ], pairsStrictEqual);322 });323 test('works when the one of the arguments is a generator', () => {324 function* generatorFunction() {...

Full Screen

Full Screen

TestUtils.ts

Source:TestUtils.ts Github

copy

Full Screen

...33export const runSingleDocumentRoundTripForTenant = async (client: TenantSecurityClient, tenant: string) => {34 const metadata = getMetadata(tenant);35 const data = getDataToEncrypt();36 const {edek, encryptedDocument} = await client.encryptDocument(data, metadata);37 expect(edek).not.toBeEmpty();38 assertEncryptedData(client, encryptedDocument);39 const decryptResult = await client.decryptDocument({edek, encryptedDocument}, metadata);40 expect(decryptResult.edek).toEqual(edek);41 expect(decryptResult.plaintextDocument.field1).toEqual(data.field1);42};43export const runSingleExistingDocumentRoundTripForTenant = async (client: TenantSecurityClient, tenant: string) => {44 const metadata = getMetadata(tenant);45 const data = getDataToEncrypt();46 const firstEncrypt = await client.encryptDocument(data, metadata);47 const {edek, encryptedDocument} = await client.encryptDocumentWithExistingKey({edek: firstEncrypt.edek, plaintextDocument: data}, metadata);48 expect(edek).not.toBeEmpty();49 assertEncryptedData(client, encryptedDocument);50 //Should be able to decrypt using the first EDEK we got back51 const res = await client.decryptDocument({edek: firstEncrypt.edek, encryptedDocument}, metadata);52 expect(res.edek).toEqual(edek);53 expect(res.plaintextDocument.field1).toEqual(data.field1);54 expect(res.plaintextDocument.field2).toEqual(data.field2);55 expect(res.plaintextDocument.field3).toEqual(data.field3);56};57export const runBatchDocumentRoundtripForTenant = async (client: TenantSecurityClient, tenant: string) => {58 const metadata = getMetadata(tenant);59 const data = getBatchDataToEncrypt();60 const encryptResult = await client.encryptDocumentBatch(data, metadata);61 expect(encryptResult.hasFailures).toBeFalse();62 expect(encryptResult.failures).toBeEmpty();63 expect(encryptResult.hasSuccesses).toBeTrue();64 expect(encryptResult.successes.batch1.edek).not.toBeEmpty();65 assertEncryptedData(client, encryptResult.successes.batch1.encryptedDocument);66 expect(encryptResult.successes.batch2.edek).not.toBeEmpty();67 assertEncryptedData(client, encryptResult.successes.batch2.encryptedDocument);68 expect(encryptResult.successes.batch3.edek).not.toBeEmpty();69 assertEncryptedData(client, encryptResult.successes.batch3.encryptedDocument);70 expect(encryptResult.successes.batch4.edek).not.toBeEmpty();71 assertEncryptedData(client, encryptResult.successes.batch4.encryptedDocument);72 expect(encryptResult.successes.batch5.edek).not.toBeEmpty();73 assertEncryptedData(client, encryptResult.successes.batch5.encryptedDocument);74 const decryptResult = await client.decryptDocumentBatch(encryptResult.successes, metadata);75 expect(decryptResult.hasFailures).toBeFalse();76 expect(decryptResult.failures).toBeEmpty();77 expect(decryptResult.hasSuccesses).toBeTrue();78 expect(decryptResult.successes.batch1.plaintextDocument).toEqual(data.batch1);79 expect(decryptResult.successes.batch2.plaintextDocument).toEqual(data.batch2);80 expect(decryptResult.successes.batch3.plaintextDocument).toEqual(data.batch3);81 expect(decryptResult.successes.batch4.plaintextDocument).toEqual(data.batch4);82 expect(decryptResult.successes.batch5.plaintextDocument).toEqual(data.batch5);83};84export const runReusedBatchDocumentRoundtripForTenant = async (client: TenantSecurityClient, tenant: string) => {85 const metadata = getMetadata(tenant);86 const data = getBatchDataToEncrypt();87 const firstEncrypt = await client.encryptDocumentBatch(data, metadata);88 expect(firstEncrypt.hasFailures).toBeFalse();89 expect(firstEncrypt.failures).toBeEmpty();90 expect(firstEncrypt.hasSuccesses).toBeTrue();91 expect(Object.values(firstEncrypt.successes)).toHaveLength(5);92 const dataForReEncrypt = Object.entries(firstEncrypt.successes).reduce((currentMap, [docId, {edek}]) => {93 currentMap[docId] = {edek, plaintextDocument: data[docId]};94 return currentMap;95 }, {} as PlaintextDocumentWithEdekCollection);96 const reencryptResult = await client.encryptDocumentBatchWithExistingKey(dataForReEncrypt, metadata);97 expect(reencryptResult.hasFailures).toBeFalse();98 expect(reencryptResult.failures).toBeEmpty();99 expect(reencryptResult.hasSuccesses).toBeTrue();100 expect(Object.values(reencryptResult.successes)).toHaveLength(5);101 expect(reencryptResult.successes.batch1.edek).not.toBeEmpty();102 assertEncryptedData(client, reencryptResult.successes.batch1.encryptedDocument);103 expect(reencryptResult.successes.batch2.edek).not.toBeEmpty();104 assertEncryptedData(client, reencryptResult.successes.batch2.encryptedDocument);105 expect(reencryptResult.successes.batch3.edek).not.toBeEmpty();106 assertEncryptedData(client, reencryptResult.successes.batch3.encryptedDocument);107 expect(reencryptResult.successes.batch4.edek).not.toBeEmpty();108 assertEncryptedData(client, reencryptResult.successes.batch4.encryptedDocument);109 expect(reencryptResult.successes.batch5.edek).not.toBeEmpty();110 assertEncryptedData(client, reencryptResult.successes.batch5.encryptedDocument);111 const decryptResult = await client.decryptDocumentBatch(reencryptResult.successes, metadata);112 expect(decryptResult.hasFailures).toBeFalse();113 expect(decryptResult.failures).toBeEmpty();114 expect(decryptResult.hasSuccesses).toBeTrue();115 expect(decryptResult.successes.batch1.plaintextDocument).toEqual(data.batch1);116 expect(decryptResult.successes.batch2.plaintextDocument).toEqual(data.batch2);117 expect(decryptResult.successes.batch3.plaintextDocument).toEqual(data.batch3);118 expect(decryptResult.successes.batch4.plaintextDocument).toEqual(data.batch4);119 expect(decryptResult.successes.batch5.plaintextDocument).toEqual(data.batch5);120};121export const runSingleDocumentRekeyRoundTripForTenants = async (client: TenantSecurityClient, tenant1: string, tenant2: string) => {122 const metadata = getMetadata(tenant1);123 const data = getDataToEncrypt();124 const encryptResult = await client.encryptDocument(data, metadata);125 expect(encryptResult.edek).not.toBeEmpty();126 assertEncryptedData(client, encryptResult.encryptedDocument);127 const rekeyResult = await client.rekeyDocument(encryptResult, tenant2, metadata);128 expect(rekeyResult.edek).not.toBeEmpty();129 assertEncryptedData(client, rekeyResult.encryptedDocument);130 expect(rekeyResult.encryptedDocument).toEqual(encryptResult.encryptedDocument);131 const newMetadata = getMetadata(tenant2);132 const decryptResult = await client.decryptDocument(rekeyResult, newMetadata);133 expect(decryptResult.edek).toEqual(rekeyResult.edek);134 expect(decryptResult.plaintextDocument.field1).toEqual(data.field1);...

Full Screen

Full Screen

expect.spec.ts

Source:expect.spec.ts Github

copy

Full Screen

...74 // Extracted example from their typings.75 // Reference: https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts76 declare namespace jest {77 interface Matchers<R> {78 toBeEmpty(): R;79 }80 }81 `,82 'a.spec.ts': `83 const { test } = folio;84 test.expect('').toBeEmpty();85 test.expect('hello').not.toBeEmpty();86 test.expect([]).toBeEmpty();87 test.expect(['hello']).not.toBeEmpty();88 test.expect({}).toBeEmpty();89 test.expect({ hello: 'world' }).not.toBeEmpty();90 `91 });92 expect(result.exitCode).toBe(0);93});94test('should work with custom folio namespace', async ({runTSC}) => {95 const result = await runTSC({96 'global.d.ts': `97 // Extracted example from their typings.98 // Reference: https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts99 declare namespace folio {100 interface Matchers<R> {101 toBeEmpty(): R;102 }103 }104 `,105 'a.spec.ts': `106 const { test } = folio;107 test.expect.extend({108 toBeWithinRange() { },109 });110 test.expect('').toBeEmpty();111 test.expect('hello').not.toBeEmpty();112 test.expect([]).toBeEmpty();113 test.expect(['hello']).not.toBeEmpty();114 test.expect({}).toBeEmpty();115 test.expect({ hello: 'world' }).not.toBeEmpty();116 `117 });118 expect(result.exitCode).toBe(0);...

Full Screen

Full Screen

log.test.js

Source:log.test.js Github

copy

Full Screen

...32 expect(transport.filename).toMatch(fileRegex);33 });34 });35 test('Log Errors', async () => {36 expect(logFrom('error')).toBeEmpty();37 logger.info('This is not written as an error');38 await sleep(500);39 expect(logFrom('error')).toBeEmpty();40 logger.error('This is an error log');41 await sleep(500);42 const errorLog = logFrom('error');43 expect(errorLog.length).toBe(1);44 const { timestamp, ...item } = errorLog[0];45 expect(item).toEqual({46 message: 'This is an error log',47 service: 'testing',48 level: 'error',49 });50 });51 test('Log Level', async () => {52 expect(logFrom('error')).toBeEmpty();53 expect(logFrom(logLevel)).toBeEmpty();54 expect(logFrom(today())).toBeEmpty();55 logger.log(logLevel, 'This is a level log');56 await sleep(500);57 expect(logFrom('error')).toBeEmpty();58 expect(logFrom(logLevel)).not.toBeEmpty();59 expect(logFrom(today())).not.toBeEmpty();60 expect(logFrom(logLevel)).toEqual(logFrom(today()));61 const currentLog = logFrom(logLevel);62 expect(currentLog.length).toBe(1);63 const { timestamp, ...item } = currentLog[0];64 expect(item).toEqual({65 level: logLevel,66 message: 'This is a level log',67 });68 });69 test('Log Daily', async () => {70 expect(logFrom(logLevel)).toBeEmpty();71 expect(logFrom('error')).toBeEmpty();72 expect(logFrom(today())).toBeEmpty();73 logger.error('This is a daily log');74 await sleep(500);75 expect(logFrom(logLevel)).not.toBeEmpty();76 expect(logFrom('error')).not.toBeEmpty();77 expect(logFrom(today())).not.toBeEmpty();78 expect(logFrom(today())).toEqual(logFrom(logLevel));79 expect(logFrom(today())).toEqual(logFrom('error'));80 const currentLog = logFrom(today());81 expect(currentLog.length).toBe(1);82 const { timestamp, ...item } = currentLog[0];83 expect(item).toEqual({84 level: 'error',85 service: 'testing',86 message: 'This is a daily log',87 });88 });...

Full Screen

Full Screen

database.test.js

Source:database.test.js Github

copy

Full Screen

...18 ['translationText', 'this is a teste'], ['user', 'user1']])19 .toContainKey('dateTranslated');20 expect(data.ops[0].dateTranslated)21 .toBeString()22 .not.toBeEmpty();23 insertedDBId = data.insertedId;24});25test('Happy path Search in DB', async () => {26 const data = await db.findindb('user1', insertedDBId);27 expect(data)28 .toBeObject()29 .toContainAllKeys(['_id', 'user', 'originalLanguage', 'originalText', 'translationLanguage',30 'translationText', 'dateTranslated', 'channel', 'receiver']);31 expect(data.user)32 .toBeString()33 .not.toBeEmpty()34 .toEqualCaseInsensitive('user1');35 expect(data.originalLanguage)36 .toBeString()37 .not.toBeEmpty()38 .toEqualCaseInsensitive('en');39 expect(data.originalText)40 .toBeString()41 .not.toBeEmpty()42 .toEqualCaseInsensitive('this is a test');43 expect(data.translationLanguage)44 .toBeString()45 .not.toBeEmpty()46 .toEqualCaseInsensitive('fr');47 expect(data.translationText)48 .toBeString()49 .not.toBeEmpty()50 .toEqualCaseInsensitive('this is a teste');51 expect(data.channel)52 .toBeString()53 .not.toBeEmpty()54 .toEqualCaseInsensitive('channel');55 expect(data.receiver)56 .toBeString()57 .not.toBeEmpty()58 .toEqualCaseInsensitive('receiver');59 expect(data.dateTranslated)60 .toBeString()61 .not.toBeEmpty();62});63test('Search in DB, id not found', async () => {64 // Sending bad id65 const data = await db.findindb('user1', '123456789012345678abcdef');66 expect(data)67 .toBeObject()68 .toBeEmpty();69});70test('Search in DB, invalid id', async () => {71 // Sending invalid id72 const data = await db.findindb('user1', 'badId');73 expect(data)74 .toBeString()75 .not.toBeEmpty()76 .toEqualCaseInsensitive('Invalid ID, must be a single String of 12 bytes or a string of 24 hex characters');...

Full Screen

Full Screen

to-be-empty.js

Source:to-be-empty.js Github

copy

Full Screen

...3 value: true4});5exports.toBeEmpty = toBeEmpty;6var _utils = require("./utils");7function toBeEmpty(element) {8 (0, _utils.deprecate)('toBeEmpty', 'Please use instead toBeEmptyDOMElement for finding empty nodes in the DOM.');9 (0, _utils.checkHtmlElement)(element, toBeEmpty, this);10 return {11 pass: element.innerHTML === '',12 message: () => {13 return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toBeEmpty`, 'element', ''), '', 'Received:', ` ${this.utils.printReceived(element.innerHTML)}`].join('\n');14 }15 };...

Full Screen

Full Screen

to-be-empty 2.js

Source:to-be-empty 2.js Github

copy

Full Screen

...3 value: true4});5exports.toBeEmpty = toBeEmpty;6var _utils = require("./utils");7function toBeEmpty(element) {8 (0, _utils.deprecate)('toBeEmpty', 'Please use instead toBeEmptyDOMElement for finding empty nodes in the DOM.');9 (0, _utils.checkHtmlElement)(element, toBeEmpty, this);10 return {11 pass: element.innerHTML === '',12 message: () => {13 return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toBeEmpty`, 'element', ''), '', 'Received:', ` ${this.utils.printReceived(element.innerHTML)}`].join('\n');14 }15 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toBeEmpty } = require('jest-extended');2expect.extend({ toBeEmpty });3test('empty string', () => {4 expect('').toBeEmpty();5});6test('empty array', () => {7 expect([]).toBeEmpty();8});9test('not empty object', () => {10 expect({ foo: 'bar' }).not.toBeEmpty();11});12test('not empty string', () => {13 expect('foo').not.toBeEmpty();14});15test('not empty array', () => {16 expect(['foo']).not.toBeEmpty();17});18const { toBeEmptyArray } = require('jest-extended');19expect.extend({ toBeEmptyArray });20test('empty array', () => {21 expect([]).toBeEmptyArray();22});23test('not empty array', () => {24 expect(['foo']).not.toBeEmptyArray();25});26const { toBeEmptyObject } = require('jest-extended');27expect.extend({ toBeEmptyObject });28test('empty object', () => {29 expect({}).toBeEmptyObject();30});31test('not empty object', () => {32 expect({ foo: 'bar' }).not.toBeEmptyObject();33});34const { toBeEmptyString } = require('jest-extended');35expect.extend({ toBeEmptyString });36test('empty string', () => {37 expect('').toBeEmptyString();38});39test('not empty string', () => {40 expect('foo').not.toBeEmptyString();41});42const { toBeFalse } = require('jest-extended');43expect.extend({ toBeFalse });44test('false', () => {45 expect(false).toBeFalse();46});47test('not false', () => {48 expect(true).not.toBeFalse();49});50const { toBeFunction } = require('jest-extended');51expect.extend({ toBeFunction });52test('function', () => {53 expect(() => {}).toBeFunction();54});55test('not function', () => {56 expect('foo').not.toBeFunction();57});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toBeEmpty } = require('jest-extended');2expect.extend({ toBeEmpty });3test('passes when given an empty string', () => {4 expect('').toBeEmpty();5});6test('fails when given a non-empty string', () => {7 expect('foo').toBeEmpty();8});9const { toBeEmpty } = require('jest-extended');10expect.extend({ toBeEmpty });11test('passes when given an empty string', () => {12 expect('').toBeEmpty();13});14test('fails when given a non-empty string', () => {15 expect('foo').toBeEmpty();16});17const { toBeEmpty } = require('jest-extended');18expect.extend({ toBeEmpty });19test('passes when given an empty string', () => {20 expect('').toBeEmpty();21});22test('fails when given a non-empty string', () => {23 expect('foo').toBeEmpty();24});25import { toBeEmpty } from 'jest-extended';26expect.extend({ toBeEmpty });27test('passes when given an empty string', () => {28 expect('').toBeEmpty();29});30test('fails when given a non-empty string', () => {31 expect('foo').toBeEmpty();32});33import { toBeEmpty } from 'jest-extended';34expect.extend({ toBeEmpty });35test('passes when given an empty string', () => {36 expect('').toBeEmpty();37});38test('fails when given a non-empty string', () => {39 expect('foo').toBeEmpty();40});41import { toBeEmpty } from 'jest-extended';42expect.extend({ toBeEmpty });43test('passes when given an empty string', () => {44 expect('').toBeEmpty();45});46test('fails when given a non-empty string', () => {47 expect('foo').toBeEmpty();48});49import { toBeEmpty } from 'jest-extended';50expect.extend({ toBe

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toBeEmpty } = require('jest-extended');2expect.extend({ toBeEmpty });3const { toBeEmpty } = require('jest-extended');4expect.extend({ toBeEmpty });5const { toBeEmpty } = require('jest-extended');6expect.extend({ toBeEmpty });7const { toBeEmpty } = require('jest-extended');8expect.extend({ toBeEmpty });9const { toBeEmpty } = require('jest-extended');10expect.extend({ toBeEmpty });11const { toBeEmpty } = require('jest-extended');12expect.extend({ toBeEmpty });13const { toBeEmpty } = require('jest-extended');14expect.extend({ toBeEmpty });15const { toBeEmpty } = require('jest-extended');16expect.extend({ toBeEmpty });17const { toBeEmpty } = require('jest-extended');18expect.extend({ toBeEmpty });19const { toBeEmpty } = require('jest-extended');20expect.extend({ toBeEmpty });21const { toBeEmpty } = require('jest-extended');22expect.extend({ toBeEmpty });23const { toBeEmpty } = require('jest-extended');24expect.extend({ toBeEmpty });25const { toBeEmpty } = require('jest-extended');26expect.extend({ toBeEmpty });27const { toBeEmpty } = require('jest-extended');28expect.extend({ toBeEmpty });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toBeEmpty } = require('jest-extended');2expect.extend({ toBeEmpty });3test('passes when value is empty', () => {4 expect([]).toBeEmpty();5 expect('').toBeEmpty();6 expect({}).toBeEmpty();7});8test('fails when value is not empty', () => {9 expect([1, 2, 3]).not.toBeEmpty();10 expect('abc').not.toBeEmpty();11 expect({ a: 1, b: 2 }).not.toBeEmpty();12});13const { toBeEmptyObject } = require('jest-extended');14expect.extend({ toBeEmptyObject });15test('passes when value is empty object', () => {16 expect({}).toBeEmptyObject();17});18test('fails when value is not empty object', () => {19 expect({ a: 1, b: 2 }).not.toBeEmptyObject();20});21const { toBeEmptyString } = require('jest-extended');22expect.extend({ toBeEmptyString });23test('passes when value is empty string', () => {24 expect('').toBeEmptyString();25});26test('fails when value is not empty string', () => {27 expect('abc').not.toBeEmptyString();28});29const { toBeEmptyArray } = require('jest-extended');30expect.extend({ toBeEmptyArray });31test('passes when value is empty array', () => {32 expect([]).toBeEmptyArray();33});34test('fails when value is not empty array', () => {35 expect([1, 2, 3]).not.toBeEmptyArray();36});37const { toBeEmptyString } = require('jest-extended');38expect.extend({ toBeEmptyString });39test('passes when value is empty string', () => {40 expect('').toBeEmptyString();41});42test('fails when value is not empty string', () => {43 expect('abc').not.toBeEmpty

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toBeEmpty } = require('jest-extended');2expect.extend({toBeEmpty});3describe('toBeEmpty', () => {4 test('passes when given an empty string', () => {5 expect('').toBeEmpty();6 });7 test('fails when given a string', () => {8 expect(() => expect('abc').toBeEmpty()).toThrow();9 });10});11const { toBeEmpty } = require('jest-extended');12expect.extend({toBeEmpty});13describe('toBeEmpty', () => {14 test('passes when given an empty string', () => {15 expect('').toBeEmpty();16 });17 test('fails when given a string', () => {18 expect(() => expect('abc').toBeEmpty()).toThrow();19 });20});21const { toBeEmpty } = require('jest-extended');22expect.extend({toBeEmpty});23describe('toBeEmpty', () => {24 test('passes when given an empty string', () => {25 expect('').toBeEmpty();26 });27});28const { toBeEmpty } = require('jest-extended');29expect.extend({toBeEmpty});30describe('toBeEmpty', () => {31 test('fails when given a string', () => {32 expect(() => expect('abc').toBeEmpty()).toThrow();33 });34});35const { toBeEmpty } = require('jest-extended');36expect.extend({toBeEmpty});37describe('toBeEmpty', () => {38 test('passes when given an empty string', () => {39 expect('').toBeEmpty();40 });41});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toBeEmpty } = require('jest-extended');2expect.extend({ toBeEmpty });3test('passes when given an empty array', () => {4 expect([]).toBeEmpty();5});6test('fails when given a non-empty array', () => {7 expect([1, 2, 3]).not.toBeEmpty();8});9test('fails when given an empty string', () => {10 expect('').not.toBeEmpty();11});12test('fails when given a non-empty string', () => {13 expect('hello').not.toBeEmpty();14});15test('fails when given an empty object', () => {16 expect({}).not.toBeEmpty();17});18test('fails when given a non-empty object', () => {19 expect({ a: 1 }).not.toBeEmpty();20});21test('fails when given an empty map', () => {22 expect(new Map()).not.toBeEmpty();23});24test('fails when given a non-empty map', () => {25 expect(new Map([['a', 1]])).not.toBeEmpty();26});27test('fails when given an empty set', () => {28 expect(new Set()).not.toBeEmpty();29});30test('fails when given a non-empty set', () => {31 expect(new Set([1, 2, 3])).not.toBeEmpty();32});33test('fails when given an empty weakmap', () => {34 expect(new WeakMap()).not.toBeEmpty();35});36test('fails when given a non-empty weakmap', () => {37 expect(new WeakMap([[{}, 1]])).not.toBeEmpty();38});39test('fails when given an empty weakset', () => {40 expect(new WeakSet()).not.toBeEmpty();41});42test('fails when given a non-empty weakset', () => {43 expect(new WeakSet([{}])).not.toBeEmpty();44});45test('fails when given a number', () => {46 expect(1).not.toBeEmpty();47});48test('fails when given a boolean', () => {49 expect(false).not.toBeEmpty();50});51test('fails when given null', () => {52 expect(null).not.toBeEmpty();53});54test('fails when given undefined', () => {55 expect(undefined).not.toBeEmpty();56});57test('fails when given NaN', () => {58 expect(NaN).not.toBeEmpty();59});60test('fails when given a Date', () => {61 expect(new Date()).not.toBeEmpty();62});63test('fails when given a function', () =>

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toBeEmpty } = require('jest-extended');2expect.extend({ toBeEmpty });3expect([]).toBeEmpty();4expect('').toBeEmpty();5expect({}).toBeEmpty();6expect(new Set()).toBeEmpty();7expect(new Map()).toBeEmpty();8expect([1]).not.toBeEmpty();9expect('foo').not.toBeEmpty();10expect({ foo: 'bar' }).not.toBeEmpty();11expect(new Set([1])).not.toBeEmpty();12expect(new Map([['foo', 'bar']])).not.toBeEmpty();13expect('').toBeEmptyString();14expect('foo').not.toBeEmptyString();15expect({}).toBeEmptyObject();16expect({ foo: 'bar' }).not.toBeEmptyObject();17expect([]).toBeEmptyArray();18expect([1]).not.toBeEmptyArray();19expect(new Set()).toBeEmptySet();20expect(new Set([1])).not.toBeEmptySet();21expect(new Map()).toBeEmptyMap();22expect(new Map([['foo', 'bar']])).not.toBeEmptyMap();23expect(() => {}).toBeEmptyFunction();24expect(() => 1).not.toBeEmptyFunction();25expect('').toBeEmptyString();26expect('foo').not.toBeEmptyString();27expect({}).toBeEmptyObject();28expect({ foo: 'bar' }).not.toBe

Full Screen

Using AI Code Generation

copy

Full Screen

1const jestExtended = require('jest-extended');2const jest = require('jest');3const expect = require('expect');4const puppeteer = require('puppeteer');5let browser;6let page;7beforeAll(async () => {8 browser = await puppeteer.launch({9 });10 page = await browser.newPage();11});12afterAll(() => {13 browser.close();14});15test('Test to check the url', async () => {16 await page.waitForSelector('input[name="q"]');17 await page.type('input[name="q"]', 'puppeteer');18 await page.waitForSelector('input[name="btnK"]');19 await page.click('input[name="btnK"]');20 await page.waitForSelector('div.g');21 const results = await page.$$('div.g');22 expect(results).toBeEmpty();23}, 16000);24test('Test to check the url', async () => {25 await page.waitForSelector('input[name="q"]');26 await page.type('input[name="q"]', 'puppeteer');27 await page.waitForSelector('input[name="btnK"]');28 await page.click('input[name="btnK"]');29 await page.waitForSelector('div.g');30 const results = await page.$$('div.g');31 expect(results).toBeEmpty();32}, 16000);33test('Test to check the url', async () => {34 await page.waitForSelector('input[name="q"]');35 await page.type('input[name="q"]', 'puppeteer');36 await page.waitForSelector('input[name="btnK"]');37 await page.click('input[name="btnK"]');38 await page.waitForSelector('div.g');39 const results = await page.$$('div.g');40 expect(results).toBeEmpty();41}, 16000);

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run jest-extended 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