Repository: pactumjs/pactum
Pull request #357 (2024-05-28 14:29:11)

chore: add actual value in assert expression failure


Patch:
diff --git a/package-lock.json b/package-lock.json
index cdd6280..7bfe008 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "pactum",
-  "version": "3.6.9",
+  "version": "3.7.0",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "pactum",
-      "version": "3.6.9",
+      "version": "3.7.0",
       "license": "MIT",
       "dependencies": {
         "@exodus/schemasafe": "^1.3.0",
diff --git a/package.json b/package.json
index b38fb3e..03b010a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "pactum",
-  "version": "3.6.9",
+  "version": "3.7.0",
   "description": "REST API Testing Tool for all levels in a Test Pyramid",
   "main": "./src/index.js",
   "types": "./src/index.d.ts",
diff --git a/src/adapters/json.like.js b/src/adapters/json.like.js
index c07a73f..c4139b1 100644
--- a/src/adapters/json.like.js
+++ b/src/adapters/json.like.js
@@ -34,7 +34,7 @@ class LikeJson {
         const expression = expected.replace(value, 'actual');
         const res = eval(expression);
         if (res !== true) {
-          return `${this.target} doesn't fulfil expression '${expression.replace('actual', expectedPath).trim()}'`;
+          return `${this.target} doesn't fulfil expression '${expression.replace('actual', expectedPath).trim()}'. Actual value found: ${actual}`;
         }
         return true;
       }
@@ -169,7 +169,7 @@ class LikeJson {
 function validate(actual, expected, opts) {
   let actual_path = '$';
   let expected_path = '$';
-  if (opts && opts.root_path) { 
+  if (opts && opts.root_path) {
     expected_path = opts.root_path;
   }
   return new LikeJson(opts).compare(actual, expected, actual_path, expected_path);


Test patch:
diff --git a/test/unit/json.like.spec.js b/test/unit/json.like.spec.js
index e1ff6bb..e20aa73 100644
--- a/test/unit/json.like.spec.js
+++ b/test/unit/json.like.spec.js
@@ -1051,8 +1051,8 @@ describe('JSON Like - Assert Expressions', () => {
   it('object does not fulfil simple expression', () => {
     const actual = { id: 1 };
     const expected = { id: '$V > 1' };
-    expect(jsl.validate(actual, expected)).equals(`Json doesn't fulfil expression '$.id > 1'`);
-    expect(jsl.validate(actual, expected, { root_path: 'data' })).equals(`Json doesn't fulfil expression 'data.id > 1'`);
+    expect(jsl.validate(actual, expected)).equals(`Json doesn't fulfil expression '$.id > 1'. Actual value found: 1`);
+    expect(jsl.validate(actual, expected, { root_path: 'data' })).equals(`Json doesn't fulfil expression 'data.id > 1'. Actual value found: 1`);
   });
 
   it('array fulfil simple expression', () => {
@@ -1064,8 +1064,8 @@ describe('JSON Like - Assert Expressions', () => {
   it('array does not fulfil simple expression', () => {
     const actual = [{ id: 1 }];
     const expected = '$V.length > 1';
-    expect(jsl.validate(actual, expected)).equals(`Json doesn't fulfil expression '$.length > 1'`);
-    expect(jsl.validate(actual, expected, { root_path: 'data.users' })).equals(`Json doesn't fulfil expression 'data.users.length > 1'`);
+    expect(jsl.validate(actual, expected)).equals(`Json doesn't fulfil expression '$.length > 1'. Actual value found: [object Object]`);
+    expect(jsl.validate(actual, expected, { root_path: 'data.users' })).equals(`Json doesn't fulfil expression 'data.users.length > 1'. Actual value found: [object Object]`);
   });
 
   it('object fulfil complex expression', () => {
@@ -1077,7 +1077,7 @@ describe('JSON Like - Assert Expressions', () => {
   it('object does not fulfil complex expression', () => {
     const actual = { id: 1, marks: { maths: 70 } };
     const expected = { id: 1, marks: { maths: '$V > 80' } };
-    expect(jsl.validate(actual, expected)).equals(`Json doesn't fulfil expression '$.marks.maths > 80'`);
+    expect(jsl.validate(actual, expected)).equals(`Json doesn't fulfil expression '$.marks.maths > 80'. Actual value found: 70`);
   });
 
   it('object fulfil simple custom includes expression', () => {