| 1 |
var describe = QUnit.module; |
| 2 |
var it = QUnit.test; |
| 3 |
|
| 4 |
describe('parseURL', function() { |
| 5 |
var parseURL = Pretender.parseURL; |
| 6 |
|
| 7 |
function testUrl(url, expectedParts) { |
| 8 |
it('pathname, fullpath, protocol, hash and search are correct', function( |
| 9 |
assert |
| 10 |
) { |
| 11 |
var parts = parseURL(url); |
| 12 |
assert.ok(parts, 'Parts exist'); |
| 13 |
|
| 14 |
assert.equal( |
| 15 |
parts.protocol, |
| 16 |
expectedParts.protocol, |
| 17 |
'protocol should be "' + expectedParts.protocol + '"' |
| 18 |
); |
| 19 |
assert.equal( |
| 20 |
parts.pathname, |
| 21 |
expectedParts.pathname, |
| 22 |
'pathname should be "' + expectedParts.pathname + '"' |
| 23 |
); |
| 24 |
assert.equal( |
| 25 |
parts.host, |
| 26 |
expectedParts.host, |
| 27 |
'hostname is equal to "' + expectedParts.host + '"' |
| 28 |
); |
| 29 |
assert.equal( |
| 30 |
parts.search, |
| 31 |
expectedParts.search, |
| 32 |
'search should be "' + expectedParts.search + '"' |
| 33 |
); |
| 34 |
assert.equal( |
| 35 |
parts.hash, |
| 36 |
expectedParts.hash, |
| 37 |
'hash should be "' + expectedParts.search + '"' |
| 38 |
); |
| 39 |
assert.equal( |
| 40 |
parts.fullpath, |
| 41 |
expectedParts.fullpath, |
| 42 |
'fullpath should be "' + expectedParts.fullpath + '"' |
| 43 |
); |
| 44 |
}); |
| 45 |
} |
| 46 |
|
| 47 |
describe('relative HTTP URLs', function() { |
| 48 |
testUrl('/mock/my/request?test=abc#def', { |
| 49 |
protocol: 'http:', |
| 50 |
pathname: '/mock/my/request', |
| 51 |
host: window.location.host, |
| 52 |
search: '?test=abc', |
| 53 |
hash: '#def', |
| 54 |
fullpath: '/mock/my/request?test=abc#def', |
| 55 |
}); |
| 56 |
}); |
| 57 |
|
| 58 |
describe('same-origin absolute HTTP URLs', function() { |
| 59 |
testUrl( |
| 60 |
window.location.protocol + |
| 61 |
'//' + |
| 62 |
window.location.host + |
| 63 |
'/mock/my/request?test=abc#def', |
| 64 |
{ |
| 65 |
protocol: window.location.protocol, |
| 66 |
pathname: '/mock/my/request', |
| 67 |
host: window.location.host, |
| 68 |
search: '?test=abc', |
| 69 |
hash: '#def', |
| 70 |
fullpath: '/mock/my/request?test=abc#def', |
| 71 |
} |
| 72 |
); |
| 73 |
}); |
| 74 |
|
| 75 |
describe('cross-origin absolute HTTP URLs', function() { |
| 76 |
testUrl('https://www.yahoo.com/mock/my/request?test=abc', { |
| 77 |
protocol: 'https:', |
| 78 |
pathname: '/mock/my/request', |
| 79 |
host: 'www.yahoo.com', |
| 80 |
search: '?test=abc', |
| 81 |
hash: '', |
| 82 |
fullpath: '/mock/my/request?test=abc', |
| 83 |
}); |
| 84 |
}); |
| 85 |
}); |