|
| 1 | +import { expect } from 'chai'; |
| 2 | +import typeStorage from '../typeStorage'; |
| 3 | + |
| 4 | +describe('typeStorage', () => { |
| 5 | + it('should be instance of Map', () => { |
| 6 | + expect(typeStorage).instanceof(Map); |
| 7 | + }); |
| 8 | + |
| 9 | + it('should work `get`, `set`, `has`, `clear` methods and `size` property', () => { |
| 10 | + typeStorage.clear(); |
| 11 | + expect(typeStorage.size).to.equal(0); |
| 12 | + typeStorage.set(123, 567); |
| 13 | + expect(typeStorage.get(123)).to.equal(567); |
| 14 | + expect(typeStorage.has(123)).to.be.true; |
| 15 | + expect(typeStorage.size).to.equal(1); |
| 16 | + typeStorage.clear(); |
| 17 | + expect(typeStorage.size).to.equal(0); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('getOrSet() method', () => { |
| 21 | + it('should return existed value', () => { |
| 22 | + typeStorage.clear(); |
| 23 | + typeStorage.set(123, 456); |
| 24 | + expect(typeStorage.getOrSet(123, 'any')).to.equal(456); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should set new value and return it, if key not exists', () => { |
| 28 | + typeStorage.clear(); |
| 29 | + expect(typeStorage.getOrSet(123, 456)).to.equal(456); |
| 30 | + expect(typeStorage.get(123)).to.equal(456); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should not set new value if it is empty', () => { |
| 34 | + typeStorage.clear(); |
| 35 | + expect(typeStorage.getOrSet(123, null)).to.equal(null); |
| 36 | + expect(typeStorage.has(123)).to.be.false; |
| 37 | + }); |
| 38 | + }); |
| 39 | +}); |
0 commit comments