Skip to content

Conversation

@xamgore
Copy link
Contributor

@xamgore xamgore commented Apr 14, 2021

Imagine we have a code like this. If expect.fail() returns R, we won't be able to call val.slice as val may be null, thus we get a compiler error.

    test('example', async () => {
      const val = foo() // string | null
      if (!val) expect.fail('string expected, got null')
      
      val.slice(5) // some operations with the string
      // ...
    })

Though, if we change expect.fail() return type to never, typescript will start understanding the further execution won't be possible with val === null, so the val.slice is exactly string::slice call. And there won't be any compilation errors.

@xamgore
Copy link
Contributor Author

xamgore commented Apr 15, 2021

@mattphillips are you ok with this?

@WORMSS
Copy link

WORMSS commented Jun 28, 2021

would you need not.pass() also?

@WORMSS
Copy link

WORMSS commented Jun 28, 2021

I thought this sounded familiar

#204

#204 (comment)

https://github.com/keeganwitt/jest-extended/pull/26

Seems fail is currently a no-op according to the code?

@xamgore
Copy link
Contributor Author

xamgore commented Jun 28, 2021

would you need not.pass() also?

I would consider only fail to increase the probability of this PR getting merged.

@SimenB
Copy link
Member

SimenB commented Oct 6, 2021

Hmm, this isn't implemented according to the docs. Should we just remove it from the types?

https://github.com/jest-community/jest-extended#failmessage

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Landed #204, so this makes sense now. Thanks!

@SimenB SimenB merged commit c4961cd into jest-community:main Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants