|
| 1 | +import { TranslatorCollection, TranslatorConfigFactory } from '../src'; |
| 2 | + |
| 3 | + |
| 4 | +describe('TranslatorCollection', () => { |
| 5 | + let collection: TranslatorCollection; |
| 6 | + beforeEach(() => { |
| 7 | + collection = new TranslatorCollection(); |
| 8 | + collection.set('p', { ignore: true }); |
| 9 | + }); |
| 10 | + test('size', () => |
| 11 | + expect(collection.size).toBe(1) |
| 12 | + ); |
| 13 | + test('get', () => { |
| 14 | + expect(collection.get('p')).toEqual({ ignore: true }); |
| 15 | + expect(collection.get('P')).toEqual({ ignore: true }); |
| 16 | + expect(collection['P']).toEqual({ ignore: true }); |
| 17 | + }); |
| 18 | + test('set', () => { |
| 19 | + collection.set('p', { ignore: false }); |
| 20 | + expect(collection.get('p')).toEqual({ ignore: false }); |
| 21 | + }); |
| 22 | + test('set with preserveBase', () => { |
| 23 | + collection.set('p', { recurse: true }, true); |
| 24 | + expect(collection.get('p')).toEqual({ ignore: true, recurse: true }); |
| 25 | + }); |
| 26 | + test('set with preserveBase and configFactory', () => { |
| 27 | + collection.set('p', () => ({ recurse: true }), true); |
| 28 | + expect(collection.get('p')).toBeInstanceOf(Function) |
| 29 | + expect((<Function>collection.get('p'))()).toEqual({ recurse: true }); |
| 30 | + expect((<TranslatorConfigFactory>collection.get('p')).base).toEqual({ ignore: true }); |
| 31 | + }); |
| 32 | + test('set with multiple keys', () => { |
| 33 | + collection.set('p,div', { ignore: false }); |
| 34 | + expect(collection.get('p')).toEqual({ ignore: false }); |
| 35 | + expect(collection.get('div')).toEqual({ ignore: false }); |
| 36 | + }); |
| 37 | + test('entries', () => expect(collection.entries()).toEqual([ [ 'P', { ignore: true } ] ])); |
| 38 | + test('remove', () => { |
| 39 | + collection.remove('p'); |
| 40 | + expect(collection.get('p')).toBeUndefined(); |
| 41 | + }); |
| 42 | +}); |
0 commit comments