01What is Jest Matcher Builder?
This builder helps you write a Jest test block by hand, one assertion at a time. It does not guess assertions from sample data. You name the describe() and it() blocks, then add rows. Each row has an Actual Value, a Matcher picked from a list of 20, an optional Expected Value and a Negate (.not) checkbox. The matchers are grouped the way the Jest expect docs group them. Basic has toBe, toEqual and toStrictEqual. Truthiness has toBeNull, toBeUndefined, toBeTruthy and toBeFalsy. Collections has toContain and toHaveLength, and Objects has toHaveProperty and toMatchObject. Errors has toThrow plus a toThrow(ErrorClass) entry. Numbers has toBeGreaterThan, toBeLessThan and toBeCloseTo. Strings has toMatch, and Mocks has toHaveBeenCalled, toHaveBeenCalledWith and toHaveBeenCalledTimes. Category buttons above the dropdown filter it. The output uses the names that survive in Jest 30. That release dropped old aliases like toThrowError and toBeCalled. Picking the toThrow(ErrorClass) entry still writes plain toThrow(SyntaxError). A few small rules make the generated code safer. For the two error matchers, an actual value that ends in a call, like parse('x'), is wrapped as () => parse('x'). Jest can only catch the error if it calls the function itself. An existing arrow function or a bare name like parse is left alone. An awaited call such as await load() becomes await expect(load()).rejects.toThrow(), and the it() callback turns async. Matchers that take no argument, such as toBeNull or toHaveBeenCalled, hide the Expected Value field and print empty parentheses. The describe and it names are written as JSON string literals, so a quote in a test name gets escaped instead of breaking the file. An empty Actual Value falls back to the placeholder name value. Here is a quick example. Name the blocks sum and adds, then set sum(1, 2) with toBe and 3. Add a second row with sum(1, 2), toBeNull and Negate ticked. You get a four-space indented expect(sum(1, 2)).toBe(3) line followed by expect(sum(1, 2)).not.toBeNull(), wrapped in a complete describe and it block. Now the limits. Values go in exactly as you type them, so strings need your own quotes. The builder does not check that your code parses. There is no beforeEach or other setup code.
JavaScript and TypeScript developers drafting Jest or Vitest assertions, and instructors who teach the expect API. The tool runs entirely in your browser, so your data never leaves your device.
02How to use Jest Matcher Builder
- Enter names in the describe() block name and it() block name fields.
- Fill in Actual Value for the first assertion, such as result, mockFn or parse('x').
- Use the category buttons to narrow the list, then choose a Matcher from the dropdown.
- Enter an Expected Value if the matcher needs one, and tick Negate (.not) if you want the opposite check.
- Click Add Assertion for more rows, then copy the Generated Test Code.
03Worked examples
- Input:
describe "sum", it "adds"; sum(1, 2) toBe 3; sum(1, 2) toBeNull with Negate - Result:
describe("sum", () => { it("adds", () => { expect(sum(1, 2)).toBe(3); expect(sum(1, 2)).not.toBeNull(); }); }); - toBeNull takes no argument, so the expected value is dropped.
- Input:
parse('x') with toThrow(ErrorClass) SyntaxError; () => parse('y') with toThrow; parse with toThrow - Result:
expect(() => parse('x')).toThrow(SyntaxError); expect(() => parse('y')).toThrow(); expect(parse).toThrow(); - Only the assertion lines are shown. A call is wrapped, while an arrow or a bare name is left as is.
- Input:
Empty Actual Value, toEqual { id: 1 } - Result:
expect(value).toEqual({ id: 1 }); - An empty actual field falls back to the placeholder value.
- Input:
describe name: say "hi" - Result:
describe("say \"hi\"", () => { - Quotes in block names are escaped. Only the first line is shown.
- Input:
0.1 + 0.2 toBeCloseTo 0.3; mockFn toHaveBeenCalledTimes 2 - Result:
expect(0.1 + 0.2).toBeCloseTo(0.3); expect(mockFn).toHaveBeenCalledTimes(2); - Assertion lines only.
- Input:
await load() with toThrow - Result:
await expect(load()).rejects.toThrow(); - The it() callback is written as async () => so the await is valid.
04Common use cases
- Writing the first test file for a utility module in a project that just added Jest
- Drafting mock call assertions for a service layer that wraps fetch, using toHaveBeenCalledWith and toHaveBeenCalledTimes
- Showing a workshop group how toEqual and toStrictEqual differ by building both lines side by side
- Adding negative cases with .not for an input validation helper
- Producing a test skeleton to paste into a Vitest file, since Vitest follows the same expect API for these matchers
- Updating old tests that used toThrowError or toBeCalled to the names Jest 30 still accepts
05Tips
- toEqual ignores undefined properties and class types, while toStrictEqual checks them. Use the strict one when the exact shape matters.
- For promises, type await load() as the actual value with toThrow. The builder writes the rejects form and makes the it() callback async for you.
- Values are pasted in verbatim. Quote strings yourself, like "hello", and use a regex literal such as /^ok/ for toMatch.
- Use toBeCloseTo for floats such as 0.1 + 0.2. A plain toBe fails there because of rounding error.
- Typing a bare function name like parse for toThrow is fine. Jest calls it with no arguments.
06Related concepts
Jest, matchers, mock functions, describe and it blocks, unit tests.
Frequently Asked Questions
What is Jest Matcher Builder?
Jest Matcher Builder is a free, browser-based developer tool on AIDToolStack. Build Jest test assertions It requires no installation or sign-up and works entirely in your browser.
Is Jest Matcher Builder free to use?
Yes. No sign-up, no fees and no usage cap.
Does Jest Matcher Builder store my data?
No. It runs in your browser; nothing is uploaded.