import url from 'url'; import { createCache, destroyCache } from '../spr'; import { cacheAddition, connectFactor, fname, maybeSync, namespaceHash, valueFactory, withCoalescedInvoke, } from '../util'; describe('test spr util functions', () => { it('should return value correctly', () => { expect(connectFactor('bar', 'foo')).toBe('bar-foo'); expect(fname(1)).toBe('f1'); expect(namespaceHash('modern', '!@#$%^&')).toBe('modern/!@#$%^&'); }); it('should create or destroy instance correctly', () => { const ins1 = createCache(); const ins2 = createCache(); expect(ins1 === ins2).toBe(true); destroyCache(); const ins3 = createCache(); expect(ins1 === ins3).toBe(false); expect(ins2 === ins3).toBe(false); }); it('should return function correctly', () => { const urlParams: any = (() => new url.URLSearchParams())(); urlParams.set('name', 'modern'); const getParam = valueFactory(urlParams); expect(getParam('name')).toBe('modern'); const headers: any = { age: '12345' }; const getHeader = valueFactory(headers); expect(getHeader('age')).toBe('12345'); }); it('should add target html content', () => { const contentNoHead = '