|
| 1 | +const test = require('ava'); |
| 2 | + |
| 3 | +const EntityTypeError = require('../lib/entity-type-error'); |
| 4 | + |
| 5 | +test('should create type error', t => { |
| 6 | + const error = new EntityTypeError(); |
| 7 | + |
| 8 | + t.is(error.message, 'the `undefined` is not valid BEM entity'); |
| 9 | +}); |
| 10 | + |
| 11 | +test('should create type error with number', t => { |
| 12 | + const error = new EntityTypeError(42); |
| 13 | + |
| 14 | + t.is(error.message, 'the number `42` is not valid BEM entity'); |
| 15 | +}); |
| 16 | + |
| 17 | +test('should create type error with string', t => { |
| 18 | + const error = new EntityTypeError('block'); |
| 19 | + |
| 20 | + t.is(error.message, 'the string `\'block\'` is not valid BEM entity'); |
| 21 | +}); |
| 22 | + |
| 23 | +test('should create type error with empty object', t => { |
| 24 | + const error = new EntityTypeError({}); |
| 25 | + |
| 26 | + t.is(error.message, 'the object `{}` is not valid BEM entity'); |
| 27 | +}); |
| 28 | + |
| 29 | +test('should create type error with object', t => { |
| 30 | + const error = new EntityTypeError({ key: 'val' }); |
| 31 | + |
| 32 | + t.is(error.message, "the object `{ key: 'val' }` is not valid BEM entity"); |
| 33 | +}); |
| 34 | + |
| 35 | +test('should create type error with deep object', t => { |
| 36 | + const error = new EntityTypeError({ a: { b: { c: 'd' } } }); |
| 37 | + |
| 38 | + t.is(error.message, 'the object `{ a: { b: [Object] } }` is not valid BEM entity'); |
| 39 | +}); |
| 40 | + |
| 41 | +test('should create type error with reason', t => { |
| 42 | + const error = new EntityTypeError({ elem: 'elem' }, 'the field `block` is undefined'); |
| 43 | + |
| 44 | + t.is(error.message, "the object `{ elem: 'elem' }` is not valid BEM entity, the field `block` is undefined"); |
| 45 | +}); |
0 commit comments