Skip to content

Commit 9216393

Browse files
yT0n1barmac
authored andcommitted
test: add full validation error output for failed test
Allows developers to directly copy the error to the fixture file.
1 parent 50b9c04 commit 9216393

File tree

2 files changed

+20
-2
lines changed
  • packages

2 files changed

+20
-2
lines changed

packages/element-templates-json-schema-shared/test/helpers/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const {
33
set
44
} = require('min-dash');
55

6+
const chai = require('chai');
7+
68
const { default: Ajv } = require('ajv');
79
const AjvErrors = require('ajv-errors');
810

@@ -53,4 +55,20 @@ function setErrorMessage(schema, error) {
5355
];
5456

5557
return set(schema, errorMessagePath, errorMessage);
56-
}
58+
}
59+
60+
function eqlErrors(chai, utils) {
61+
62+
const Assertion = chai.Assertion;
63+
64+
Assertion.addMethod('eqlErrors', function(expectedErrors, filter) {
65+
66+
const actualErrors = this._obj;
67+
68+
// formats the validation errors, so that they can be used directly in the fixture files.
69+
this.eql(expectedErrors,
70+
`Errors from validation do not match expected.\n\tValidation returned this error (you can use it in the fixture):\n\t${JSON.stringify(actualErrors, null, 2).replace(/"([^"]+)":/g, '$1:')}\n`);
71+
});
72+
}
73+
74+
chai.use(eqlErrors);

packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function createTest(name, file, it) {
4949
} = validateTemplate(template);
5050

5151
// then
52-
expect(errors).to.eql(expectedErrors);
52+
expect(errors).to.eqlErrors(expectedErrors);
5353
});
5454
}
5555

0 commit comments

Comments
 (0)