Skip to content

Commit 40fec9d

Browse files
Change Error to TypeError and update tests
Change generic JavaScript `Error` object to more specific `TypeError`: - https://nodejs.org/api/errors.html#errors_class_typeerror - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError
1 parent f153f5b commit 40fec9d

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
*/
66
var domToReact = require('./lib/dom-to-react');
77
var htmlToDOM = (
8-
process.browser && process.title === 'browser' ?
8+
process.browser ?
99
require('./lib/html-to-dom-client') :
1010
require('./lib/html-to-dom-server')
1111
);
1212

1313
/**
1414
* Convert HTML string to React elements.
1515
*
16-
* @param {String} html - The HTML.
16+
* @param {String} html - The HTML string.
1717
* @param {Object} [options] - The additional options.
1818
* @param {Function} [options.replace] - The replace method.
1919
* @return {ReactElement|Array}
2020
*/
2121
function HTMLReactParser(html, options) {
2222
if (typeof html !== 'string') {
23-
throw new Error('`HTMLReactParser`: The first argument must be a string.');
23+
throw new TypeError('First argument must be a string');
2424
}
2525
return domToReact(htmlToDOM(html), options);
2626
}

lib/utilities.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
function camelCase(string) {
1010
if (typeof string !== 'string') {
11-
throw new Error('`camelCase`: first argument must be a string.');
11+
throw new TypeError('First argument must be a string');
1212
}
1313

1414
// hyphen found after first character
@@ -35,7 +35,7 @@ function camelCase(string) {
3535
*/
3636
function invertObject(obj, override) {
3737
if (typeof obj !== 'object' || !obj) { // null is an object
38-
throw new Error('`invert`: First argument must be an object.');
38+
throw new TypeError('First argument must be an object');
3939
}
4040

4141
var key;

test/html-to-react.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ describe('html-to-react', function() {
1919
*/
2020
describe('parser', function() {
2121

22-
it('throws an error if first argument is not a string', function() {
23-
assert.throws(function() { Parser(); });
22+
it('errors if first argument is not a string', function() {
23+
assert.throws(function() { Parser(); }, TypeError);
2424

2525
[undefined, null, {}, [], 42].forEach(function(arg) {
26-
assert.throws(function() { Parser(arg); });
26+
assert.throws(function() { Parser(arg); }, TypeError);
2727
});
2828
});
2929

30-
it('returns string if cannot be parsed to HTML', function() {
30+
it('returns original argument if it is unable to parse the HTML', function() {
3131
assert.equal(Parser('foo'), 'foo');
3232
});
3333

test/utilities.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ describe('utilties', function() {
2626
assert.equal(camelCase('CAMEL-CASE'), 'camelCase');
2727
});
2828

29-
it('throws an error if the first argument is invalid', function() {
29+
it('errors if the first argument is invalid', function() {
3030
[undefined, null, 1337, {}, []].forEach(function(parameter) {
31-
assert.throws(function() { camelCase(parameter); });
31+
assert.throws(function() { camelCase(parameter); }, TypeError);
3232
});
3333
});
3434
});
3535

3636
describe('`invertObject` helper', function() {
3737
var invertObject = utilities.invertObject;
3838

39-
it('throws an error if the first argument is invalid', function() {
39+
it('errors if the first argument is invalid', function() {
4040
[undefined, null, 'foo', 1337].forEach(function(parameter) {
41-
assert.throws(function() { invertObject(parameter); });
41+
assert.throws(function() { invertObject(parameter); }, TypeError);
4242
});
4343
});
4444

0 commit comments

Comments
 (0)