feat(rtts_assert): avoid deep recursion in prettyPrint

This commit is contained in:
Victor Berchet
2015-02-24 16:24:58 +01:00
parent 908a0aa7dc
commit e05079f4a8
2 changed files with 44 additions and 4 deletions

View File

@ -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.
//