Skip to content

Commit

Permalink
feat: add satisfy alias (#1172)
Browse files Browse the repository at this point in the history
* feat: add satisfy alias

* test: add toSatisfy test
  • Loading branch information
Shinigami92 committed Apr 20, 2022
1 parent c2e98ef commit 7dbd837
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/vitest/src/index.ts
Expand Up @@ -119,6 +119,7 @@ declare global {
lastReturnedWith<E>(value: E): void
toHaveNthReturnedWith<E>(nthCall: number, value: E): void
nthReturnedWith<E>(nthCall: number, value: E): void
toSatisfy<E>(matcher: (value: E) => boolean, message?: string): void
}

// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/integrations/chai/jest-expect.ts
Expand Up @@ -536,6 +536,9 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
callResult,
)
})
def('toSatisfy', function() {
return this.be.satisfy
})

utils.addProperty(chai.Assertion.prototype, 'resolves', function __VITEST_RESOLVES__(this: any) {
utils.flag(this, 'promise', 'resolves')
Expand Down
12 changes: 12 additions & 0 deletions test/core/test/jest-expect.test.ts
Expand Up @@ -419,6 +419,18 @@ describe('toBeTypeOf()', () => {
})
})

describe('toSatisfy()',() => {
const isOdd = (value: number) => value % 2 !== 0

it('pass with 0',() => {
expect(1).toSatisfy(isOdd)
})

it('pass with negotiation',() => {
expect(2).not.toSatisfy(isOdd)
})
})

describe('async expect', () => {
it('resolves', async() => {
await expect((async() => 'true')()).resolves.toBe('true')
Expand Down

0 comments on commit 7dbd837

Please sign in to comment.