Jest: What mean in toBeUndefined?

Created on 18 Jun 2019  ·  4Comments  ·  Source: facebook/jest

🐛 Bug Report

the code expect(undefined).not.toBeUndefined
it pass the test.
Dose it means undefined !== undefined ????

and I found any test with toBeUndefined, it will pass
like this expect(1).toBeUndefined

To Reproduce

the full test code

test('1: undefined is not be undefined?', () => {
  expect(undefined).not.toBeUndefined
})


test('2: undefined is not be undefined?', () => {
  expect(undefined).not.toBe(undefined)
})


test('3: 1 is be the undefined?', () => {
  expect(1).toBeUndefined
})

the result

 FAIL  test/undefined.test.js
  ✓ 1: undefined is not be undefined?
  ✕ 2: undefined is not be undefined? (1ms)
  ✓ 3: 1 is be the undefined?

  ● 2: undefined is not be undefined?

    expect(received).not.toBe(expected) // Object.is equality

    Expected: not undefined

       6 | 
       7 | test('2: undefined is not be undefined?', () => {
    >  8 |   expect(undefined).not.toBe(undefined)
         |                         ^
       9 | })
      10 | 
      11 | 

      at Object.<anonymous>.test **(test/undefined.test.js:8:25)**

## Expected behavior

toBeUndefined should alias toBe(undefined)

Bug Report Needs Repro Needs Triage

Most helpful comment

You need to call it: expect(undefined).toBeDefined(), it's a function, not a property/getter

All 4 comments

I found the code expect(undefined).toBeDefined will pass the test also.

You need to call it: expect(undefined).toBeDefined(), it's a function, not a property/getter

You need to call it: expect(undefined).toBeDefined(), it's a function, not a property/getter

@thymikee thanks,
I am sorry to submit this issue,
and I should ready the docs carefully.

Happens! Have fun testing :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ticky picture ticky  ·  3Comments

samzhang111 picture samzhang111  ·  3Comments

withinboredom picture withinboredom  ·  3Comments

StephanBijzitter picture StephanBijzitter  ·  3Comments

kentor picture kentor  ·  3Comments