Skip to content

Commit fe783a4

Browse files
committed
Merge pull request #7 from wmde/factoryfix
Fixed constructor assertion in parser/formatter factories
2 parents 875ec60 + c2c0f95 commit fe783a4

File tree

4 files changed

+5
-33
lines changed

4 files changed

+5
-33
lines changed

js/src/ValueFormatters/ValueFormatterFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
* @throws {Error} if the provided argument is not a valueFormatters.ValueFormatter constructor.
122122
*/
123123
function assertIsValueFormatterConstructor( Formatter ) {
124-
if( !$.isFunction( Formatter ) && Formatter.prototype instanceof vf.ValueFormatter ) {
124+
if( !( $.isFunction( Formatter ) && Formatter.prototype instanceof vf.ValueFormatter ) ) {
125125
throw new Error( 'Invalid ValueFormatter constructor' );
126126
}
127127
}

js/src/ValueParsers/ValueParserFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
* @throws {Error} if the provided argument is not a valueParsers.ValueParser constructor.
120120
*/
121121
function assertIsValueParserConstructor( Parser ) {
122-
if( !$.isFunction( Parser ) && Parser.prototype instanceof vp.ValueParser ) {
122+
if( !( $.isFunction( Parser ) && Parser.prototype instanceof vp.ValueParser ) ) {
123123
throw new Error( 'Invalid ValueParser constructor' );
124124
}
125125
}

js/tests/ValueFormatters/ValueFormatterFactory.tests.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,11 @@
6060
'Failed trying to register an invalid formatter constructor.'
6161
);
6262

63-
assert.throws(
64-
function() {
65-
formatterFactory.registerDataTypeFormatter( StringFormatter, 'invalid' );
66-
},
67-
'Failed trying to register a formatter with an invalid purpose.'
68-
);
69-
7063
formatterFactory.registerDataTypeFormatter( StringFormatter, stringType.getId() );
7164

7265
assert.throws(
7366
function() {
74-
formatterFactory.getFormatter( stringType.getId() );
67+
formatterFactory.getFormatter( stringType );
7568
},
7669
'Failed trying to get a formatter with an invalid purpose.'
7770
);
@@ -87,18 +80,11 @@
8780
'Failed trying to register an invalid formatter constructor.'
8881
);
8982

90-
assert.throws(
91-
function() {
92-
formatterFactory.registerDataValueFormatter( StringFormatter, 'invalid' );
93-
},
94-
'Failed trying to register a formatter with an invalid purpose.'
95-
);
96-
9783
formatterFactory.registerDataValueFormatter( StringFormatter, StringValue.TYPE );
9884

9985
assert.throws(
10086
function() {
101-
formatterFactory.getFormatter( StringValue.TYPE );
87+
formatterFactory.getFormatter( StringValue );
10288
},
10389
'Failed trying to get a formatter with an invalid purpose.'
10490
);

js/tests/ValueParsers/ValueParserFactory.tests.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,11 @@
6060
'Failed trying to register an invalid parser constructor.'
6161
);
6262

63-
assert.throws(
64-
function() {
65-
parserFactory.registerDataTypeParser( StringParser, 'invalid' );
66-
},
67-
'Failed trying to register a parser with an invalid purpose.'
68-
);
69-
7063
parserFactory.registerDataTypeParser( StringParser, stringType.getId() );
7164

7265
assert.throws(
7366
function() {
74-
parserFactory.getParser( StringValue );
67+
parserFactory.getParser( stringType );
7568
},
7669
'Failed trying to get a parser with an invalid purpose.'
7770
);
@@ -87,13 +80,6 @@
8780
'Failed trying to register an invalid parser constructor.'
8881
);
8982

90-
assert.throws(
91-
function() {
92-
parserFactory.registerDataValueParser( StringParser, 'invalid' );
93-
},
94-
'Failed trying to register a parser with an invalid purpose.'
95-
);
96-
9783
parserFactory.registerDataValueParser( StringParser, StringValue.TYPE );
9884

9985
assert.throws(

0 commit comments

Comments
 (0)