Skip to content

Instantly share code, notes, and snippets.

@corocoto
Created December 31, 2020 09:56
Show Gist options
  • Select an option

  • Save corocoto/617a6bbe24e47b3c54753fb79337b09f to your computer and use it in GitHub Desktop.

Select an option

Save corocoto/617a6bbe24e47b3c54753fb79337b09f to your computer and use it in GitHub Desktop.
//correct test for https://ru.hexlet.io/courses/js-advanced-testing/lessons/files/exercise_unit task
import os from 'os';
import path from 'path';
import { promises as fs } from 'fs';
import getFunction from '../functions.js';
const prettifyHTMLFile = getFunction();
// BEGIN (write your solution here)
let expected;
const getFixturePath = filename => path.join('__fixtures__', filename);
const src = getFixturePath('before.html');
const dest = path.join(os.tmpdir(), 'before.html');
beforeAll(async () => expected = await fs.readFile(getFixturePath('after.html'), 'utf-8'));
beforeEach(async () => await fs.copyFile(src, dest));
test('prettifyHTMLFile', async () => {
await prettifyHTMLFile(dest);
const actual = await fs.readFile(dest, 'utf-8');
expect(actual).toBe(expected);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment