Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toThrowError() treats empty string param as though it is undefined #6618

Closed
6 tasks done
U-4-E-A opened this issue Oct 2, 2024 · 1 comment · Fixed by #6710
Closed
6 tasks done

toThrowError() treats empty string param as though it is undefined #6618

U-4-E-A opened this issue Oct 2, 2024 · 1 comment · Fixed by #6710
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) pr welcome

Comments

@U-4-E-A
Copy link

U-4-E-A commented Oct 2, 2024

Describe the bug

toThrowError() treats an empty string (toThrowError('')) as it would if the value was undefined when it should reject an empty string as it is not equal to the error.

Reproduction

import { expect, test } from 'vitest'

function getFruitStock(type: string): void {
  if (type === 'pineapples') {
    throw new Error('Pineapples are not in stock')
  }
}

test('throws on pineapples', () => {
  // undefined error passes
  expect(() => getFruitStock('pineapples')).toThrowError()
  // error of empty string should fail as it does not represent the error but passes
  expect(() => getFruitStock('pineapples')).toThrowError('')
})

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 4.36 GB / 15.73 GB
  Binaries:
    Node: 22.4.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.21 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.8.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.19041.4355
  npmPackages:
    vitest: ^2.0.5 => 2.1.1

Used Package Manager

yarn

Validations

@sheremet-va sheremet-va added pr welcome p2-edge-case Bug, but has workaround or limited in scope (priority) and removed pending triage labels Oct 2, 2024
@hi-ogawa
Copy link
Contributor

hi-ogawa commented Oct 3, 2024

This might be a chai issue. It's very similar to #5228 but this time it's empty string on "expected" side. We can probably fix it on our side though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2-edge-case Bug, but has workaround or limited in scope (priority) pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants