---
title: "Discussion on \"Writing Tests for Custom Matchers in Jest\" | Hashnode"
description: "Discussion on \"Writing Tests for Custom Matchers in Jest\". TLDR: Here's an example of how to write a test for a custom matcher:\ndescribe(\"toHaveDevDependency\", () => {\n  it(\"fails when given a number\", () => {\n    expect(() => {\n      expect(2).toHaveDevDependency(\"node\");\n    }).toThrow(\"Expected 2 to be a ..."
url: "https://hashnode.com/posts/writing-tests-for-custom-matchers-in-jest/62e859c7430bd1d04a8484ab"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Writing Tests for Custom Matchers in Jest](https://blog.chiubaka.com/writing-tests-for-custom-matchers-in-jest?utm_source=hashnode&utm_medium=feed)

TLDR: Here's an example of how to write a test for a custom matcher: describe("toHaveDevDependency", () => { it("fails when given a number", () => { expect(() => { expect(2).toHaveDevDependency("node"); }).toThrow("Expected 2 to be a ...

Jul 7, 2022 · 4 min read · blog.chiubaka.com  
Read the article

-   [#jest](https://hashnode.com/tag/jest)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#testing](https://hashnode.com/tag/testing)
-   [#tdd](https://hashnode.com/tag/tdd)

## Written by

[Daniel](https://hashnode.com/@chiubaka)

@chiubaka

  
[View profile](https://hashnode.com/@chiubaka)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
