Best JavaScript code snippet using ava
assert.js
Source:assert.js
...346test('.deepEqual()', t => {347 // Tests starting here are to detect regressions in the underlying libraries348 // used to test deep object equality349 fails(t, () => {350 assertions.deepEqual({a: false}, {a: 0});351 });352 passes(t, () => {353 assertions.deepEqual({354 a: 'a',355 b: 'b'356 }, {357 b: 'b',358 a: 'a'359 });360 });361 passes(t, () => {362 assertions.deepEqual({363 a: 'a',364 b: 'b',365 c: {366 d: 'd'367 }368 }, {369 c: {370 d: 'd'371 },372 b: 'b',373 a: 'a'374 });375 });376 fails(t, () => {377 assertions.deepEqual([1, 2, 3], [1, 2, 3, 4]);378 });379 passes(t, () => {380 assertions.deepEqual([1, 2, 3], [1, 2, 3]);381 });382 fails(t, () => {383 const fnA = a => a;384 const fnB = a => a;385 assertions.deepEqual(fnA, fnB);386 });387 passes(t, () => {388 const x1 = {z: 4};389 const y1 = {x: x1};390 x1.y = y1;391 const x2 = {z: 4};392 const y2 = {x: x2};393 x2.y = y2;394 assertions.deepEqual(x1, x2);395 });396 passes(t, () => {397 function Foo(a) {398 this.a = a;399 }400 const x = new Foo(1);401 const y = new Foo(1);402 assertions.deepEqual(x, y);403 });404 fails(t, () => {405 function Foo(a) {406 this.a = a;407 }408 function Bar(a) {409 this.a = a;410 }411 const x = new Foo(1);412 const y = new Bar(1);413 assertions.deepEqual(x, y);414 });415 fails(t, () => {416 assertions.deepEqual({417 a: 'a',418 b: 'b',419 c: {420 d: false421 }422 }, {423 c: {424 d: 0425 },426 b: 'b',427 a: 'a'428 });429 });430 fails(t, () => {431 assertions.deepEqual({}, []);432 });433 fails(t, () => {434 assertions.deepEqual({0: 'a', 1: 'b'}, ['a', 'b']);435 });436 fails(t, () => {437 assertions.deepEqual({a: 1}, {a: 1, b: undefined});438 });439 fails(t, () => {440 assertions.deepEqual(new Date('1972-08-01'), null);441 });442 fails(t, () => {443 assertions.deepEqual(new Date('1972-08-01'), undefined);444 });445 passes(t, () => {446 assertions.deepEqual(new Date('1972-08-01'), new Date('1972-08-01'));447 });448 passes(t, () => {449 assertions.deepEqual({x: new Date('1972-08-01')}, {x: new Date('1972-08-01')});450 });451 fails(t, () => {452 assertions.deepEqual(() => {}, () => {});453 });454 passes(t, () => {455 assertions.deepEqual(undefined, undefined);456 assertions.deepEqual({x: undefined}, {x: undefined});457 assertions.deepEqual({x: [undefined]}, {x: [undefined]});458 });459 passes(t, () => {460 assertions.deepEqual(null, null);461 assertions.deepEqual({x: null}, {x: null});462 assertions.deepEqual({x: [null]}, {x: [null]});463 });464 passes(t, () => {465 assertions.deepEqual(0, 0);466 assertions.deepEqual(1, 1);467 assertions.deepEqual(3.14, 3.14);468 });469 fails(t, () => {470 assertions.deepEqual(0, 1);471 });472 fails(t, () => {473 assertions.deepEqual(1, -1);474 });475 fails(t, () => {476 assertions.deepEqual(3.14, 2.72);477 });478 fails(t, () => {479 assertions.deepEqual({0: 'a', 1: 'b'}, ['a', 'b']);480 });481 passes(t, () => {482 assertions.deepEqual(483 [484 {foo: {z: 100, y: 200, x: 300}},485 'bar',486 11,487 {baz: {d: 4, a: 1, b: 2, c: 3}}488 ],489 [490 {foo: {x: 300, y: 200, z: 100}},491 'bar',492 11,493 {baz: {c: 3, b: 2, a: 1, d: 4}}494 ]495 );496 });497 passes(t, () => {498 assertions.deepEqual(499 {x: {a: 1, b: 2}, y: {c: 3, d: 4}},500 {y: {d: 4, c: 3}, x: {b: 2, a: 1}}501 );502 });503 passes(t, () => {504 assertions.deepEqual(505 renderer.create(React.createElement(HelloMessage, {name: 'Sindre'})).toJSON(),506 React.createElement('div', null, 'Hello ', React.createElement('mark', null, 'Sindre'))507 );508 });509 // Regression test end here510 passes(t, () => {511 assertions.deepEqual({a: 'a'}, {a: 'a'});512 });513 passes(t, () => {514 assertions.deepEqual(['a', 'b'], ['a', 'b']);515 });516 fails(t, () => {517 assertions.deepEqual({a: 'a'}, {a: 'b'});518 });519 fails(t, () => {520 assertions.deepEqual(['a', 'b'], ['a', 'a']);521 });522 fails(t, () => {523 assertions.deepEqual([['a', 'b'], 'c'], [['a', 'b'], 'd']);524 });525 fails(t, () => {526 const circular = ['a', 'b'];527 circular.push(circular);528 assertions.deepEqual([circular, 'c'], [circular, 'd']);529 });530 failsWith(t, () => {531 assertions.deepEqual('foo', 'bar');532 }, {533 assertion: 'deepEqual',534 message: '',535 raw: {actual: 'foo', expected: 'bar'},536 values: [{label: 'Difference:', formatted: /- 'foo'\n\+ 'bar'/}]537 });538 failsWith(t, () => {539 assertions.deepEqual('foo', 42);540 }, {541 assertion: 'deepEqual',542 message: '',543 raw: {actual: 'foo', expected: 42},544 values: [{label: 'Difference:', formatted: /- 'foo'\n\+ 42/}]545 });546 failsWith(t, () => {547 assertions.deepEqual('foo', 42, 'my message');548 }, {549 assertion: 'deepEqual',550 message: 'my message',551 values: [{label: 'Difference:', formatted: /- 'foo'\n\+ 42/}]552 });553 t.end();554});555test('.notDeepEqual()', t => {556 passes(t, () => {557 assertions.notDeepEqual({a: 'a'}, {a: 'b'});558 });559 passes(t, () => {560 assertions.notDeepEqual(['a', 'b'], ['c', 'd']);561 });...
update-show-sections-in-readmes-test.js
Source:update-show-sections-in-readmes-test.js
1import { readFile } from "fs/promises";2import { dirname, join } from "path";3import { fileURLToPath } from "url";4import { equal, deepEqual, ok } from "assert/strict";5import { test } from "uvu";6import { run } from "../update-show-sections-in-readmes.js";7const __dirname = dirname(fileURLToPath(import.meta.url));8test("update-show-sections-in-readmes.js without any issues", async () => {9 // mock environment variables10 const mockEnv = {11 GITHUB_TOKEN: "secret",12 };13 // mock octokit14 const mockOctokit = {15 paginate: async (route, parameters) => {16 if (route === "GET /repos/{owner}/{repo}/issues") {17 deepEqual(parameters, {18 owner: "gr2m",19 repo: "helpdesk",20 labels: "show",21 state: "all",22 per_page: 100,23 });24 return [];25 }26 throw new Error("Unexpected route: " + route);27 },28 request: async (route, parameters) => {29 throw new Error("Unexpected route: " + route);30 },31 };32 // mock twitterRequest33 const mockReadmeBox = {34 async updateSection(newContent, parameters) {35 equal(36 newContent,37 `38## Upcoming shows39## Past shows40`41 );42 const { repo, ...rest } = parameters;43 ok(["helpdesk", "gr2m"].includes(repo), `${repo} could not be matched`);44 deepEqual(rest, {45 token: "secret",46 owner: "gr2m",47 section: "helpdesk-shows",48 branch: "main",49 message: "docs(README): update helpdesk shows",50 });51 return;52 },53 };54 // mock core55 const outputLogs = [];56 const outputs = {};57 const mockCore = {58 info(message) {59 outputLogs.push(message);60 },61 setOutput(name, value) {62 outputs[name] = value;63 },64 setFailed(message) {65 throw new Error(message);66 },67 };68 // run action69 await run(mockEnv, mockCore, mockOctokit, mockReadmeBox);70 // assertions71 deepEqual(outputLogs, [72 "README updated in gr2m/helpdesk",73 "README updated in gr2m/gr2m",74 ]);75});76test("update-show-sections-in-readmes.js with two issues", async () => {77 const issues = JSON.parse(78 await readFile(79 join(__dirname, "fixtures/list-issues-for-update-show-sections.json")80 )81 );82 // mock environment variables83 const mockEnv = {84 GITHUB_TOKEN: "secret",85 };86 // mock octokit87 const mockOctokit = {88 paginate: async (route, parameters) => {89 if (route === "GET /repos/{owner}/{repo}/issues") {90 deepEqual(parameters, {91 owner: "gr2m",92 repo: "helpdesk",93 labels: "show",94 state: "all",95 per_page: 100,96 });97 return issues;98 }99 throw new Error("Unexpected route: " + route);100 },101 request: async (route, parameters) => {102 throw new Error("Unexpected route: " + route);103 },104 };105 // mock twitterRequest106 const mockReadmeBox = {107 async updateSection(newContent, parameters) {108 equal(109 newContent,110 `111## Upcoming shows112- ð
9/2 @ 10:00am PT â [Creating tests for actions for faster iteration Part III](https://github.com/gr2m/helpdesk/issues/49)113## Past shows114- [Creating tests for actions for faster iteration Part II](https://github.com/gr2m/helpdesk/issues/47)115`116 );117 const { repo, ...rest } = parameters;118 ok(["helpdesk", "gr2m"].includes(repo), `${repo} could not be matched`);119 deepEqual(rest, {120 token: "secret",121 owner: "gr2m",122 section: "helpdesk-shows",123 branch: "main",124 message: "docs(README): update helpdesk shows",125 });126 return;127 },128 };129 // mock core130 const outputLogs = [];131 const outputs = {};132 const mockCore = {133 info(message) {134 outputLogs.push(message);135 },136 setOutput(name, value) {137 outputs[name] = value;138 },139 setFailed(message) {140 throw new Error(message);141 },142 };143 // run action144 await run(mockEnv, mockCore, mockOctokit, mockReadmeBox);145 // assertions146 deepEqual(outputLogs, [147 "README updated in gr2m/helpdesk",148 "README updated in gr2m/gr2m",149 ]);150});...
Using AI Code Generation
1const test = require('ava');2test('deepEqual', t => {3 const object1 = {a: {b: 1}};4 const object2 = {a: {b: 1}};5 const object3 = {a: {b: 2}};6 t.deepEqual(object1, object2);7 t.deepEqual(object1, object3);8});9const test = require('ava');10test('notDeepEqual', t => {11 const object1 = {a: {b: 1}};12 const object2 = {a: {b: 1}};13 const object3 = {a: {b: 2}};14 t.notDeepEqual(object1, object3);15 t.notDeepEqual(object1, object2);16});17const test = require('ava');18test('true', t => {19 t.true(true);20 t.true(1);21 t.true({});22 t.true('foo');23 t.true([]);24 t.true(function () {});25});26const test = require('ava');27test('false', t => {28 t.false(false);29 t.false(0);30 t.false('');31 t.false(null);32 t.false(undefined);33 t.false(NaN);34});35const test = require('ava');36test('truthy', t => {37 t.truthy('foo');38 t.truthy(1);39 t.truthy({});40 t.truthy([]);41 t.truthy(function () {});42});
Using AI Code Generation
1const test = require('ava');2const assert = require('assert');3test('deepEqual', t => {4 t.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);5});6test('nodejs deepEqual', t => {7 assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);8});
Using AI Code Generation
1const test = require('ava');2const assert = require('assert');3test('deepEqual', t => {4 const obj1 = {5 };6 const obj2 = {7 };8 const obj3 = {9 };10 const obj4 = Object.create(obj1);11 t.deepEqual(obj1, obj2);12 assert.deepEqual(obj1, obj2);13 assert.deepEqual(obj1, obj3);14 assert.deepEqual(obj1, obj4);15});16const test = require('ava');17const assert = require('assert');18test('deepEqual', t => {19 const obj1 = {20 };21 const obj2 = {22 };23 const obj3 = {24 };25 const obj4 = Object.create(obj1);26 t.deepEqual(obj1, obj2);27 t.deepEqual(obj1, obj3);28 t.deepEqual(obj1, obj4);29});30const test = require('ava');31const assert = require('assert');32test('deepEqual', t => {33 const obj1 = {34 };35 const obj2 = {36 };37 const obj3 = {38 };39 const obj4 = Object.create(obj1);40 t.deepEqual(obj1, obj2);41 t.deepEqual(obj1, obj3);42 t.deepEqual(obj1, obj4);43});
Using AI Code Generation
1const test = require('ava');2const { deepEqual } = require('assert');3test('deepEqual', t => {4 const obj1 = { a: 1, b: 2 };5 const obj2 = { a: 1, b: 2 };6 const obj3 = { a: 1, b: 2 };7 const obj4 = Object.create(obj1);8 deepEqual(obj1, obj1);9 deepEqual(obj1, obj2);10 deepEqual(obj1, obj3);11 deepEqual(obj1, obj4);12});13const test = require('ava');14const { notDeepEqual } = require('assert');15test('notDeepEqual', t => {16 const obj1 = { a: 1, b: 2 };17 const obj2 = { a: 1, b: 2 };18 const obj3 = { a: 1, b: 2 };19 const obj4 = Object.create(obj1);20 notDeepEqual(obj1, obj1);21 notDeepEqual(obj1, obj2);22 notDeepEqual(obj1, obj3);23 notDeepEqual(obj1, obj4);24});25const test = require('ava');26const { deepStrictEqual } = require('assert');27test('deepStrictEqual', t => {28 const obj1 = { a: 1, b: 2 };
Using AI Code Generation
1const test = require('ava');2const assert = require('assert');3const add = require('./add.js');4test('add()', t => {5 const result = add(1, 2);6 t.deepEqual(result, 3);7});8function add(a, b) {9 return a + b;10}11module.exports = add;
Using AI Code Generation
1import test from 'ava'2import {assertions} from 'ava'3assertions.deepEqual({foo: 'bar'}, {foo: 'bar'})4### `assertions.notDeepEqual(actual, expected, [message])`5import test from 'ava'6import {assertions} from 'ava'7assertions.notDeepEqual({foo: 'bar'}, {foo: 'bar'})8### `assertions.deepStrictEqual(actual, expected, [message])`9import test from 'ava'10import {assertions} from 'ava'11assertions.deepStrictEqual({foo: 'bar'}, {foo: 'bar'})12### `assertions.notDeepStrictEqual(actual, expected, [message])`13import test from 'ava'14import {assertions} from 'ava'15assertions.notDeepStrictEqual({foo: 'bar'}, {foo: 'bar'})16### `assertions.throws(function|promise, [error, [message]])`17import test from 'ava'18import {assertions} from 'ava'19assertions.throws(() => {20 throw new TypeError('foo')21})22### `assertions.notThrows(function|promise, [message])`
Using AI Code Generation
1import test from 'ava';2import * as myModule from '../src/index.js';3test('test 1', t => {4 t.deepEqual(myModule.test1(), {5 });6});7test('test 2', t => {8 t.deepEqual(myModule.test2(), {9 });10});11test('test 3', t => {12 t.deepEqual(myModule.test3(), {13 });14});15test('test 4', t => {16 t.deepEqual(myModule.test4(), {17 });18});19test('test 5', t => {20 t.deepEqual(myModule.test5(), {21 });22});23test('test 6', t => {24 t.deepEqual(myModule.test6(), {25 });26});27test('test 7', t => {28 t.deepEqual(myModule.test7(), {29 });30});31test('test 8', t => {32 t.deepEqual(myModule.test8(), {33 });34});35test('test 9', t => {36 t.deepEqual(myModule.test9(), {37 });38});39test('test 10', t => {40 t.deepEqual(myModule.test10(), {41 });42});43test('test 11', t => {44 t.deepEqual(myModule.test11(), {45 });46});47test('test 12', t => {48 t.deepEqual(myModule.test12(), {49 });50});51test('test 13', t => {52 t.deepEqual(my
Using AI Code Generation
1const test = require('ava');2const assert = require('assert');3const { getOptions } = require('./index');4test('should return an object with the correct properties', t => {5 const options = getOptions();6 assert.deepEqual(options, {7 });8});9module.exports = {10};11function getOptions() {12 return {13 };14}15const test = require('ava');16const assert = require('assert');17const { getOptions } = require('./index');18test('should return an object with the correct properties', t => {19 const options = getOptions();20 assert.is(options.host, 'localhost');21 assert.is(options.port, 8080);22 assert.is(options.path, '/test');23 assert.is(options.method, 'GET');24});25module.exports = {26};27function getOptions() {28 return {29 };30}31const test = require('ava');32const assert = require('assert');33const { getOptions } = require('./index');34test('should return an object with the correct properties', t => {35 const options = getOptions();36 assert.is(options.host, 'localhost');37 assert.is(options.port, 8080);38 assert.is(options.path, '/test');39 assert.is(options.method, 'GET');40});41module.exports = {42};43function getOptions() {44 return {
Using AI Code Generation
1const test = require('ava');2const assert = require('assert');3test('test', t => {4 t.deepEqual(1, 1);5});6const test = require('ava');7const assert = require('assert');8test('test', t => {9 assert.deepEqual(1, 1);10});11const test = require('ava');12const assert = require('assert');13test('test', t => {14 assert.equal(1, 1);15});16const test = require('ava');17const assert = require('assert');18test('test', t => {19 assert.strictEqual(1, 1);20});21const test = require('ava');22const assert = require('assert');23test('test', t => {24 assert.equal(1, 1);25});26const test = require('ava');27const assert = require('assert');28test('test', t => {29 assert.notEqual(1, 2);30});31const test = require('ava');32const assert = require('assert');33test('test', t => {34 assert.notStrictEqual(1, 2);35});36const test = require('ava');37const assert = require('assert');38test('
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!!