Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c75796b

Browse files
author
Thomas Grainger
committed
code review
1 parent a3ad826 commit c75796b

File tree

1 file changed

+65
-37
lines changed

1 file changed

+65
-37
lines changed

Diff for: test/ng/qSpec.js

+65-37
Original file line numberDiff line numberDiff line change
@@ -2165,15 +2165,40 @@ describe('q', function() {
21652165

21662166

21672167
describe('when exceptionHandler is called', function() {
2168-
var exceptionEg = new Error('Fail');
2169-
var exceptionStr = toDebugString(exceptionEg);
2168+
function CustomError() { }
2169+
CustomError.prototype = Object.create(Error.prototype);
2170+
2171+
var errorEg = new Error('Fail');
2172+
var errorStr = toDebugString(errorEg);
2173+
2174+
var customError = new CustomError('Custom');
2175+
var customErrorStr = toDebugString(customError);
2176+
2177+
var nonErrorObj = { isATest: 'this is' };
2178+
var nonErrorObjStr = toDebugString(nonErrorObj);
2179+
21702180
var fixtures = [
21712181
{
2172-
type: 'exception',
2173-
value: exceptionEg,
2182+
type: 'Error object',
2183+
value: errorEg,
2184+
expected: {
2185+
exception: errorEg,
2186+
reason: 'Possibly unhandled rejection: ' + errorStr
2187+
}
2188+
},
2189+
{
2190+
type: 'Custom Error object',
2191+
value: customError,
21742192
expected: {
2175-
exception: exceptionEg,
2176-
reason: 'Possibly unhandled rejection: ' + exceptionStr
2193+
exception: customError,
2194+
reason: 'Possibly unhandled rejection: ' + customErrorStr
2195+
}
2196+
},
2197+
{
2198+
type: 'Non-Error object',
2199+
value: nonErrorObj,
2200+
expected: {
2201+
reason: 'Possibly unhandled rejection: ' + nonErrorObjStr
21772202
}
21782203
},
21792204
{
@@ -2188,45 +2213,48 @@ describe('q', function() {
21882213
var type = fixture.type;
21892214
var value = fixture.value;
21902215
var expected = fixture.expected;
2191-
it('should log an unhandled' + type + ' rejected promise', function() {
2192-
var defer = q.defer();
2193-
defer.reject(value);
2194-
mockNextTick.flush();
2195-
expect(exceptionHandlerCalls).toEqual([expected]);
2196-
});
2216+
describe(type, function() {
2217+
2218+
it('should log an unhandled rejected promise', function() {
2219+
var defer = q.defer();
2220+
defer.reject(value);
2221+
mockNextTick.flush();
2222+
expect(exceptionHandlerCalls).toEqual([expected]);
2223+
});
21972224

21982225

2199-
it('should not log an unhandled' + type + ' rejected promise if disabled', function() {
2200-
var defer = q_no_error.defer();
2201-
defer.reject(value);
2202-
expect(exceptionHandlerCalls).toEqual([]);
2203-
});
2226+
it('should not log an unhandled rejected promise if disabled', function() {
2227+
var defer = q_no_error.defer();
2228+
defer.reject(value);
2229+
expect(exceptionHandlerCalls).toEqual([]);
2230+
});
22042231

22052232

2206-
it('should log a handled' + type + ' rejected promise on a promise without rejection callbacks', function() {
2207-
var defer = q.defer();
2208-
defer.promise.then(noop);
2209-
defer.reject(value);
2210-
mockNextTick.flush();
2211-
expect(exceptionHandlerCalls).toEqual([expected]);
2212-
});
2233+
it('should log a handled rejected promise on a promise without rejection callbacks', function() {
2234+
var defer = q.defer();
2235+
defer.promise.then(noop);
2236+
defer.reject(value);
2237+
mockNextTick.flush();
2238+
expect(exceptionHandlerCalls).toEqual([expected]);
2239+
});
22132240

22142241

2215-
it('should not log a handled' + type + 'rejected promise', function() {
2216-
var defer = q.defer();
2217-
defer.promise.catch(noop);
2218-
defer.reject(value);
2219-
mockNextTick.flush();
2220-
expect(exceptionHandlerCalls).toEqual([]);
2221-
});
2242+
it('should not log a handled rejected promise', function() {
2243+
var defer = q.defer();
2244+
defer.promise.catch(noop);
2245+
defer.reject(value);
2246+
mockNextTick.flush();
2247+
expect(exceptionHandlerCalls).toEqual([]);
2248+
});
22222249

22232250

2224-
it('should not log a handled' + type + ' rejected promise that is handled in a future tick', function() {
2225-
var defer = q.defer();
2226-
defer.promise.catch(noop);
2227-
defer.resolve(q.reject(value));
2228-
mockNextTick.flush();
2229-
expect(exceptionHandlerCalls).toEqual([]);
2251+
it('should not log a handled rejected promise that is handled in a future tick', function() {
2252+
var defer = q.defer();
2253+
defer.promise.catch(noop);
2254+
defer.resolve(q.reject(value));
2255+
mockNextTick.flush();
2256+
expect(exceptionHandlerCalls).toEqual([]);
2257+
});
22302258
});
22312259
});
22322260
});

0 commit comments

Comments
 (0)