Skip to content

Add unit tests for OAuthError and TimeoutError classes #3

@koistya

Description

@koistya

Description

The error classes in src/errors.ts currently lack unit tests. This is a critical gap in our test coverage that needs to be addressed to ensure these foundational error handling components work correctly.

What needs to be done

Create comprehensive unit tests that verify:

  • Constructor properly sets all error properties (error, error_description, error_uri)
  • Error inheritance from native Error class works correctly
  • Default messages are applied when not provided
  • Error name is set correctly to "OAuthError" and "TimeoutError"
  • The error stack trace is properly maintained
  • Serialization behavior (what happens with JSON.stringify)

Why this matters

Error handling is a critical part of OAuth flows. Without proper tests, we can't guarantee:

  • Errors are properly caught and identified in try/catch blocks
  • Error messages provide useful debugging information
  • The error properties match OAuth 2.0 specifications

Implementation considerations

⚠️ Note: This feature requires critical thinking during implementation. Consider:

  1. Edge cases: What happens with extremely long error descriptions? Unicode characters? Null/undefined values?
  2. Error comparison: Should we test error equality? How do we handle error comparison in tests?
  3. Alternative approach: Consider whether we should use a more sophisticated error hierarchy with specific error types (e.g., AccessDeniedError, InvalidScopeError) instead of a generic OAuthError
  4. Error recovery: Should these errors include recovery suggestions or links to documentation?

Files to modify/create

  • Create: src/errors.test.ts
  • Reference: src/errors.ts

Example test structure

import { expect, test, describe } from "bun:test";
import { OAuthError, TimeoutError } from "./errors";

describe("OAuthError", () => {
  test("should set properties correctly", () => {
    const error = new OAuthError("access_denied", "User denied access", "https://example.com/error");
    expect(error.error).toBe("access_denied");
    expect(error.error_description).toBe("User denied access");
    expect(error.error_uri).toBe("https://example.com/error");
    expect(error.name).toBe("OAuthError");
  });
  
  // Add more comprehensive tests...
});

Skills required

  • TypeScript
  • Testing with Bun
  • Understanding of error handling patterns

Difficulty

Easy - This is a great first issue for someone new to the codebase!

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions