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

feat: add satisfy alias #1172

Merged
merged 2 commits into from Apr 20, 2022
Merged

feat: add satisfy alias #1172

merged 2 commits into from Apr 20, 2022

Conversation

Shinigami92
Copy link
Contributor

@Shinigami92 Shinigami92 commented Apr 20, 2022

In Faker we want to use expect(...).to* assertions so we have consistent tests for everything.

Examples:

expect(...).toBe
expect(...).toContain
expect(...).toMatch
expect(...).toSatisfy

@netlify
Copy link

netlify bot commented Apr 20, 2022

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit dd01131
🔍 Latest deploy log https://app.netlify.com/sites/vitest-dev/deploys/626015d1baccca0008bc4941
😎 Deploy Preview https://deploy-preview-1172--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@antfu
Copy link
Member

antfu commented Apr 20, 2022

Can you add a simple test for it? Thanks

@Shinigami92
Copy link
Contributor Author

Can you add a simple test for it? Thanks

@antfu done ✅

@antfu antfu merged commit 7dbd837 into vitest-dev:main Apr 20, 2022
@Shinigami92 Shinigami92 deleted the to-satisfy branch April 20, 2022 14:21
@fardolieri
Copy link

fardolieri commented Apr 28, 2022

To me it seems like toSatisfy never even calls the given function and always results in a passing test. I wrote two test cases that show what I mean.

+ import { vi } from 'vitest'

describe.only('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)
  })
+
+  it('calls the function',() => {
+    const isOddMock = vi.fn(isOdd)
+    expect(isOddMock).not.toBeCalled()
+    expect(1).toSatisfy(isOddMock)
+    expect(isOddMock).toBeCalled()
+  })
+
+  it('fails when not satisfied',() => {
+    const shouldFailFn = () => expect(2).toSatisfy(isOdd)
+    expect(shouldFailFn).toThrow()
+  })
})

@fardolieri
Copy link

Here's a reproduction link
https://stackblitz.com/edit/vitest-dev-vitest-yap1ev?file=test/basic.test.ts

Do you want me to open an issue?

@Shinigami92
Copy link
Contributor Author

Here's a reproduction link stackblitz.com/edit/vitest-dev-vitest-yap1ev?file=test/basic.test.ts

Do you want me to open an issue?

You could also directly open a PR 🙂

@ST-DDT
Copy link
Contributor

ST-DDT commented May 21, 2022

@fardolieri : I created a PR with a fix: #1350

@fardolieri
Copy link

Awesome, thanks for stepping in!

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.

None yet

4 participants