Skip to content

Commit 31e54f6

Browse files
Fixed some tests in old Webkit browsers
1 parent 8d6a595 commit 31e54f6

2 files changed

Lines changed: 60 additions & 46 deletions

File tree

tests/fixtures/globals.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
window.expect = chai.expect;
1616
window.userAgent = {
1717
isNode: false,
18-
isBrowser: true,
19-
isPhantomJS: /PhantomJS/.test(navigator.userAgent)
18+
isBrowser: true
2019
};
2120
}
2221
else {

tests/specs/blank/blank.spec.js

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,66 @@
11
'use strict';
22

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+
});
1718

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) {
2353
expect(err).to.be.an.instanceOf(SyntaxError);
2454
expect(err.message).to.contain('Error parsing "');
2555
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));
5065
});
51-
}
66+
});

0 commit comments

Comments
 (0)