summaryrefslogtreecommitdiffstats
path: root/test/node-fetch/utils/chai-timeout.js
blob: 6838a4cc322c0c515e66ef06798c1417ddbd97f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const pTimeout = require('p-timeout')

module.exports = ({ Assertion }, utils) => {
  utils.addProperty(Assertion.prototype, 'timeout', async function () {
    let timeouted = false
    await pTimeout(this._obj, 150, () => {
      timeouted = true
    })
    return this.assert(
      timeouted,
      'expected promise to timeout but it was resolved',
      'expected promise not to timeout but it timed out'
    )
  })
}