From dc42f050765214e71fd838f8ab6bed273097b511 Mon Sep 17 00:00:00 2001 From: Varun0157 Date: Sat, 11 May 2024 19:54:18 +0530 Subject: [PATCH] feat: going one level deeper for size assertions (supporting $gt, $gte, etc.) --- package-lock.json | 4 ++-- src/runTests.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 95538d2..d4524a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "zzapi", - "version": "1.0.2", + "version": "1.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "zzapi", - "version": "1.0.2", + "version": "1.1.1", "license": "MIT", "dependencies": { "got": "11.8.6", diff --git a/src/runTests.ts b/src/runTests.ts index e6d8c3f..fbc2336 100644 --- a/src/runTests.ts +++ b/src/runTests.ts @@ -95,7 +95,17 @@ function runObjectTests( } else if (typeof receivedObject === "string" || Array.isArray(receivedObject)) { receivedLen = receivedObject.length; } - pass = receivedLen === expected; + if (typeof expected === "number") { + pass = receivedLen === expected; + } else { + try { + expected = JSON.parse(expected); + } catch (err: any) { + message = `$size val is not num or valid JSON`; + } + results.push(...runObjectTests(expected, receivedLen, spec)); + continue; + } } else if (op === "$exists") { const exists = received != undefined; pass = exists === expected;