-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest.js
55 lines (47 loc) · 1.89 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
var assert = require('assert')
var nocache = require('./index.js')
function mockRequest() {
return {
data: {},
set: function (arg1, arg2) {
this.data[arg1] = arg2
}
}
}
describe ('X-Requested-With, Expires, and Cache-Control headers', function() {
var expected = {
'X-Requested-With': 'XMLHttpRequest',
'Expires': '-1',
'Cache-Control': 'no-cache,no-store,must-revalidate,max-age=-1,private'
}
it('should be set when using default exports', function() {
var results = nocache(mockRequest())
Object.keys(expected).forEach(function (header) {
assert(results.data[header] === expected[header], header + ' === ' + expected[header])
})
})
it('should be set when using withQueryStrings export', function() {
var results = nocache.withQueryStrings(mockRequest())
Object.keys(expected).forEach(function (header) {
assert(results.data[header] === expected[header], header + ' === ' + expected[header])
})
})
})
describe('withQueryStrings export', function () {
it('should set query string', function () {
var results = nocache.withQueryStrings(mockRequest())
assert(/^\d+$/.test(results._query[0]), 'random digits')
})
it('should append to existing query string', function () {
var request = mockRequest()
request._query = ['existing']
var results = nocache.withQueryStrings(request)
assert(/^existing&\d+$/.test(results._query[0]), 'append random digits')
})
})
it('works with IE (example - use with third-party "component-ie" package)', function () {
var isIE = true; // replace with: var isIE = require('ie')
var finalNocache = isIE ? nocache.withQueryStrings : nocache;
var results = finalNocache(mockRequest())
assert(/^\d+$/.test(results._query[0]), 'query string present when IE')
})