Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
iankhou committed Jan 22, 2025
1 parent 64a1125 commit 9450eb8
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { Construct } from 'constructs';
import { ValidationError } from '../../lib/errors';
import { validateAllProps, ValidationRule } from '../../lib/helpers-internal/validate-all-props';

class MockConstruct extends Construct {
class TestConstruct extends Construct {
constructor() {
super(undefined as any, 'MockConstruct');
super(undefined as any, 'TestConstruct');
}
}

describe('validateAllProps', () => {
let mockScope: Construct;
let testScope: Construct;

beforeEach(() => {
mockScope = new MockConstruct();
testScope = new TestConstruct();
});

it('should not throw an error when all validations pass', () => {
Expand All @@ -24,7 +24,7 @@ describe('validateAllProps', () => {
},
];

expect(() => validateAllProps(mockScope, 'TestClass', props, rules)).not.toThrow();
expect(() => validateAllProps(testScope, 'TestClass', props, rules)).not.toThrow();
});

it('should throw a ValidationError when a validation fails', () => {
Expand All @@ -36,7 +36,7 @@ describe('validateAllProps', () => {
},
];

expect(() => validateAllProps(mockScope, 'TestClass', props, rules)).toThrow(ValidationError);
expect(() => validateAllProps(testScope, 'TestClass', props, rules)).toThrow(ValidationError);
});

it('should include all failed validation messages in the error', () => {
Expand All @@ -52,9 +52,9 @@ describe('validateAllProps', () => {
},
];

expect(() => validateAllProps(mockScope, 'TestClass', props, rules)).toThrow(ValidationError);
expect(() => validateAllProps(testScope, 'TestClass', props, rules)).toThrow(ValidationError);
try {
validateAllProps(mockScope, 'TestClass', props, rules);
validateAllProps(testScope, 'TestClass', props, rules);
} catch (error) {
if (error instanceof ValidationError) {
expect(error.message).toBe(
Expand All @@ -75,9 +75,9 @@ describe('validateAllProps', () => {
},
];

expect(() => validateAllProps(mockScope, 'TestClass', props, rules)).toThrow(ValidationError);
expect(() => validateAllProps(testScope, 'TestClass', props, rules)).toThrow(ValidationError);
try {
validateAllProps(mockScope, 'TestClass', props, rules);
validateAllProps(testScope, 'TestClass', props, rules);
} catch (error) {
if (error instanceof ValidationError) {
expect(error.message).toBe(
Expand Down

0 comments on commit 9450eb8

Please sign in to comment.