Skip to content

Commit

Permalink
feat(readCache): add test for stale value
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanebachelier committed Mar 6, 2016
1 parent c89f884 commit 2bec9e7
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/read-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,35 @@ test('readCache cache miss', t => {
})
})
})

test('readCache cache stale', t => {
const req = new Request()

const value = {
expires: -1,
data: {
body: {
responseType: 'text',
responseText: 'Hello world',
status: 200,
statusText: 'OK'
},
headers: 'content-type: text/plain'
}
}

return new Promise(resolve => {
readCache(req, log)(value)
.then(res => {
t.error('response should not be defined on cache stale')

resolve()
})
.catch(err => {
// add test in case of error
t.equals(err.reason, 'cache-stale', 'reading a stale value from cache should throw')

resolve()
})
})
})

0 comments on commit 2bec9e7

Please sign in to comment.