freeCodeCamp/utils/sort-challengefiles.test.js

25 lines
964 B
JavaScript
Raw Normal View History

2020-06-01 16:28:22 +00:00
const { challengeFiles } = require('./__fixtures__/challenges');
const { sortChallengeFiles } = require('./sort-challengefiles');
2020-06-01 16:28:22 +00:00
describe('sort-files', () => {
describe('sortChallengeFiles', () => {
2020-06-01 16:28:22 +00:00
it('should return an array', () => {
const sorted = sortChallengeFiles(challengeFiles);
2020-06-01 16:28:22 +00:00
expect(Array.isArray(sorted)).toBe(true);
});
it('should not modify the challenges', () => {
const sorted = sortChallengeFiles(challengeFiles);
const expected = challengeFiles;
2020-06-01 16:28:22 +00:00
expect(sorted).toEqual(expect.arrayContaining(expected));
expect(sorted.length).toEqual(expected.length);
});
it('should sort the objects into html, css, jsx, js order', () => {
const sorted = sortChallengeFiles(challengeFiles);
const sortedKeys = sorted.map(({ fileKey }) => fileKey);
const expected = ['indexhtml', 'indexcss', 'indexjsx', 'indexjs'];
2020-06-01 16:28:22 +00:00
expect(sortedKeys).toStrictEqual(expected);
});
});
});