mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added tests for ValidationErrorsFormatter
This commit is contained in:
+2
-1
@@ -13,7 +13,8 @@ import './unit-tests/decorators/initializable/Initializable.spec';
|
||||
import './unit-tests/node/node-appender/NodeAppender.spec';
|
||||
import './unit-tests/node/node-utils/NodeUtils.spec';
|
||||
import './unit-tests/obfuscation-result/ObfuscationResult.spec';
|
||||
import './unit-tests/options/options-normalizer/OptionsNormalizer.spec';
|
||||
import './unit-tests/options/OptionsNormalizer.spec';
|
||||
import './unit-tests/options/ValidationErrorsFormatter.spec';
|
||||
import './unit-tests/source-map-corrector/SourceMapCorrector.spec';
|
||||
import './unit-tests/stack-trace-analyzer/stack-trace-analyzer/StackTraceAnalyzer.spec';
|
||||
import './unit-tests/storages/ArrayStorage.spec';
|
||||
|
||||
+5
-5
@@ -1,13 +1,13 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { TInputOptions } from '../../../../src/types/options/TInputOptions';
|
||||
import { TInputOptions } from '../../../src/types/options/TInputOptions';
|
||||
|
||||
import { IOptions } from '../../../../src/interfaces/options/IOptions';
|
||||
import { IOptions } from '../../../src/interfaces/options/IOptions';
|
||||
|
||||
import { DEFAULT_PRESET } from '../../../../src/options/presets/Default';
|
||||
import { DEFAULT_PRESET } from '../../../src/options/presets/Default';
|
||||
|
||||
import { Options } from '../../../../src/options/Options';
|
||||
import { OptionsNormalizer } from '../../../../src/options/OptionsNormalizer';
|
||||
import { Options } from '../../../src/options/Options';
|
||||
import { OptionsNormalizer } from '../../../src/options/OptionsNormalizer';
|
||||
|
||||
/**
|
||||
* @param optionsPreset
|
||||
@@ -0,0 +1,108 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { ValidationError } from 'class-validator';
|
||||
|
||||
import { ValidationErrorsFormatter } from '../../../src/options/ValidationErrorsFormatter';
|
||||
|
||||
describe('ValidationErrorsFormatter', () => {
|
||||
describe('format (validationErrors: ValidationError[]): string', () => {
|
||||
describe('variant #1: one constraint group with one constraint', () => {
|
||||
const constraintGroupRegExp: RegExp = /`foo` *errors:/;
|
||||
const constraintRegExp: RegExp = /(?: *-)+ *constraint *text/;
|
||||
const validationErrors: ValidationError[] = [{
|
||||
target: {},
|
||||
property: 'foo',
|
||||
value: null,
|
||||
constraints: {
|
||||
'constraint1': '- constraint text'
|
||||
},
|
||||
children: []
|
||||
}];
|
||||
|
||||
let validationError: string;
|
||||
|
||||
before(() => {
|
||||
validationError = ValidationErrorsFormatter.format(validationErrors);
|
||||
});
|
||||
|
||||
it('match #1: should return valid validation errors', () => {
|
||||
assert.match(validationError, constraintGroupRegExp);
|
||||
});
|
||||
|
||||
it('match #2: should return valid validation errors', () => {
|
||||
assert.match(validationError, constraintRegExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #2: one constraint group with two constraint', () => {
|
||||
const constraintGroupRegExp: RegExp = /`foo` *errors:/;
|
||||
const constraintRegExp1: RegExp = /(?: *-)+ constraint *text *#1/;
|
||||
const constraintRegExp2: RegExp = /(?: *-)+ constraint *text *#2/;
|
||||
const validationErrors: ValidationError[] = [{
|
||||
target: {},
|
||||
property: 'foo',
|
||||
value: null,
|
||||
constraints: {
|
||||
'constraint1': '- constraint text #1',
|
||||
'constraint2': '- constraint text #2'
|
||||
},
|
||||
children: []
|
||||
}];
|
||||
|
||||
let validationError: string;
|
||||
|
||||
before(() => {
|
||||
validationError = ValidationErrorsFormatter.format(validationErrors);
|
||||
});
|
||||
|
||||
it('match #1: should return valid validation errors', () => {
|
||||
assert.match(validationError, constraintGroupRegExp);
|
||||
});
|
||||
|
||||
it('match #2: should return valid validation errors', () => {
|
||||
assert.match(validationError, constraintRegExp1);
|
||||
});
|
||||
|
||||
it('match #3: should return valid validation errors', () => {
|
||||
assert.match(validationError, constraintRegExp2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #3: two constraint groups', () => {
|
||||
const regExpMatch: string = `` +
|
||||
`\`foo\` *errors:\\n` +
|
||||
`(?: *-)+ *constraint *group *#1 *text\\n+` +
|
||||
`\`bar\` *errors:\\n` +
|
||||
`(?: *-)+ *constraint *group *#2 *text\\n+` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(regExpMatch);
|
||||
const validationErrors: ValidationError[] = [{
|
||||
target: {},
|
||||
property: 'foo',
|
||||
value: null,
|
||||
constraints: {
|
||||
'constraint': '- constraint group #1 text'
|
||||
},
|
||||
children: []
|
||||
}, {
|
||||
target: {},
|
||||
property: 'bar',
|
||||
value: null,
|
||||
constraints: {
|
||||
'constraint': '- constraint group #2 text'
|
||||
},
|
||||
children: []
|
||||
}];
|
||||
|
||||
let validationError: string;
|
||||
|
||||
before(() => {
|
||||
validationError = ValidationErrorsFormatter.format(validationErrors);
|
||||
});
|
||||
|
||||
it('should return valid validation errors', () => {
|
||||
assert.match(validationError, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user