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

Commit db968dc

Browse files
committed
fix: error test cases to be more simple
1 parent 3d887a9 commit db968dc

33 files changed

+239
-724
lines changed

test/AnalyserNode.js

+11-33
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ describe("AnalyserNode", function() {
1515

1616
assert.throws(function() {
1717
return new global.AnalyserNode();
18-
}, function(e) {
19-
return e instanceof TypeError && /Illegal constructor/.test(e.message);
20-
});
18+
}, TypeError);
2119
});
2220
});
2321

@@ -53,9 +51,7 @@ describe("AnalyserNode", function() {
5351

5452
assert.throws(function() {
5553
node.fftSize = 4096;
56-
}, function(e) {
57-
return e instanceof TypeError && /should be an enum/.test(e.message);
58-
});
54+
}, TypeError);
5955
});
6056
});
6157

@@ -73,9 +69,7 @@ describe("AnalyserNode", function() {
7369

7470
assert.throws(function() {
7571
node.frequencyBinCount = 256;
76-
}, function(e) {
77-
return e instanceof TypeError && /readonly/.test(e.message);
78-
});
72+
}, TypeError);
7973
});
8074
});
8175

@@ -93,9 +87,7 @@ describe("AnalyserNode", function() {
9387

9488
assert.throws(function() {
9589
node.minDecibels = "INVALID";
96-
}, function(e) {
97-
return e instanceof TypeError && /should be a number/.test(e.message);
98-
});
90+
}, TypeError);
9991
});
10092
});
10193

@@ -113,9 +105,7 @@ describe("AnalyserNode", function() {
113105

114106
assert.throws(function() {
115107
node.maxDecibels = "INVALID";
116-
}, function(e) {
117-
return e instanceof TypeError && /should be a number/.test(e.message);
118-
});
108+
}, TypeError);
119109
});
120110
});
121111

@@ -133,9 +123,7 @@ describe("AnalyserNode", function() {
133123

134124
assert.throws(function() {
135125
node.smoothingTimeConstant = "INVALID";
136-
}, function(e) {
137-
return e instanceof TypeError && /should be a number/.test(e.message);
138-
});
126+
}, TypeError);
139127
});
140128
});
141129

@@ -149,9 +137,7 @@ describe("AnalyserNode", function() {
149137

150138
assert.throws(function() {
151139
node.getFloatFrequencyData(i16);
152-
}, function(e) {
153-
return e instanceof TypeError && /should be a Float32Array/.test(e.message);
154-
});
140+
}, TypeError);
155141

156142
assert(node.getFloatFrequencyData === global.AnalyserNode.prototype.getFloatFrequencyData);
157143
});
@@ -167,9 +153,7 @@ describe("AnalyserNode", function() {
167153

168154
assert.throws(function() {
169155
node.getByteFrequencyData(i16);
170-
}, function(e) {
171-
return e instanceof TypeError && /should be a Uint8Array/.test(e.message);
172-
});
156+
}, TypeError);
173157

174158
assert(node.getByteFrequencyData === global.AnalyserNode.prototype.getByteFrequencyData);
175159
});
@@ -183,9 +167,7 @@ describe("AnalyserNode", function() {
183167

184168
assert.throws(function() {
185169
node.getFloatTimeDomainData(f32);
186-
}, function(e) {
187-
return e instanceof TypeError && /not enabled/.test(e.message);
188-
});
170+
}, TypeError);
189171

190172
WebAudioTestAPI.setState("AnalyserNode#getFloatTimeDomainData", "enabled");
191173

@@ -195,9 +177,7 @@ describe("AnalyserNode", function() {
195177

196178
assert.throws(function() {
197179
node.getFloatTimeDomainData(i16);
198-
}, function(e) {
199-
return e instanceof TypeError && /should be a Float32Array/.test(e.message);
200-
});
180+
}, TypeError);
201181

202182
WebAudioTestAPI.setState("AnalyserNode#getFloatTimeDomainData", "disabled");
203183

@@ -215,9 +195,7 @@ describe("AnalyserNode", function() {
215195

216196
assert.throws(function() {
217197
node.getByteTimeDomainData(i16);
218-
}, function(e) {
219-
return e instanceof TypeError && /should be a Uint8Array/.test(e.message);
220-
});
198+
}, TypeError);
221199

222200
assert(node.getByteTimeDomainData === global.AnalyserNode.prototype.getByteTimeDomainData);
223201
});

test/AudioBuffer.js

+25-75
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,19 @@ describe("AudioBuffer", function() {
1414

1515
assert.throws(function() {
1616
audioContext.createBuffer(1.5, 128, 44100);
17-
}, function(e) {
18-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
19-
});
17+
}, TypeError);
2018

2119
assert.throws(function() {
2220
audioContext.createBuffer(2, 16.5, 44100);
23-
}, function(e) {
24-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
25-
});
21+
}, TypeError);
2622

2723
assert.throws(function() {
2824
audioContext.createBuffer(2, 128, 44100.5);
29-
}, function(e) {
30-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
31-
});
25+
}, TypeError);
3226

3327
assert.throws(function() {
3428
return new global.AudioBuffer();
35-
}, function(e) {
36-
return e instanceof TypeError && /Illegal constructor/.test(e.message);
37-
});
29+
}, TypeError);
3830
});
3931
});
4032

@@ -50,9 +42,7 @@ describe("AudioBuffer", function() {
5042

5143
assert.throws(function() {
5244
buf1.sampleRate = 48000;
53-
}, function(e) {
54-
return e instanceof TypeError && /readonly/.test(e.message);
55-
});
45+
}, TypeError);
5646
});
5747
});
5848

