Skip to content

Commit

Permalink
Throw on null (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
sscotth authored and sdgluck committed Mar 29, 2017
1 parent c1241bf commit e635c74
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function mewt(target) {
}
}

if (!isA && typeof target !== 'object') {
if (typeof target !== 'object' || !target) {
throw new Error('mewt accepts array or object')
}

Expand Down
31 changes: 29 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,35 @@ test('exports a function', (t) => {
t.end()
})

test('throws without object or array', (t) => {
t.throws(() => mewt(), /accepts array or object/)
test('throws without object or array type', (t) => {
{
// undefined
t.throws(() => mewt(), /accepts array or object/)
}
{
// null
t.throws(() => mewt(null), /accepts array or object/)
}
{
// string
t.throws(() => mewt('foo'), /accepts array or object/)
}
{
// number
t.throws(() => mewt(123), /accepts array or object/)
}
{
// boolean
t.throws(() => mewt(true), /accepts array or object/)
}
{
// function
t.throws(() => mewt(() => {}), /accepts array or object/)
}
{
// symbol
t.throws(() => mewt(true), /accepts array or object/)
}
t.end()
})

Expand Down

0 comments on commit e635c74

Please sign in to comment.