|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -// Browserify's HTTP module throws errors in PhantomJS when downloading zero-byte files |
4 | | -if (!userAgent.isPhantomJS) { |
5 | | - describe('Blank files', function() { |
6 | | - it('should throw an error if parsed as YAML', function(done) { |
7 | | - $RefParser |
8 | | - .parse(path.rel('specs/blank/blank.yaml')) |
9 | | - .then(helper.shouldNotGetCalled(done)) |
10 | | - .catch(function(err) { |
11 | | - expect(err).to.be.an.instanceOf(SyntaxError); |
12 | | - expect(err.message).to.contain('blank/blank.yaml" is not a valid JSON Schema'); |
13 | | - done(); |
14 | | - }) |
15 | | - .catch(helper.shouldNotGetCalled(done)); |
16 | | - }); |
| 3 | +describe('Blank files', function() { |
| 4 | + var windowOnError, testDone; |
| 5 | + |
| 6 | + beforeEach(function() { |
| 7 | + // Some old Webkit browsers throw an error when downloading zero-byte files. |
| 8 | + windowOnError = global.onerror; |
| 9 | + global.onerror = function() { |
| 10 | + testDone(); |
| 11 | + return true; |
| 12 | + } |
| 13 | + }); |
| 14 | + |
| 15 | + afterEach(function() { |
| 16 | + global.onerror = windowOnError; |
| 17 | + }); |
17 | 18 |
|
18 | | - it('should throw an error if parsed as JSON', function(done) { |
19 | | - $RefParser |
20 | | - .parse(path.rel('specs/blank/blank.yaml'), {allow: {yaml: false}}) |
21 | | - .then(helper.shouldNotGetCalled(done)) |
22 | | - .catch(function(err) { |
| 19 | + it('should throw an error if parsed as YAML', function(done) { |
| 20 | + testDone = done; |
| 21 | + $RefParser |
| 22 | + .parse(path.rel('specs/blank/blank.yaml')) |
| 23 | + .then(helper.shouldNotGetCalled(done)) |
| 24 | + .catch(function(err) { |
| 25 | + expect(err).to.be.an.instanceOf(SyntaxError); |
| 26 | + expect(err.message).to.contain('blank/blank.yaml" is not a valid JSON Schema'); |
| 27 | + done(); |
| 28 | + }) |
| 29 | + .catch(helper.shouldNotGetCalled(done)); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should throw an error if parsed as JSON', function(done) { |
| 33 | + testDone = done; |
| 34 | + $RefParser |
| 35 | + .parse(path.rel('specs/blank/blank.yaml'), {allow: {yaml: false}}) |
| 36 | + .then(helper.shouldNotGetCalled(done)) |
| 37 | + .catch(function(err) { |
| 38 | + expect(err).to.be.an.instanceOf(SyntaxError); |
| 39 | + expect(err.message).to.contain('Error parsing "'); |
| 40 | + expect(err.message).to.contain('blank/blank.yaml"'); |
| 41 | + done(); |
| 42 | + }) |
| 43 | + .catch(helper.shouldNotGetCalled(done)); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should throw an error if "options.allow.empty" is disabled', function(done) { |
| 47 | + testDone = done; |
| 48 | + $RefParser |
| 49 | + .parse(path.rel('specs/blank/blank.yaml'), {allow: {empty: false}}) |
| 50 | + .then(helper.shouldNotGetCalled(done)) |
| 51 | + .catch(function(err) { |
| 52 | + if (userAgent.isNode) { |
23 | 53 | expect(err).to.be.an.instanceOf(SyntaxError); |
24 | 54 | expect(err.message).to.contain('Error parsing "'); |
25 | 55 | expect(err.message).to.contain('blank/blank.yaml"'); |
26 | | - done(); |
27 | | - }) |
28 | | - .catch(helper.shouldNotGetCalled(done)); |
29 | | - }); |
30 | | - |
31 | | - it('should throw an error if "options.allow.empty" is disabled', function(done) { |
32 | | - $RefParser |
33 | | - .parse(path.rel('specs/blank/blank.yaml'), {allow: {empty: false}}) |
34 | | - .then(helper.shouldNotGetCalled(done)) |
35 | | - .catch(function(err) { |
36 | | - if (userAgent.isNode) { |
37 | | - expect(err).to.be.an.instanceOf(SyntaxError); |
38 | | - expect(err.message).to.contain('Error parsing "'); |
39 | | - expect(err.message).to.contain('blank/blank.yaml"'); |
40 | | - expect(err.message).to.contain('Parsed value is empty'); |
41 | | - } |
42 | | - else { |
43 | | - expect(err).to.be.an.instanceOf(Error); |
44 | | - expect(err.message).to.contain('HTTP 204: No Content'); |
45 | | - } |
46 | | - done(); |
47 | | - }) |
48 | | - .catch(helper.shouldNotGetCalled(done)); |
49 | | - }); |
| 56 | + expect(err.message).to.contain('Parsed value is empty'); |
| 57 | + } |
| 58 | + else { |
| 59 | + expect(err).to.be.an.instanceOf(Error); |
| 60 | + expect(err.message).to.contain('HTTP 204: No Content'); |
| 61 | + } |
| 62 | + done(); |
| 63 | + }) |
| 64 | + .catch(helper.shouldNotGetCalled(done)); |
50 | 65 | }); |
51 | | -} |
| 66 | +}); |
0 commit comments