Skip to content
This repository was archived by the owner on Feb 9, 2018. It is now read-only.

Commit 70ee3d0

Browse files
committed
assert.throw => assert.throws, use regexp to match messages
1 parent 7e45ed1 commit 70ee3d0

10 files changed

+90
-78
lines changed

test/js/computed-style-property-map.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ suite('Computed StylePropertyMap', function() {
2222
document.body.removeChild(this.element);
2323
});
2424

25+
var lemonNotSupportedErr = /^lemon is not a supported CSS property$/;
26+
2527
test('get method throws a TypeError if the property is not supported', function() {
2628
var computedStyleMap = getComputedStyleMap(this.element);
2729

28-
assert.throw(function() {computedStyleMap.get('lemon')}, TypeError,
29-
'lemon is not a supported CSS property');
30+
assert.throws(function() {computedStyleMap.get('lemon')}, TypeError, lemonNotSupportedErr);
3031
});
3132

3233

@@ -87,8 +88,7 @@ suite('Computed StylePropertyMap', function() {
8788
test('getAll method throws a TypeError if the property is not supported', function() {
8889
var computedStyleMap = getComputedStyleMap(this.element);
8990

90-
assert.throw(function() {computedStyleMap.getAll('lemon')}, TypeError,
91-
'lemon is not a supported CSS property');
91+
assert.throws(function() {computedStyleMap.getAll('lemon')}, TypeError, lemonNotSupportedErr);
9292
});
9393

9494
test('getting an unsupported but valid property returns a base CSSStyleValue', function() {

test/js/css-angle-value.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,24 @@ test('CSSAngleValue constructor works for valid arguments', function() {
3939
});
4040

4141
test('Wrong number of arguments throws', function() {
42-
assert.throw(function() { new CSSAngleValue(); }, TypeError, 'Must specify an angle and a unit');
43-
assert.throw(function() { new CSSAngleValue(5); }, TypeError, 'Must specify an angle and a unit');
44-
assert.throw(function() { new CSSAngleValue(5, 5, 5); }, TypeError, 'Must specify an angle and a unit');
42+
var specifyErr = /^Must specify an angle and a unit$/;
43+
assert.throws(function() { new CSSAngleValue(); }, TypeError, specifyErr);
44+
assert.throws(function() { new CSSAngleValue(5); }, TypeError, specifyErr);
45+
assert.throws(function() { new CSSAngleValue(5, 5, 5); }, TypeError, specifyErr);
4546
});
4647

4748
test('Value not a number throws', function() {
48-
assert.throw(function() { new CSSAngleValue('foo', 'deg'); }, TypeError, 'Value must be a number');
49-
assert.throw(function() { new CSSAngleValue({}, 'deg'); }, TypeError, 'Value must be a number');
50-
assert.throw(function() { new CSSAngleValue(undefined, 'deg'); }, TypeError, 'Value must be a number');
49+
var numberErr = /^Value must be a number$/;
50+
assert.throws(function() { new CSSAngleValue('foo', 'deg'); }, TypeError, numberErr);
51+
assert.throws(function() { new CSSAngleValue({}, 'deg'); }, TypeError, numberErr);
52+
assert.throws(function() { new CSSAngleValue(undefined, 'deg'); }, TypeError, numberErr);
5153
});
5254

5355
test('Invalid unit throws', function() {
54-
assert.throw(function() { new CSSAngleValue(5, 'asdfa'); }, TypeError, 'Invalid unit type');
55-
assert.throw(function() { new CSSAngleValue(5, {}); }, TypeError, 'Invalid unit type');
56-
assert.throw(function() { new CSSAngleValue(5, 5); }, TypeError, 'Invalid unit type');
56+
var unitErr = /^Invalid unit type$/;
57+
assert.throws(function() { new CSSAngleValue(5, 'asdfa'); }, TypeError, unitErr);
58+
assert.throws(function() { new CSSAngleValue(5, {}); }, TypeError, unitErr);
59+
assert.throws(function() { new CSSAngleValue(5, 5); }, TypeError, unitErr);
5760
});
5861

5962
test('Conversions when specified as degrees', function() {

test/js/css-color-value.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,33 @@
1515
suite('CSSColorValue', function() {
1616
test('Constructor should throw an error if r, g and b are not integers', function() {
1717
assert.doesNotThrow(function() {new CSSColorValue(0, 50, 255);});
18-
assert.throw(function() {new CSSColorValue(0, "lemon", 50);}, TypeError,
19-
'r, g and b must be integers.');
20-
assert.throw(function() {new CSSColorValue(0, 50, null);}, TypeError,
21-
'r, g and b must be integers.');
22-
assert.throw(function() {new CSSColorValue(50.5, 20, 50);}, TypeError,
23-
'r, g and b must be integers.');
18+
19+
var integerErr = /^r, g and b must be integers\.$/;
20+
assert.throws(function() {new CSSColorValue(0, "lemon", 50);}, TypeError, integerErr);
21+
assert.throws(function() {new CSSColorValue(0, 50, null);}, TypeError, integerErr);
22+
assert.throws(function() {new CSSColorValue(50.5, 20, 50);}, TypeError, integerErr);
2423
});
2524

2625
test('Constructor should throw an error if r, g and b are not between 0 and 255', function() {
27-
assert.throw(function() {new CSSColorValue(0, -1, 50, 0);}, TypeError,
28-
'r, g and b must be integers between 0 and 255.');
29-
assert.throw(function() {new CSSColorValue(0, 255, 256);}, TypeError,
30-
'r, g and b must be integers between 0 and 255.');
31-
assert.throw(function() {new CSSColorValue(300, 255, 256);}, TypeError,
32-
'r, g and b must be integers between 0 and 255.');
26+
var rangeErr = /^r, g and b must be integers between 0 and 255\.$/;
27+
assert.throws(function() {new CSSColorValue(0, -1, 50, 0);}, TypeError, rangeErr);
28+
assert.throws(function() {new CSSColorValue(0, 255, 256);}, TypeError, rangeErr);
29+
assert.throws(function() {new CSSColorValue(300, 255, 256);}, TypeError, rangeErr);
3330
});
3431

3532
test('Constructor should throw an error if a is not a number', function() {
36-
assert.throw(function() {new CSSColorValue(0, 50, 50, "lemon");}, TypeError,
37-
'a must be a number.');
38-
assert.throw(function() {new CSSColorValue(0, 50, 50, null);}, TypeError,
39-
'a must be a number.');
33+
var numberErr = /^a must be a number\.$/;
34+
assert.throws(function() {new CSSColorValue(0, 50, 50, "lemon");}, TypeError, numberErr);
35+
assert.throws(function() {new CSSColorValue(0, 50, 50, null);}, TypeError, numberErr);
4036
});
4137

4238
test('Constructor should throw an error if a is not between 0 and 1', function() {
4339
assert.doesNotThrow(function() {new CSSColorValue(0, 50, 255, 1);});
4440
assert.doesNotThrow(function() {new CSSColorValue(0, 50, 255, 0);});
45-
assert.throw(function() {new CSSColorValue(0, 50, 50, -0.1);}, TypeError,
46-
'a must be a number between 0 and 1.');
47-
assert.throw(function() {new CSSColorValue(0, 50, 255, 1.2);}, TypeError,
48-
'a must be a number between 0 and 1.');
41+
42+
var rangeErr = /^a must be a number between 0 and 1\.$/;
43+
assert.throws(function() {new CSSColorValue(0, 50, 50, -0.1);}, TypeError, rangeErr);
44+
assert.throws(function() {new CSSColorValue(0, 50, 255, 1.2);}, TypeError, rangeErr);
4945
});
5046

5147
test('cssText should return rgb(<number>,<number>,<number>) if alpha ' +

test/js/css-image-value.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
suite('CSSImageValue', function() {
1616
test('Can only create internal CSSImageValue object', function() {
17-
assert.throw(function() { new CSSImageValue(new Image()); }, TypeError, "Can\'t instantiate CSSImageValue");
17+
var instantiateErr = /^Can't instantiate CSSImageValue$/;
18+
assert.throws(function() { new CSSImageValue(new Image()); }, TypeError, instantiateErr);
1819
assert.doesNotThrow(function() { new typedOM.internal.CSSImageValue(new Image()); });
1920
});
2021

@@ -25,11 +26,12 @@ suite('CSSImageValue', function() {
2526
});
2627

2728
test('CSSImageValue only accepts Image object', function() {
28-
assert.throw(function() { new typedOM.internal.CSSImageValue(); }, TypeError, "image must be an Image object");
29-
assert.throw(function() { new typedOM.internal.CSSImageValue(1); }, TypeError, "image must be an Image object");
30-
assert.throw(function() { new typedOM.internal.CSSImageValue("abc"); }, TypeError, "image must be an Image object");
31-
assert.throw(function() { new typedOM.internal.CSSImageValue([]); }, TypeError, "image must be an Image object");
32-
assert.throw(function() { new typedOM.internal.CSSImageValue({ x: 1, y: 2 }); }, TypeError, "image must be an Image object");
29+
var imageErr = /image must be an Image object/;
30+
assert.throws(function() { new typedOM.internal.CSSImageValue(); }, TypeError, imageErr);
31+
assert.throws(function() { new typedOM.internal.CSSImageValue(1); }, TypeError, imageErr);
32+
assert.throws(function() { new typedOM.internal.CSSImageValue("abc"); }, TypeError, imageErr);
33+
assert.throws(function() { new typedOM.internal.CSSImageValue([]); }, TypeError, imageErr);
34+
assert.throws(function() { new typedOM.internal.CSSImageValue({ x: 1, y: 2 }); }, TypeError, imageErr);
3335
});
3436

3537
test('CSSImageValue\'s state and dimensions are correct before and after loaded', function(done) {

test/js/css-resource-value.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ suite('CSSResourceValue', function() {
1919
});
2020

2121
test('Constructor only accepts a string of CSSResourceState', function() {
22-
assert.throw(function() { new CSSResourceValue(); }, TypeError, 'State of a CSSResourceValue must be one of CSSResourceState');
23-
assert.throw(function() { new CSSResourceValue(1); }, TypeError, 'State of a CSSResourceValue must be one of CSSResourceState');
24-
assert.throw(function() { new CSSResourceValue([1, 2]); }, TypeError, 'State of a CSSResourceValue must be one of CSSResourceState');
25-
assert.throw(function() { new CSSResourceValue('undefined'); }, TypeError, 'State of a CSSResourceValue must be one of CSSResourceState');
22+
var stateErr = /^State of a CSSResourceValue must be one of CSSResourceState$/;
23+
assert.throws(function() { new CSSResourceValue(); }, TypeError, stateErr);
24+
assert.throws(function() { new CSSResourceValue(1); }, TypeError, stateErr);
25+
assert.throws(function() { new CSSResourceValue([1, 2]); }, TypeError, stateErr);
26+
assert.throws(function() { new CSSResourceValue('undefined'); }, TypeError, stateErr);
2627
});
2728
});

test/js/css-unparsed-value.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@ suite('CSSUnparsedValue', function() {
1919
});
2020

2121
test('Values not an array throws', function() {
22-
assert.throw(function() { new CSSUnparsedValue(1); }, TypeError,
23-
'CSSUnparsedValue should be an array of string or CSSVariableReferenceValue');
24-
assert.throw(function() { new CSSUnparsedValue("123"); }, TypeError,
25-
'CSSUnparsedValue should be an array of string or CSSVariableReferenceValue');
26-
assert.throw(function() { new CSSUnparsedValue({ h:10, w:5, d:4, t:"5" });}, TypeError,
27-
'CSSUnparsedValue should be an array of string or CSSVariableReferenceValue');
22+
var valueErr = /^CSSUnparsedValue should be an array of string or CSSVariableReferenceValue$/;
23+
assert.throws(function() { new CSSUnparsedValue(1); }, TypeError, valueErr);
24+
assert.throws(function() { new CSSUnparsedValue("123"); }, TypeError, valueErr);
25+
assert.throws(function() { new CSSUnparsedValue({ h:10, w:5, d:4, t:"5" });}, TypeError, valueErr);
2826
});
2927

3028
test('Values not an array of string or CSSVariableReferenceValue throws', function() {
31-
assert.throw(function() { new CSSUnparsedValue([1]); }, TypeError,
32-
"CSSUnparsedValue\'s elements should be string or CSSVariableReferenceValue");
33-
assert.throw(function() { new CSSUnparsedValue(["1234", "2342", 1]); }, TypeError,
34-
"CSSUnparsedValue\'s elements should be string or CSSVariableReferenceValue");
29+
var valueErr = /^CSSUnparsedValue's elements should be string or CSSVariableReferenceValue$/;
30+
assert.throws(function() { new CSSUnparsedValue([1]); }, TypeError, valueErr);
31+
assert.throws(function() { new CSSUnparsedValue(["1234", "2342", 1]); }, TypeError, valueErr);
3532
});
3633

3734
test('Using spread operator on CSSUnparsedValue results in the correct values', function() {

test/js/css-url-image-value.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ suite('CSSURLImageValue', function() {
2121
});
2222

2323
test('CSSURLImageValue only accepts string', function() {
24-
assert.throw(function() { new CSSURLImageValue(); }, TypeError, "URL must be a string");
25-
assert.throw(function() { new CSSURLImageValue([]); }, TypeError, "URL must be a string");
26-
assert.throw(function() { new CSSURLImageValue(1); }, TypeError, "URL must be a string");
24+
var stringErr = /^URL must be a string$/;
25+
assert.throws(function() { new CSSURLImageValue(); }, TypeError, stringErr);
26+
assert.throws(function() { new CSSURLImageValue([]); }, TypeError, stringErr);
27+
assert.throws(function() { new CSSURLImageValue(1); }, TypeError, stringErr);
2728
assert.doesNotThrow(function() { new CSSURLImageValue(''); });
2829
});
2930

test/js/css-variable-reference-value.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ suite('CSSVariableReferenceValue', function() {
2626
});
2727

2828
test('Constructor only accepts a string and a CSSUnparsedValue', function() {
29-
assert.throw(function() { new CSSVariableReferenceValue(); }, TypeError, 'CSSVariableReferenceValue constructor should get two parameters');
30-
assert.throw(function() { new CSSVariableReferenceValue("123"); }, TypeError, 'CSSVariableReferenceValue constructor should get two parameters');
31-
assert.throw(function() { new CSSVariableReferenceValue(1234, 1234); }, TypeError, 'Variable of CSSVariableReferenceValue must be a string');
32-
assert.throw(function() { new CSSVariableReferenceValue(["1"], 1234); }, TypeError, 'Variable of CSSVariableReferenceValue must be a string');
33-
assert.throw(function() { new CSSVariableReferenceValue("123", 1234); }, TypeError, 'Fallback of CSSVariableReferenceValue must be a CSSUnparsedValue');
29+
var paramsErr = /^CSSVariableReferenceValue constructor should get two parameters$/;
30+
assert.throws(function() { new CSSVariableReferenceValue(); }, TypeError, paramsErr);
31+
assert.throws(function() { new CSSVariableReferenceValue("123"); }, TypeError, paramsErr);
32+
33+
var stringErr = /^Variable of CSSVariableReferenceValue must be a string$/;
34+
assert.throws(function() { new CSSVariableReferenceValue(1234, 1234); }, TypeError, stringErr);
35+
assert.throws(function() { new CSSVariableReferenceValue(["1"], 1234); }, TypeError, stringErr);
36+
37+
var fallbackErr = /^Fallback of CSSVariableReferenceValue must be a CSSUnparsedValue$/;
38+
assert.throws(function() { new CSSVariableReferenceValue("123", 1234); }, TypeError, fallbackErr);
3439
});
3540

3641
test('CSSVariableReferenceValue can have undefined fallback', function() {

test/js/inline-style-property-map.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,38 @@ suite('Inline StylePropertyMap', function() {
5757
var inlineStyleMap = this.element.styleMap();
5858
var valueSequence = [new CSSSimpleLength(3, 'px'), new CSSSimpleLength(6, 'px')];
5959

60-
assert.throw(function() {inlineStyleMap.set('height', valueSequence)}, TypeError, 'height does not support sequences of styleValues');
60+
assert.throws(function() {inlineStyleMap.set('height', valueSequence)}, TypeError,
61+
/^height does not support sequences of styleValues$/);
6162
});
6263

6364
test('Set should throw a TypeError if a non CSSKeywordValue CSSStyleValue unsupported by the CSS style property is set', function() {
6465
var inlineStyleMap = this.element.styleMap();
6566
var numberValue = new CSSNumberValue(42);
6667

67-
assert.throw(function() {inlineStyleMap.set('height', numberValue)}, TypeError);
68+
assert.throws(function() {inlineStyleMap.set('height', numberValue)}, TypeError,
69+
/^height does not take values of type CSSNumberValue$/);
6870
});
6971

7072
test('Set should throw a TypeError if a CSSKeywordValue unsupported by the CSS style property is set ', function() {
7173
var inlineStyleMap = this.element.styleMap();
7274
var keyword = new CSSKeywordValue('lemon');
7375

74-
assert.throw(function() {inlineStyleMap.set('height', keyword)}, 'height does not take the keyword lemon');
76+
assert.throws(function() {inlineStyleMap.set('height', keyword)},
77+
/^height does not take the keyword lemon$/);
7578
});
7679

7780
test('Set should throw a TypeError if a non CSSStyleValue is inputed into the function', function() {
7881
var inlineStyleMap = this.element.styleMap();
7982

80-
assert.throw(function() {inlineStyleMap.set('height', 4)}, TypeError);
83+
assert.throws(function() {inlineStyleMap.set('height', 4)}, TypeError,
84+
/^height does not take values of type Number$/);
8185
});
8286

8387
test('Set should throw a TypeError if an unsupported property is inputed into the function', function() {
8488
var inlineStyleMap = this.element.styleMap();
8589

86-
assert.throw(function() {inlineStyleMap.set('lemons', new CSSSimpleLength(3, 'px'))}, TypeError);
90+
assert.throws(function() {inlineStyleMap.set('lemons', new CSSSimpleLength(3, 'px'))}, TypeError,
91+
/^Cannot set lemons because it is not a supported CSS property$/);
8792
});
8893

8994
test('The delete method clears a given property', function() {
@@ -97,7 +102,8 @@ suite('Inline StylePropertyMap', function() {
97102
test('The delete method should throw a TypeError if an unsupported property', function() {
98103
var inlineStyleMap = this.element.styleMap();
99104

100-
assert.throw(function() {inlineStyleMap.delete('lemons')}, TypeError);
105+
assert.throws(function() {inlineStyleMap.delete('lemons')}, TypeError,
106+
/^Cannot delete lemons because it is not a supported CSS property$/);
101107
});
102108

103109
test('The has method will return true if the valid CSS property input has been assigned a value' +
@@ -111,7 +117,8 @@ suite('Inline StylePropertyMap', function() {
111117
test('The has method should throw a TypeError if an unsupported property', function() {
112118
var inlineStyleMap = this.element.styleMap();
113119

114-
assert.throw(function() {inlineStyleMap.has('lemons')}, TypeError);
120+
assert.throws(function() {inlineStyleMap.has('lemons')}, TypeError,
121+
/^Cannot use has method for lemons because it is not a supported CSS property$/);
115122
});
116123

117124
test('The append method should successfully append a supported CSSStyleValue to a property ' +
@@ -149,29 +156,29 @@ suite('Inline StylePropertyMap', function() {
149156
var valueSequence = [new CSSNumberValue(4), new CSSNumberValue(5), new CSSSimpleLength(3, 'px'), new CSSKeywordValue('infinite')];
150157
this.element.style['animation-iteration-count'] = 'infinite, 2, 5';
151158

152-
assert.throw(function() {inlineStyleMap.append('animation-iteration-count', valueSequence)}, TypeError,
153-
'animation-iteration-count does not take values of type CSSSimpleLength');
159+
assert.throws(function() {inlineStyleMap.append('animation-iteration-count', valueSequence)}, TypeError,
160+
/^animation-iteration-count does not take values of type CSSSimpleLength$/);
154161
});
155162

156163
test('The append method should throw a TypeError when an unsupported CSS property is entered', function() {
157164
var inlineStyleMap = this.element.styleMap();
158165

159-
assert.throw(function() {inlineStyleMap.append('lemon', new CSSNumberValue(4))}, TypeError,
160-
'lemon is not a supported CSS property');
166+
assert.throws(function() {inlineStyleMap.append('lemon', new CSSNumberValue(4))}, TypeError,
167+
/^lemon is not a supported CSS property$/);
161168
});
162169

163170
test('The append method should throw a TypeError when a CSS property that does not support list values is entered', function() {
164171
var inlineStyleMap = this.element.styleMap();
165172

166-
assert.throw(function() {inlineStyleMap.append('height', new CSSNumberValue(4))}, TypeError,
167-
'height does not support sequences of styleValues');
173+
assert.throws(function() {inlineStyleMap.append('height', new CSSNumberValue(4))}, TypeError,
174+
/^height does not support sequences of styleValues$/);
168175
});
169176

170177
test('The append method should throw a TypeError when null is entered as the value', function() {
171178
var inlineStyleMap = this.element.styleMap();
172179

173-
assert.throw(function() {inlineStyleMap.append('animation-iteration-count', null)}, TypeError,
174-
'null cannot be appended to CSS properties');
180+
assert.throws(function() {inlineStyleMap.append('animation-iteration-count', null)}, TypeError,
181+
/^null cannot be appended to CSS properties$/);
175182
});
176183

177184
test('getProperties returns an ordered list of properties that have been set on an element', function() {

test/js/property-dictionary.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ suite('PropertyDictionary', function() {
7777

7878
test('listValueSeparator method should throw a TypeError if the property entered does not support list values', function() {
7979

80-
assert.throw(function () {cssPropertyDictionary.listValueSeparator('height')}, TypeError);
80+
assert.throws(function () {cssPropertyDictionary.listValueSeparator('height')}, TypeError, /^height does not support lists of CSSStyleValues$/);
8181
});
8282

8383
test('supportedStyleValues should return an array of constructors for all CSSStyleValue types accepted by that property', function() {
@@ -88,6 +88,6 @@ suite('PropertyDictionary', function() {
8888

8989
test('supportedStyleValues should throw a type error for unsupported properties', function() {
9090

91-
assert.throw(function () {cssPropertyDictionary.supportedStyleValues('lemon');}, TypeError);
91+
assert.throws(function () {cssPropertyDictionary.supportedStyleValues('lemon');}, TypeError, /^lemon is not a supported CSS property$/);
9292
});
9393
});

0 commit comments

Comments
 (0)