@@ -68,9 +58,7 @@ describe("AudioBuffer", function() {
6858

6959
assert.throws(function() {
7060
buf1.length = 32;
71-
}, function(e) {
72-
return e instanceof TypeError && /readonly/.test(e.message);
73-
});
61+
}, TypeError);
7462
});
7563
});
7664

@@ -86,9 +74,7 @@ describe("AudioBuffer", function() {
8674

8775
assert.throws(function() {
8876
buf1.duration = 32 / 48000;
89-
}, function(e) {
90-
return e instanceof TypeError && /readonly/.test(e.message);
91-
});
77+
}, TypeError);
9278
});
9379
});
9480

@@ -104,9 +90,7 @@ describe("AudioBuffer", function() {
10490

10591
assert.throws(function() {
10692
buf1.numberOfChannels = 2;
107-
}, function(e) {
108-
return e instanceof TypeError && /readonly/.test(e.message);
109-
});
93+
}, TypeError);
11094
});
11195
});
11296

@@ -129,19 +113,13 @@ describe("AudioBuffer", function() {
129113

130114
assert.throws(function() {
131115
buf1.getChannelData(1);
132-
}, function(e) {
133-
return e instanceof TypeError && /exceeds number of channels/.test(e.message);
134-
});
116+
}, TypeError);
135117
assert.throws(function() {
136118
buf2.getChannelData(2);
137-
}, function(e) {
138-
return e instanceof TypeError && /exceeds number of channels/.test(e.message);
139-
});
119+
}, TypeError);
140120
assert.throws(function() {
141121
buf1.getChannelData(2.5);
142-
}, function(e) {
143-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
144-
});
122+
}, TypeError);
145123

146124
assert(buf1.getChannelData === global.AudioBuffer.prototype.getChannelData);
147125
});
@@ -157,9 +135,7 @@ describe("AudioBuffer", function() {
157135

158136
assert.throws(function() {
159137
buf1.copyFromChannel(dest, 0, 0);
160-
}, function(e) {
161-
return e instanceof TypeError && /not enabled/.test(e.message);
162-
});
138+
}, TypeError);
163139

164140
WebAudioTestAPI.setState("AudioBuffer#copyFromChannel", "enabled");
165141

@@ -177,39 +153,27 @@ describe("AudioBuffer", function() {
177153

178154
assert.throws(function() {
179155
buf1.copyFromChannel("INVALID", 0, 0);
180-
}, function(e) {
181-
return e instanceof TypeError && /should be a Float32Array/.test(e.message);
182-
});
156+
}, TypeError);
183157

184158
assert.throws(function() {
185159
buf1.copyFromChannel(dest, "INVALID", 0);
186-
}, function(e) {
187-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
188-
});
160+
}, TypeError);
189161

190162
assert.throws(function() {
191163
buf1.copyFromChannel(dest, 0, "INVALID");
192-
}, function(e) {
193-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
194-
});
164+
}, TypeError);
195165

196166
assert.throws(function() {
197167
buf1.copyFromChannel(dest, 10, 0);
198-
}, function(e) {
199-
return e instanceof TypeError && /outside the range/.test(e.message);
200-
});
168+
}, TypeError);
201169

202170
assert.throws(function() {
203171
buf1.copyFromChannel(dest, 0, 10);
204-
}, function(e) {
205-
return e instanceof TypeError && /outside the range/.test(e.message);
206-
});
172+
}, TypeError);
207173

208174
assert.throws(function() {
209175
buf1.copyFromChannel(dest, 0, undefined);
210-
}, function(e) {
211-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
212-
});
176+
}, TypeError);
213177

214178
WebAudioTestAPI.setState("AudioBuffer#copyFromChannel", "disabled");
215179

@@ -224,9 +188,7 @@ describe("AudioBuffer", function() {
224188

225189
assert.throws(function() {
226190
buf1.copyToChannel(source, 0, 0);
227-
}, function(e) {
228-
return e instanceof TypeError && /not enabled/.test(e.message);
229-
});
191+
}, TypeError);
230192

231193
WebAudioTestAPI.setState("AudioBuffer#copyToChannel", "enabled");
232194

@@ -244,39 +206,27 @@ describe("AudioBuffer", function() {
244206

245207
assert.throws(function() {
246208
buf1.copyToChannel("INVALID", 0, 0);
247-
}, function(e) {
248-
return e instanceof TypeError && /should be a Float32Array/.test(e.message);
249-
});
209+
}, TypeError);
250210

251211
assert.throws(function() {
252212
buf1.copyToChannel(source, "INVALID", 0);
253-
}, function(e) {
254-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
255-
});
213+
}, TypeError);
256214

257215
assert.throws(function() {
258216
buf1.copyToChannel(source, 0, "INVALID");
259-
}, function(e) {
260-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
261-
});
217+
}, TypeError);
262218

263219
assert.throws(function() {
264220
buf1.copyToChannel(source, 10, 0);
265-
}, function(e) {
266-
return e instanceof TypeError && /outside the range/.test(e.message);
267-
});
221+
}, TypeError);
268222

269223
assert.throws(function() {
270224
buf1.copyToChannel(source, 0, 10);
271-
}, function(e) {
272-
return e instanceof TypeError && /outside the range/.test(e.message);
273-
});
225+
}, TypeError);
274226

275227
assert.throws(function() {
276228
buf1.copyToChannel(source, 0, undefined);
277-
}, function(e) {
278-
return e instanceof TypeError && /should be a positive integer/.test(e.message);
279-
});
229+
}, TypeError);
280230

281231
WebAudioTestAPI.setState("AudioBuffer#copyToChannel", "disabled");
282232

0 commit comments

Comments
 (0)