Skip to content

Commit

Permalink
Fix error code of AVV_ERR_ROOT_PLG_BOOTED (#206)
Browse files Browse the repository at this point in the history
* Fix error code of AVV_ERR_ROOT_PLG_BOOTED

* add unit tests

* fix

---------

Co-authored-by: Uzlopak <aras.abbasi@googlemail.com>
  • Loading branch information
mbelsky and Uzlopak authored Jun 23, 2023
1 parent 745cd0f commit 1971784
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = {
"Plugin must be a function or a promise. Received: '%s'"
),
AVV_ERR_ROOT_PLG_BOOTED: createError(
'AVV_ERR_PLUGIN_NOT_VALID',
'AVV_ERR_ROOT_PLG_BOOTED',
'Root plugin has already booted'
),
AVV_ERR_PARENT_PLG_LOADED: createError(
Expand Down
23 changes: 22 additions & 1 deletion test/errors.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'

const { test } = require('tap')
const { createError } = require('../lib/errors')
const errors = require('../lib/errors')
const createError = errors.createError

const expectedErrorName = 'AvvioError'

Expand Down Expand Up @@ -96,3 +97,23 @@ test('Create the error without the new keyword', t => {
t.equal(err.message, 'Not available')
t.equal(err.code, 'CODE')
})

test('Correct codes of AvvioErrors', t => {
const testcases = [
'AVV_ERR_EXPOSE_ALREADY_DEFINED',
'AVV_ERR_CALLBACK_NOT_FN',
'AVV_ERR_PLUGIN_NOT_VALID',
'AVV_ERR_ROOT_PLG_BOOTED',
'AVV_ERR_PARENT_PLG_LOADED',
'AVV_ERR_READY_TIMEOUT'
]

t.plan(testcases.length + 1)
// errors.js exposes errors and the createError fn
t.equal(testcases.length + 1, Object.keys(errors).length)

for (const testcase of testcases) {
const error = new errors[testcase]()
t.equal(error.code, testcase)
}
})

0 comments on commit 1971784

Please sign in to comment.