-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests for ajv helpers #430
base: mainnet-launch
Are you sure you want to change the base?
Conversation
/review |
Preparing review... |
/review |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
/improve |
// Mock implementation for initAjvSchemas that throws an error | ||
const mockInitAjvSchemasWithError = () => { | ||
const mockFn = mockRegistry.get('initGetAccountData3Req') | ||
if (mockFn) { | ||
mockFn() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Ensure that the mockInitAjvSchemasWithError
function actually throws an error to properly test error handling in schema initialization. [possible issue, importance: 8]
// Mock implementation for initAjvSchemas that throws an error | |
const mockInitAjvSchemasWithError = () => { | |
const mockFn = mockRegistry.get('initGetAccountData3Req') | |
if (mockFn) { | |
mockFn() | |
} | |
const mockInitAjvSchemasWithError = () => { | |
const mockFn = mockRegistry.get('initGetAccountData3Req') | |
if (mockFn) { | |
mockFn() | |
} | |
throw new Error('Schema initialization error') | |
} |
const createMockVerifyFn = (isValid: boolean, errors: ErrorObject[] | null) => { | ||
const mockFn = jest.fn().mockReturnValue(isValid) as jest.Mock & { errors: ErrorObject[] | null } | ||
mockFn.errors = errors | ||
return mockFn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Ensure that the createMockVerifyFn
function correctly assigns the errors
property to the mock function to avoid potential issues with error handling. [possible issue, importance: 7]
const createMockVerifyFn = (isValid: boolean, errors: ErrorObject[] | null) => { | |
const mockFn = jest.fn().mockReturnValue(isValid) as jest.Mock & { errors: ErrorObject[] | null } | |
mockFn.errors = errors | |
return mockFn | |
const createMockVerifyFn = (isValid: boolean, errors: ErrorObject[] | null) => { | |
const mockFn = jest.fn().mockReturnValue(isValid) as jest.Mock & { errors: ErrorObject[] | null } | |
Object.defineProperty(mockFn, 'errors', { value: errors, writable: true }) | |
return mockFn | |
} |
|
||
// Cleanup - Restore the original implementation | ||
spy.mockRestore() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test mocks out initAjvSchemas
implementation then calls it. it shouldnt not mock the implementation its testing.
Spy is fine since we could check how many times it was called but we shouldn't mock the implementation that we want to test.
|
||
// Cleanup - Restore the original implementation | ||
spy.mockRestore() | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with this test. mocks out initAjvSchemas
throwing an error then calls it expecting an error.
dont mock out the implementation
No description provided.