Skip to content

.not.toThrowErrorMatchingInlineSnapshot() doesn't work as expected #3089

@Maxim-Mazurok

Description

@Maxim-Mazurok

Describe the bug

I created a failing test using .not.toThrowErrorMatchingInlineSnapshot() to demonstrate to my colleague the error that they have to address.
However, when they fixed the error - the test still doesn't pass, because vitest returns Error: snapshot function didn't throw for this test.
I expect .not.toThrowErrorMatchingInlineSnapshot() to assert that error was either not thrown, or it was thrown but didn't match the snapshot.
Current behaviour is more like expect().toTrowError.not.matchingInlineSnapshot(), hope this makes sense!

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-cmmyai?file=test/basic.test.ts

// passes
it("throws", () => {
  expect(() => {
    throw "Bla-bla";
  }).toThrowErrorMatchingInlineSnapshot('"Bla-bla"');
});

// fails with `Error: snapshot function didn't throw`
it("doesn't throw", () => {
  expect(() => {}).not.toThrowErrorMatchingInlineSnapshot('"Bla-bla"');
});

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish)
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
    Memory: 23.12 GB / 31.19 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node
    npm: 8.19.3 - ~/.nvm/versions/node/v18.13.0/bin/npm
  Browsers:
    Chrome: 111.0.5563.110
  npmPackages:
    @vitejs/plugin-vue: ^3.1.2 => 3.2.0 
    @vitejs/plugin-vue-jsx: ^1.3.9 => 1.3.10 
    @vitest/coverage-c8: ^0.29.2 => 0.29.2 
    vite: ^3.1.8 => 3.2.5 
    vitest: ^0.29.2 => 0.29.2 

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions