import 'mocha'; import { expect } from 'chai'; import { replaceIDs } from '../lib/svg/id'; describe('Testing replaceIDs', () => { it('Simple code', () => { const body = ''; // Counter starts with 0, so first id is test-0 expect(replaceIDs(body, 'test-')).to.be.equal( '' ); // Using callback let counter = 0; expect(replaceIDs(body, () => 'callback-' + counter++)).to.be.equal( body .replace(/ssvg-id-1st-place-medala/g, 'callback-0') .replace(/ssvg-id-1st-place-medalb/g, 'callback-7') .replace(/ssvg-id-1st-place-medalc/g, 'callback-10') .replace(/ssvg-id-1st-place-medald/g, 'callback-1') .replace(/ssvg-id-1st-place-medale/g, 'callback-11') .replace(/ssvg-id-1st-place-medalf/g, 'callback-2') .replace(/ssvg-id-1st-place-medalg/g, 'callback-12') .replace(/ssvg-id-1st-place-medalh/g, 'callback-3') .replace(/ssvg-id-1st-place-medali/g, 'callback-13') .replace(/ssvg-id-1st-place-medalj/g, 'callback-4') .replace(/ssvg-id-1st-place-medalk/g, 'callback-8') .replace(/ssvg-id-1st-place-medall/g, 'callback-14') .replace(/ssvg-id-1st-place-medalm/g, 'callback-5') .replace(/ssvg-id-1st-place-medaln/g, 'callback-15') .replace(/ssvg-id-1st-place-medalo/g, 'callback-9') .replace(/ssvg-id-1st-place-medalp/g, 'callback-6') ); }); it('With animation', () => { const body = ''; // To avoid messing up counter, using custom callback let counter = 0; expect(replaceIDs(body, () => 'callback-' + counter++)).to.be.equal( body .replace(/ssvg-id-compassa/g, 'callback-2') .replace(/ssvg-id-compassb/g, 'callback-0') .replace(/ssvg-id-compassc/g, 'callback-1') ); }); });