Skip to content

toThrowWithMessage - should assert extra error fields #709

@razbensimon

Description

@razbensimon

Hey,
I would expect toThrowWithMessage to help with asserting extra/extended Error types. Consider extra fields besides just the error class type and message.

I have this type:

class ExecutionError extends Error {
  exitCode: number;
  failedCommand: string;

  constructor(errorMessage: string, exitCode: number, failedCommand: string) {
    super(errorMessage);
    this.exitCode = exitCode;
    this.failedCommand = failedCommand;
  }
}

which I wish I could assert failedCommand easily in a test.
I tried toStrictEqual too, without luck.

WDYT? Can you add such a thing?
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions