Skip to content

Instantly share code, notes, and snippets.

@stared
Created February 13, 2020 23:17
Show Gist options
  • Save stared/bfcaad992a19d2e20b189549434d11aa to your computer and use it in GitHub Desktop.
Save stared/bfcaad992a19d2e20b189549434d11aa to your computer and use it in GitHub Desktop.

Revisions

  1. stared created this gist Feb 13, 2020.
    21 changes: 21 additions & 0 deletions jest_typescript_extend.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    export {}

    declare global {
    namespace jest {
    interface Matchers<R> {
    myMatcher: (received: string) => R
    }
    }
    }

    function myMatcher<T>(this: jest.MatcherUtils, received: string, expected: string): jest.CustomMatcherResult {
    const pass = received === expected
    return {
    pass,
    message: (): string => `expected ${received} to be ${expected}`,
    }
    }

    expect.extend({
    myMatcher,
    })