Files
freeCodeCamp/client/utils/sort-challengefiles.test.js
2025-03-04 07:57:14 +01:00

31 lines
1.0 KiB
JavaScript

const { challengeFiles } = require('./__fixtures__/challenges');
const { sortChallengeFiles } = require('./sort-challengefiles');
describe('sort-files', () => {
describe('sortChallengeFiles', () => {
it('should return an array', () => {
const sorted = sortChallengeFiles(challengeFiles);
expect(Array.isArray(sorted)).toBe(true);
});
it('should not modify the challenges', () => {
const sorted = sortChallengeFiles(challengeFiles);
const expected = challengeFiles;
expect(sorted).toEqual(expect.arrayContaining(expected));
expect(sorted.length).toEqual(expected.length);
});
it('should sort the objects into jsx, html, css, js, ts order', () => {
const sorted = sortChallengeFiles(challengeFiles);
const sortedKeys = sorted.map(({ fileKey }) => fileKey);
const expected = [
'indexjsx',
'indexhtml',
'stylescss',
'scriptjs',
'indexts'
];
expect(sortedKeys).toStrictEqual(expected);
});
});
});