UNPKG

bixi

Version:

企业级中后台前端解决方案

71 lines (64 loc) 1.69 kB
import { isFunction, isNull, isUndefined, isObject, isString, isNullOrUndefined, toString, has, getLocalItem, setLocalItem } from './public_api'; describe('@bixi/core/utils', () => { const types = [ () => { }, // 0 undefined, // 1 null, // 2 'string', // 3 NaN, // 4 2, // 5 true, // 6 {} //7 ]; const mockObj = { a: '1' }; function typeAssert(name: string, fn: any, indexs: number[] = []) { it(`# ${name}`, () => { types.forEach((item, idx) => { expect(fn(item)).toBe(indexs.includes(idx)); }); }); } typeAssert('isFunction', isFunction, [0]); typeAssert('isNull', isNull, [2]); typeAssert('isUndefined', isUndefined, [1]); typeAssert('isObject', isObject, [0, 7]); typeAssert('isString', isString, [3]); typeAssert('isNullOrUndefined', isNullOrUndefined, [1, 2]); it('# toString', () => { expect(toString(3)).toBe('3'); expect(toString(null)).toBe(''); }); it(`# has`, () => { expect(has(mockObj, 'a')).toBe(true); expect(has(mockObj, 'b')).toBe(false); }); it(`# storage call fn`, () => { spyOn(localStorage, 'setItem').and.stub(); spyOn(localStorage, 'getItem').and.stub(); setLocalItem('olive', 'wind'); expect(localStorage.setItem).toHaveBeenCalledTimes(1); getLocalItem('olive'); expect(localStorage.getItem).toHaveBeenCalledTimes(1); expect(localStorage.getItem).toHaveBeenCalledWith('BIXI_OLIVE'); }) it(`# storage`, () => { setLocalItem('olive', 'wind'); expect(getLocalItem('olive')).toBe('wind'); }) // // TODO: // it(`#AutoUnsubscribe`, () => { // }) });