Skip to content

Commit

Permalink
test: update interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 21, 2020
1 parent 90144fa commit dc2babf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
23 changes: 9 additions & 14 deletions package.json
Expand Up @@ -81,19 +81,14 @@
}
},
"lint-staged": {
"linters": {
"package.json": [
"finepack",
"git add"
],
"*.js": [
"prettier-standard",
"git add"
],
"*.md": [
"standard-markdown",
"git add"
]
}
"package.json": [
"finepack"
],
"*.js": [
"prettier-standard"
],
"*.md": [
"standard-markdown"
]
}
}
66 changes: 37 additions & 29 deletions test/index.js
Expand Up @@ -4,46 +4,54 @@ const test = require('ava')
const requireOneOf = require('..')

test('need to pass an array', t => {
const error = t.throws(() => {
requireOneOf('one')
})
t.is(error.message, 'Need to provide a collection')
t.throws(
() => {
requireOneOf('one')
},
{
message: 'Need to provide a collection'
}
)
})

test('one', t => {
const error = t.throws(() => {
requireOneOf(['one'])
}, TypeError)

t.is(
error.message,
"'one' not found as dependency. Please, install one of them."
t.throws(
() => {
requireOneOf(['one'])
},
{
instanceOf: TypeError,
message: "'one' not found as dependency. Please, install one of them."
}
)
})

test('more than one', t => {
const error = t.throws(() => {
requireOneOf(['one', 'two'])
}, TypeError)

t.is(
error.message,
"'one' or 'two' not found as dependency. Please, install one of them."
t.throws(
() => {
requireOneOf(['one', 'two'])
},
{
instanceOf: TypeError,
message: "'one' or 'two' not found as dependency. Please, install one of them."
}
)
})

test('custom error', t => {
const error = t.throws(() => {
requireOneOf(['one', 'two'], modules => {
return new TypeError(
`Uh, oh. ${modules
.map(m => `'${m}'`)
.join(',')} not found on dependencies`
)
})
}, TypeError)

t.is(error.message, "Uh, oh. 'one','two' not found on dependencies")
t.throws(
() => {
requireOneOf(['one', 'two'], modules => {
return new TypeError(
`Uh, oh. ${modules.map(m => `'${m}'`).join(',')} not found on dependencies`
)
})
},
{
instanceOf: TypeError,
message: "Uh, oh. 'one','two' not found on dependencies"
}
)
})

test('cache based on input', t => {
Expand Down

0 comments on commit dc2babf

Please sign in to comment.