|
1 | 1 | /** |
2 | 2 | * Tests for util.js |
3 | 3 | */ |
4 | | -import chai from 'chai'; |
| 4 | +import chai, { expect } from 'chai'; |
5 | 5 | import util from './util'; |
6 | 6 |
|
7 | 7 | chai.should(); |
8 | 8 |
|
9 | 9 | describe('Util method', () => { |
| 10 | + describe('parseIntStrictly', () => { |
| 11 | + it('should parse a good integer value sucessfully', () => { |
| 12 | + util.parseIntStrictly('1234567890', 10, null).should.equal(1234567890); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should return fallback value if the initial value is a float number', () => { |
| 16 | + expect(util.parseIntStrictly('1.1', 10, null)).be.equal(null); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should return fallback value if string can be parsed partially only', () => { |
| 20 | + expect(util.parseIntStrictly('123XXX', 10, null)).be.equal(null); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should return fallback value if the initial value is `null`', () => { |
| 24 | + util.parseIntStrictly(null, 10, 0).should.equal(0); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should return fallback value if the initial value is `undefined`', () => { |
| 28 | + expect(util.parseIntStrictly(undefined, 10, null)).be.equal(null); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should return fallback value if the initial value is `""` (emtpy string)', () => { |
| 32 | + expect(util.parseIntStrictly('', 10, null)).be.equal(null); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
10 | 36 | describe('maskEmail', () => { |
11 | 37 | it('should return the original value if the email is non-string', () => { |
12 | 38 | chai.should().not.exist(util.maskEmail(null)); |
|
0 commit comments