|
| 1 | +var expect = require('expect'); |
| 2 | +var HashLocation = require('../HashLocation'); |
| 3 | + |
| 4 | +describe('HashLocation.getCurrentPath', function() { |
| 5 | + |
| 6 | + //this test is needed because Firefox will pre-decode the value retrieved from |
| 7 | + //window.location.hash |
| 8 | + it('returns a properly decoded equivalent of what window.location.hash is set to', function() { |
| 9 | + window.location.hash = ''; |
| 10 | + expect(HashLocation.getCurrentPath()).toBe(''); |
| 11 | + |
| 12 | + window.location.hash = 'asdf'; |
| 13 | + expect(HashLocation.getCurrentPath()).toBe('asdf'); |
| 14 | + |
| 15 | + window.location.hash = 'test+spaces'; |
| 16 | + expect(HashLocation.getCurrentPath()).toBe('test spaces'); |
| 17 | + |
| 18 | + window.location.hash = 'first%2Fsecond'; |
| 19 | + expect(HashLocation.getCurrentPath()).toBe('first%2Fsecond'); |
| 20 | + |
| 21 | + window.location.hash = 'first/second'; |
| 22 | + expect(HashLocation.getCurrentPath()).toBe('first/second'); |
| 23 | + |
| 24 | + window.location.hash = 'first%252Fsecond'; |
| 25 | + expect(HashLocation.getCurrentPath()).toBe('first%2Fsecond'); |
| 26 | + |
| 27 | + //decodeURI doesn't handle lone percents |
| 28 | + window.location.hash = '%'; |
| 29 | + expect(function() { |
| 30 | + HashLocation.getCurrentPath(); |
| 31 | + }).toThrow(URIError); |
| 32 | + |
| 33 | + window.location.hash = '%25'; |
| 34 | + expect(HashLocation.getCurrentPath()).toBe('%'); |
| 35 | + |
| 36 | + window.location.hash = |
| 37 | + 'complicated+string/full%2Fof%3Fspecial%25chars%2520and%23escapes%E1%88%B4'; |
| 38 | + expect(HashLocation.getCurrentPath()) |
| 39 | + .toBe('complicated string/full%2Fof%3Fspecial%chars%20and%23escapesሴ'); |
| 40 | + }); |
| 41 | + |
| 42 | + afterEach(function() { |
| 43 | + window.location.hash = ''; |
| 44 | + }); |
| 45 | +}); |
0 commit comments