Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
add a test for pad
Browse files Browse the repository at this point in the history
  • Loading branch information
http://jneen.net/ committed Dec 2, 2019
1 parent 3621724 commit 4f1a474
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions utils/context.helpers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ const res = {
},
}

test('can pad an array', async () => {
await new Promise(resolve => contextMiddleware(req, res, resolve))

const pad = res.locals.pad

expect(pad([], 3)).toEqual([{}, {}, {}])
expect(pad([], 0)).toEqual([{}])
expect(pad(undefined, 3)).toEqual([{}, {}, {}])

expect(pad([1, 2, 3], 0)).toEqual([1, 2, 3])
expect(pad([1, 2, 3], 3)).toEqual([1, 2, 3])
expect(pad([1, 2, 3], 4)).toEqual([1, 2, 3, {}])

expect(pad(undefined, undefined)).toEqual([{}])
})

test('can traverse a data structure with no context', async () => {
await new Promise(resolve => contextMiddleware(req, res, resolve))

Expand Down

0 comments on commit 4f1a474

Please sign in to comment.