Skip to content

Commit

Permalink
chore: add actual value in asser expression failure (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored May 28, 2024
1 parent 2005889 commit 851d1f2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/json.like.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions test/unit/json.like.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit 851d1f2

Please sign in to comment.