summaryrefslogtreecommitdiffstats
path: root/test/mock-errors.js
blob: a96de0bac8476180f19badeb48ee3ec76a79fc0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict'

const { test } = require('tap')
const { mockErrors, errors } = require('..')

test('mockErrors', (t) => {
  t.plan(1)

  t.test('MockNotMatchedError', t => {
    t.plan(2)

    t.test('should implement an UndiciError', t => {
      t.plan(4)

      const mockError = new mockErrors.MockNotMatchedError()
      t.type(mockError, errors.UndiciError)
      t.same(mockError.name, 'MockNotMatchedError')
      t.same(mockError.code, 'UND_MOCK_ERR_MOCK_NOT_MATCHED')
      t.same(mockError.message, 'The request does not match any registered mock dispatches')
    })

    t.test('should set a custom message', t => {
      t.plan(4)

      const mockError = new mockErrors.MockNotMatchedError('custom message')
      t.type(mockError, errors.UndiciError)
      t.same(mockError.name, 'MockNotMatchedError')
      t.same(mockError.code, 'UND_MOCK_ERR_MOCK_NOT_MATCHED')
      t.same(mockError.message, 'custom message')
    })
  })
})