Skip to content

Commit

Permalink
test(on): cover method and path validation
Browse files Browse the repository at this point in the history
  • Loading branch information
hekike committed Nov 17, 2017
1 parent 094c0fa commit 3128d80
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/methods.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@ test('the router is an object with methods', t => {
t.is(typeof findMyWay.find, 'function')
})

test('on throws for invalid method', t => {
t.plan(1)
const findMyWay = FindMyWay()

t.throws(() => {
findMyWay.on('INVALID', '/a/b')
})
})

test('on throws for invalid path', t => {
t.plan(3)
const findMyWay = FindMyWay()

// Non string
t.throws(() => {
findMyWay.on('GET', 1)
})

// Empty
t.throws(() => {
findMyWay.on('GET', '')
})

// Doesn't start with / or *
t.throws(() => {
findMyWay.on('GET', 'invalid')
})
})

test('register a route', t => {
t.plan(1)
const findMyWay = FindMyWay()
Expand Down Expand Up @@ -145,6 +174,17 @@ test('deregister a route with multiple methods', t => {
t.notOk(findMyWay.find('POST', '/a'))
})

test('reset a router', t => {
t.plan(2)
const findMyWay = FindMyWay()

findMyWay.on(['GET', 'POST'], '/a', () => {})
findMyWay.reset()

t.notOk(findMyWay.find('GET', '/a'))
t.notOk(findMyWay.find('POST', '/a'))
})

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

Expand Down

0 comments on commit 3128d80

Please sign in to comment.