freeCodeCamp/utils/sort-files.test.js

27 lines
953 B
JavaScript
Raw Normal View History

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