How to use the deepStrictEqual function from assert
Find comprehensive JavaScript assert.deepStrictEqual code examples handpicked from public code repositorys.
assert.deepStrictEqual is a function in Node.js that asserts whether two objects are strictly equal in value and type, recursively comparing nested properties.
4 5 6 7 8 9 10 11 12 13 14
// used in Audio/Video/Paragraphs sync const TIME_DIFF_THRESHOLD = 0.3; class AssertionHelper extends Helper { assertDeepEqualWithTolerance(actual, expected, fractionDigits = 2, message) { assert.deepStrictEqual( Helpers.convertToFixed(actual, fractionDigits), Helpers.convertToFixed(expected, fractionDigits), message, );
215 216 217 218 219 220 221 222 223 224
AtDetails.dontSeeMeta('23'); I.say('Check that meta is saved correctly'); const resultWithMeta = await LabelStudio.serialize(); assert.deepStrictEqual(resultWithMeta[2].meta.text, ['M 1\nM 2\n3']); I.say('Remove meta'); AtDetails.clickMeta(); fillByPressKeyDown([['CommandOrControl', 'a'], ['Backspace'], ['Enter']]);
How does assert.deepStrictEqual work?
assert.deepStrictEqual is a function in the built-in assert module in Node.js used to compare two values and assert that they are strictly equal in value and type, including any nested properties or elements. When assert.deepStrictEqual is called, it compares the two values recursively, starting from the top-level properties or elements, and checking each nested property or element. It uses the Object.is function to compare the values, which checks for strict equality, including NaN and -0. If the values are not strictly equal, assert.deepStrictEqual throws an AssertionError with a message indicating the values that were not equal. assert.deepStrictEqual is often used in automated tests to verify that a function or module produces the expected output. By comparing the output of a function with an expected value, developers can detect errors and prevent regressions. Since assert.deepStrictEqual compares values recursively, it can handle complex objects and arrays with nested properties or elements, making it a powerful tool for testing complex code.
GitHub: algorand/js-algorand-sdk
4172 4173 4174 4175 4176 4177 4178 4179 4180
const expectedType = algosdk.ABIType.from(expectedAbiType); const decodedResult = expectedType.decode(actualResult.rawReturnValue); const roundTripResult = expectedType.encode(decodedResult); assert.deepStrictEqual(roundTripResult, actualResult.rawReturnValue); } } );
+ 51 other calls in file
408 409 410 411 412 413 414 415 416 417
assert.deepStrictEqual( operations(actual), operations(expected), "Operations" ); assert.deepStrictEqual(schemas(actual), schemas(expected), "Schemas"); }); it("circular reference on collect primitive paths", function () { const csdl = {
+ 444 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
const assert = require("assert"); function doubleNumbers(numbers) { return numbers.map((n) => n * 2); } const input = [1, 2, 3]; const expectedOutput = [2, 4, 6]; const actualOutput = doubleNumbers(input); assert.deepStrictEqual( actualOutput, expectedOutput, "Expected output to be [2, 4, 6]" );
In this example, we first import the assert module. We define a function called doubleNumbers that takes an array of numbers and returns a new array with each number doubled. We define an input array of numbers and an expected output array. We then call the doubleNumbers function with the input array and store the result in actualOutput. Finally, we use assert.deepStrictEqual to assert that actualOutput is strictly equal to expectedOutput. If the values are not strictly equal, assert.deepStrictEqual will throw an AssertionError with the message "Expected output to be [2, 4, 6]". When we run the code, the test will pass if the actual output of the doubleNumbers function is equal to the expected output. If the test fails, we can inspect the AssertionError message to determine what went wrong.
345 346 347 348 349 350 351 352 353 354
"anti-csrf": res.antiCsrf, }, }); assert.strictEqual(res3.statusCode, 401); assert.deepStrictEqual(res3.result, { message: "token theft detected" }); let cookies = extractInfoFromResponse(res3); assert.strictEqual(cookies.antiCsrf, undefined); assert.strictEqual(cookies.accessToken, "");
+ 13 other calls in file
128 129 130 131 132 133 134
assert.deepStrictEqual( operations(actual), operations(expected), "Operations" ); assert.deepStrictEqual(actual, expected, "OpenAPI document"); }
+ 2 other calls in file
2857 2858 2859 2860 2861 2862 2863 2864 2865 2866
chai.assert.containsAllKeys(data.theTenant.application.monitorNotInband, keysOfInterest); }); it('should have the expected default properties', () => { assert.ok(validate(data), getErrorString(validate)); assert.deepStrictEqual(data.theTenant.application.monitorInband, { class: 'Monitor', monitorType: 'inband', failureInterval: 30,
+ 3 other calls in file
128 129 130 131 132 133 134 135 136 137
it('should match routing', () => { assert.ok(testRoute(body.Common.myRoute, currentState, 'myRoute')); }); it('should match failover unicast address', () => assert.deepStrictEqual( currentState.FailoverUnicast, { unicastAddress: [ {
+ 28 other calls in file
87 88 89 90 91 92 93 94 95 96
it('should emit start event', (done) => { let config = Object.assign({}, tester.constants.defaults, {uptime: 1234567, immediate: true}); tester.on('start', event => { assert.strictEqual(event.type, tester.constants.events.START); assert.strictEqual(tester.isRunning(), true); assert.deepStrictEqual(tester.config(), config); done(); }); tester.start(config); });
+ 3 other calls in file
536 537 538 539 540 541 542 543 544 545
// Array order of the docs is important for equality, but not for backup backupContent.sort(sortByIdThenRev); expectedContent.sort(sortByIdThenRev); // Assert that the backup matches the expected try { assert.deepStrictEqual(backupContent, expectedContent); callback(); } catch (err) { callback(err); }
+ 5 other calls in file
223 224 225 226 227 228 229 230 231 232
// network assert.strictEqual(parsedDeclaration.Common.VLAN.commonVlan.name, 'commonVlan'); assert.strictEqual(parsedDeclaration.Common.VLAN.commonVlan.tag, 1111); assert.strictEqual(parsedDeclaration.Common.NTP.timezone, 'UTC'); assert.deepStrictEqual(parsedDeclaration.Common.NTP.servers, ['0.pool.ntp.org', '1.pool.ntp.org']); assert.strictEqual(parsedDeclaration.Common.MAC_Masquerade.commonMac.name, 'commonMac'); assert.strictEqual(parsedDeclaration.Common.MAC_Masquerade.commonMac.source.interface, '1.1'); assert.strictEqual(parsedDeclaration.Common.MAC_Masquerade.commonMac2.name, 'commonMac2'); assert.strictEqual(parsedDeclaration.Common.MAC_Masquerade.commonMac2.source.interface, '1.2');
+ 4 other calls in file
1164 1165 1166 1167 1168 1169 1170 1171 1172
const runningArgs = updateResultSpy.getCall(0).args; const rollingBackArgs = updateResultSpy.getCall(1).args; const rolledBackArgs = updateResultSpy.getCall(2).args; assert.deepStrictEqual(runningArgs[1], 202); assert.deepStrictEqual(runningArgs[2], 'RUNNING'); assert.deepStrictEqual(rollingBackArgs[1], 202); assert.deepStrictEqual(rollingBackArgs[2], 'ROLLING_BACK');
+ 6 other calls in file
GitHub: thylacine/websub-hub
140 141 142 143 144 145 146 147 148 149
columnTwo: 4, }, ]; db.pgpInitOptions.receive({ data, result, ctx: event }); assert(db.logger.debug.called); assert.deepStrictEqual(data, expectedData); }); it('covers NOTIFY', function () { const data = [ {
+ 57 other calls in file
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609
let copy = JSON.parse(JSON.stringify(require('./test_data.json').deps)) console.log( deps, copy ) deepStrictEqual(deps, copy, 'deepEqual Relations test') }
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
}, (err, res, body) => { assert.ifError(err); assert.strictEqual(res.statusCode, 404); const parsedResponse = JSON.parse(body); assert.deepStrictEqual(parsedResponse.response, {}); assert.deepStrictEqual(parsedResponse.status, { code: 'not-found', message: 'User does not exist', }); done();
+ 7 other calls in file
67 68 69 70 71 72 73 74 75 76 77
describe("toArray", function () { it("should work", function () { const expected = [5, 6, 22, 11]; const head = toLinkedList(expected); const actual = toArray(head); assert.deepStrictEqual(actual, expected); }); }); describe("toLinkedList", function () {
+ 4 other calls in file
61 62 63 64 65 66 67 68 69 70
it("Example 1", function () { const head1 = toLinkedList([2, 4, 3]); const head2 = toLinkedList([5, 6, 4]); const actual = addTwoNumbers(head1, head2); const expected = [7, 0, 8]; assert.deepStrictEqual(toArray(actual), expected); }); it("Example 2", function () { const head1 = toLinkedList([0]); const head2 = toLinkedList([0]);
+ 2 other calls in file
GitHub: Automattic/mongoose
4313 4314 4315 4316 4317 4318 4319 4320 4321 4322
// Act await User.syncIndexes(); // Assert const indexes = await User.listIndexes(); assert.deepStrictEqual(indexes.map(index => index.name), ['_id_', 'name_1']); }); it('drops indexes that are not present in schema', async() => { // Arrange
+ 73 other calls in file
166 167 168 169 170 171 172 173 174 175
"name": "test API" }) .expect(200) const aux = JSON.parse(response.text); assert.deepStrictEqual(aux.name, expected.name); }); it('update category error by id empty', async () => { const expected = { error: 'Field id is required' };
+ 147 other calls in file
555 556 557 558 559 560 561 562 563
.send(post) .expect('Content-Type', /json/) .expect(200, post) // TODO find a "supertest" way to test this // https://github.com/typicode/json-server/issues/396 assert.deepStrictEqual(res.body, post) // assert it was created in database too assert.deepStrictEqual(db.posts[0], post) })
+ 3 other calls in file
assert.equal is the most popular function in assert (3580 examples)