UNPKG

bootstrap-vue

Version:

BootstrapVue, with over 40 plugins and more than 80 custom components, custom directives, and over 300 icons, provides one of the most comprehensive implementations of Bootstrap v4 components and grid system for Vue.js. With extensive and automated WAI-AR

69 lines (65 loc) 2.51 kB
import { toFixed, toFloat, toInteger } from './number' describe('utils/number', () => { it('toInteger works', async () => { expect(toInteger(1)).toBe(1) expect(toInteger('1')).toBe(1) expect(toInteger(1e5)).toBe(100000) expect(toInteger('1e5')).toBe(1) expect(toInteger('256 foobar')).toBe(256) expect(toInteger('foo 256bar')).toBe(NaN) expect(toInteger({})).toBe(NaN) expect(toInteger([])).toBe(NaN) expect(toInteger(new Date())).toBe(NaN) expect(toInteger(null)).toBe(NaN) expect(toInteger(undefined)).toBe(NaN) }) it('toFloat works', async () => { expect(toFloat(1)).toBe(1) expect(toFloat('1')).toBe(1) expect(toFloat(1.23)).toBe(1.23) expect(toFloat('1.23')).toBe(1.23) expect(toFloat(1e5)).toBe(100000) // parseFloat works differntly than patseInt in this case expect(toFloat('1e5')).toBe(100000) expect(toFloat('256 foobar')).toBe(256) expect(toFloat('256.78 foobar')).toBe(256.78) expect(toFloat('foo 256bar')).toBe(NaN) expect(toFloat({})).toBe(NaN) expect(toFloat([])).toBe(NaN) expect(toFloat(new Date())).toBe(NaN) expect(toFloat(null)).toBe(NaN) expect(toFloat(undefined)).toBe(NaN) }) it('toFixed works', async () => { expect(toFixed(1)).toBe('1') expect(toFixed(1.23)).toBe('1') expect(toFixed(1.78)).toBe('2') expect(toFixed('1')).toBe('1') expect(toFixed('1.23')).toBe('1') expect(toFixed('1.78')).toBe('2') expect(toFixed(1, 2)).toBe('1.00') expect(toFixed('1', 2)).toBe('1.00') expect(toFixed('1 foo', 2)).toBe('1.00') expect(toFixed('foo 1 bar', 2)).toBe('NaN') expect(toFixed('1.23', 4)).toBe('1.2300') expect(toFixed('1.78', 2)).toBe('1.78') expect(toFixed({})).toBe('NaN') expect(toFixed([])).toBe('NaN') expect(toFixed(new Date())).toBe('NaN') expect(toFixed(null)).toBe('NaN') expect(toFixed(undefined)).toBe('NaN') expect(toFixed({}, 3)).toBe('NaN') expect(toFixed([], 2)).toBe('NaN') expect(toFixed(new Date(), 1)).toBe('NaN') expect(toFixed(null, 4)).toBe('NaN') expect(toFixed(undefined, 3)).toBe('NaN') expect(toFixed(1, '2')).toBe('1.00') expect(toFixed('1', '2')).toBe('1.00') expect(toFixed('1 foo', '2')).toBe('1.00') expect(toFixed('foo 1 bar', '2')).toBe('NaN') expect(toFixed(1, 'foo')).toBe('1') expect(toFixed('1', undefined)).toBe('1') expect(toFixed('1 foo', null)).toBe('1') expect(toFixed('foo 1 bar', {})).toBe('NaN') }) })