TimeoutStreamTests.js 639 B

12345678910111213141516171819202122
  1. const { expect } = require('chai')
  2. const { TimeoutStream, AbortError } = require('../../index')
  3. describe('TimeoutStream', function () {
  4. it('should emit an error if the stream times out', function (done) {
  5. const timeout = 10
  6. const timeoutStream = new TimeoutStream(timeout)
  7. timeoutStream.on('error', err => {
  8. expect(err).to.be.an.instanceOf(AbortError)
  9. done()
  10. })
  11. })
  12. it('should not emit an error if the stream does not time out', function (done) {
  13. const timeout = 100
  14. const timeoutStream = new TimeoutStream(timeout)
  15. setTimeout(() => {
  16. timeoutStream.end()
  17. done()
  18. }, 1)
  19. })
  20. })