Have ideas to improve npm?Join in the discussion! »

    chai-wait-for

    1.0.4 • Public • Published

    chai-wait-for

    CircleCI Coverage Status semantic-release Commitizen friendly npm version

    poll an assertion until it succeeds. Provides an especially clean syntax for working with some chai plugins like chai-fs, chai-webdriverio-async etc:

    await waitFor('#submittedMessage').to.have.text('Your changes have been saved!')

    Usage

    npm install --save-dev chai-wait-for
    // First, use the plugin
    const chai = require('chai')
    const chaiWaitFor = require('chai-wait-for')
    chai.use(chaiWaitFor)
    
    // Then create your `waitFor` with default options:
    const waitFor = chaiWaitFor.bindWaitFor({
      // If no assertion attempt succeeds before this time elapses (in milliseconds), the waitFor will fail.
      timeout: 5000,
      // If an assertion attempt fails, it will retry after this amount of time (in milliseconds)
      retryInterval: 100,
    })
    
    it('wait for something', async function () {
      this.timeout(10000)
    
      const myObj = { foo: 0 }
    
      setInterval(() => myObj.foo++, 1000)
    
      // Then use it just like you would expect():
      await waitFor(myObj).to.have.property('foo').that.equals(3)
    
      // You can also use a getter function:
      await waitFor(() => myObj.foo).to.equal(4)
    
      // If you need to override the defaults:
      waitFor.timeout(1000)(myObj).to.have.property('foo').that.equals(3)
      waitFor.retryInterval(500)(myObj).to.have.property('foo').that.equals(3)
    })

    Install

    npm i chai-wait-for

    DownloadsWeekly Downloads

    43

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    401 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar