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

Assertions always pass #3

Closed
NaZaRKIN123 opened this issue Oct 17, 2024 · 5 comments
Closed

Assertions always pass #3

NaZaRKIN123 opened this issue Oct 17, 2024 · 5 comments

Comments

@NaZaRKIN123
Copy link

Hello,

I'm always getting all assertions passed which is not right.
I believe I'm doing all right. Please assist.

import { use } from 'chai'
import { After, Given, Then, When } from '@cucumber/cucumber'
import chai_wait_for, { bindWaitFor } from 'chai-wait-for'
use(chai_wait_for)
const waitFor = bindWaitFor({
  timeout: 5000,
  retryInterval: 100,
})

Given(/test/, function () {
  waitFor(() => {
    return { hello: 'abc' }
  }).to.deep.equal({ hello: 'def' })
  waitFor(() => 'abc').to.equal('def')
})
@jedwards1211
Copy link
Member

jedwards1211 commented Oct 18, 2024

Oh you'll always need to await your waitFor chains; they return a promise that resolves when the assertion succeeds, or rejects when it times out before success.

@jedwards1211
Copy link
Member

So:

Given(/test/, async function () {
  await waitFor(() => {
    return { hello: 'abc' }
  }).to.deep.equal({ hello: 'def' })
  await waitFor(() => 'abc').to.equal('def')
})

(I don't know for sure if Cucumber supports Promise-returning test functions, but seems like it does)

@jedwards1211
Copy link
Member

jedwards1211 commented Oct 18, 2024

(I guess the TS error you were seeing confused you. TypeScript was wrong in saying that await has no effect, because it didn't have the right type defs for this library. My fix for #2 should have made it so that TS will no longer complain about the await. If you're still seeing that error message I can reopen #2)

@NaZaRKIN123
Copy link
Author

Sorry for the confusion, I thought the fix would be the opposite. Thanks, now with await it works fine.

@jedwards1211
Copy link
Member

Okay great!

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

No branches or pull requests

2 participants