feat(rtts_assert): avoid deep recursion in prettyPrint
This commit is contained in:
@ -14,6 +14,33 @@
|
||||
|
||||
export function main() {
|
||||
|
||||
describe('prettyPrint', () => {
|
||||
class Type {};
|
||||
|
||||
it('should limit the number of printed properties', () => {
|
||||
var o = {};
|
||||
for (var i = 0; i < 100; i++) {
|
||||
o['p_' + i] = i;
|
||||
}
|
||||
try {
|
||||
assert.type(o, Type);
|
||||
throw 'fail!';
|
||||
} catch (e) {
|
||||
expect(e.message.indexOf('p_0')).toBeGreaterThan(-1);
|
||||
expect(e.message.indexOf('...')).toBeGreaterThan(-1);
|
||||
expect(e.message.indexOf('p_20')).toBe(-1);
|
||||
}
|
||||
});
|
||||
|
||||
it('should limit the depth of printed properties', () => {
|
||||
var o = {l1: {l2: {l3: {l4: {l5: {l6: 'deep'}}}}}};
|
||||
|
||||
expect(() => {
|
||||
assert.type(o, Type);
|
||||
}).toThrowError('Expected an instance of Type, got {l1: {l2: {l3: {l4: [...]}}}}!');
|
||||
});
|
||||
});
|
||||
|
||||
// ## Basic Type Check
|
||||
// By default, `instanceof` is used to check the type.
|
||||
//
|
||||
|
Reference in New Issue
Block a user