Files
freeCodeCamp/tools/challenge-helper-scripts/helpers/insert-erms.test.ts
Oliver Eyton-Williams 7216ca55cc refactor: organise TypeScript config and migrate helpers (#44747)
* feat: allow more 1000 steps to be created at once

* refactor: start migrating to typescript

* refactor: delete-step to ts

* refactor: migrated some helpers

* refactor: migrate create-empty-steps

* refactor: migrate create-step-between

* refactor: finish migrating to TS

* refactor: migrate tests

* fix: ensure mock.restore is done after each test

* fix: prevent double-tscing

* fix: repair the tests

* chore: use ts-node for scripts

We don't need the performance boost of incremental compilation and
ts-node is easier to work with

* refactor: consolidate tsconfigs

* refactor: replace gulp

* fix: use ts-node for build-curriculum

* fix: allow ts compilation of config

* feat: create and use create:config script

* fix: add /config to eslint projects

* fix: remove gulp script
2022-01-25 11:34:16 +01:00

50 lines
2.0 KiB
TypeScript

import { insertErms } from './insert-erms';
describe('insertErms helper', () => {
const code = `<h1>Hello World</h1>
<main>
<h2>CatPhotoApp</h2>
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
</main>`;
it('should throw error if erm length is less than 2', () => {
const items = [[], [1]];
items.forEach(item => {
expect(() => {
insertErms(code, item);
}).toThrow();
});
});
it('should update code with markers if provided', () => {
const newCode = `--fcc-editable-region--
<h1>Hello World</h1>
<main>
<h2>CatPhotoApp</h2>
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
--fcc-editable-region--
</main>`;
expect(insertErms(code, [0, 7])).toEqual(newCode);
});
it('should update code with 2 markers if more are provided', () => {
const newCode = `<h1>Hello World</h1>
<main>
--fcc-editable-region--
<h2>CatPhotoApp</h2>
--fcc-editable-region--
<img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
</main>`;
expect(insertErms(code, [2, 4, 6, 7])).toEqual(newCode);
});
});