Skip to content

Commit

Permalink
fix: incorrect behaviour of toBeDefined with not flag
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Dec 29, 2021
1 parent 577ff67 commit 97abcb9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/vitest/src/integrations/chai/jest-expect.ts
Expand Up @@ -194,6 +194,12 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
return this.be.null
})
def('toBeDefined', function() {
const negate = utils.flag(this, 'negate')
utils.flag(this, 'negate', false)

if (negate)
return this.be.undefined

return this.not.be.undefined
})
def('toBeInstanceOf', function(obj: any) {
Expand Down
3 changes: 3 additions & 0 deletions test/core/test/jest-expect.test.ts
Expand Up @@ -6,7 +6,10 @@ describe('jest-expect', () => {
it('basic', () => {
expect(1).toBe(1)
expect(null).toBeNull()
expect(1).not.toBeNull()
expect(null).toBeDefined()
expect(undefined).not.toBeDefined()
expect(undefined).toBeUndefined()
expect(null).not.toBeUndefined()
expect([]).toBeTruthy()
expect(0).toBeFalsy()
Expand Down

0 comments on commit 97abcb9

Please sign in to comment.