Improved deep equality testing for Node.js and the browser with support for complex types and circular references.
Overall
score
96%
Build a validation utility that compares regular expression patterns to verify they match expected configurations.
Configuration files often define regular expression patterns for validation rules (email formats, phone numbers, URL patterns, etc.). When these configurations are loaded from different sources or modified by different systems, you need to verify that the patterns remain equivalent to the expected values.
Implement a function validateRegexConfig(actual, expected) that:
Accepts two parameters:
actual: An object containing regex patterns as valuesexpected: An object containing the expected regex patternsReturns an object with:
isValid: Boolean indicating if all patterns matchmismatches: Array of keys where patterns differ (empty if all match)The comparison should:
actual and expected will have the same keysProvides deep equality comparison for complex types including regular expressions.
File: validate-regex.test.js
const { validateRegexConfig } = require('./validate-regex');
test('should validate matching regex patterns', () => {
const actual = {
email: /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g,
phone: /^\d{3}-\d{3}-\d{4}$/
};
const expected = {
email: /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g,
phone: /^\d{3}-\d{3}-\d{4}$/
};
const result = validateRegexConfig(actual, expected);
expect(result.isValid).toBe(true);
expect(result.mismatches).toEqual([]);
});File: validate-regex.test.js
test('should detect flag differences', () => {
const actual = {
email: /test@example\.com/i,
url: /https?:\/\/.+/
};
const expected = {
email: /test@example\.com/, // Missing 'i' flag
url: /https?:\/\/.+/
};
const result = validateRegexConfig(actual, expected);
expect(result.isValid).toBe(false);
expect(result.mismatches).toEqual(['email']);
});File: validate-regex.test.js
test('should detect pattern differences', () => {
const actual = {
zipCode: /^\d{5}$/,
date: /^\d{4}-\d{2}-\d{2}$/
};
const expected = {
zipCode: /^\d{5}-\d{4}$/, // Different pattern
date: /^\d{4}-\d{2}-\d{2}$/
};
const result = validateRegexConfig(actual, expected);
expect(result.isValid).toBe(false);
expect(result.mismatches).toEqual(['zipCode']);
});Install with Tessl CLI
npx tessl i tessl/npm-deep-eqldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10