2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-03 13:20:47 +00:00
nativefier/src/utils/sanitizeFilename.test.js
Jia Hao Goh 1505933826 Promisfy and parallelise config, add unit tests
Instead of optionsMain exporting an async function, this commit changes
it to return a promise instead. We split all the needed async
helpers for this config builder into smaller promises, in `src/options/*`. Another side
effect of this is that we perform all our async config inferring in
parallel, which speeds up the nativefier CLI.

Add proper unit tests as well for all of these promises. Switch to
Jest for these unit tests, and we are temporarily running both Jest and
mocha together in `npm test`. To refactor all the Mocha code to use Jest in
a future commit.
2017-05-07 15:49:15 +08:00

37 lines
1.2 KiB
JavaScript
Raw Blame History

import sanitizeFilenameLib from 'sanitize-filename';
import sanitizeFilename from './sanitizeFilename';
import { DEFAULT_APP_NAME } from './../constants';
jest.mock('sanitize-filename');
sanitizeFilenameLib.mockImplementation(str => str);
test('it should call the sanitize-filename npm module', () => {
const param = 'abc';
sanitizeFilename('', param);
expect(sanitizeFilenameLib).toHaveBeenCalledWith(param);
});
describe('replacing non ascii characters', () => {
const nonAscii = '<27>';
test('it should return a result without non ascii cahracters', () => {
const param = `${nonAscii}abc`;
const expectedResult = 'abc';
const result = sanitizeFilename('', param);
expect(result).toBe(expectedResult);
});
describe('when the result of replacing these characters is empty', () => {
const result = sanitizeFilename('', nonAscii);
expect(result).toBe(DEFAULT_APP_NAME);
});
});
describe('when the platform is linux', () => {
test('it should return a kebab cased name', () => {
const param = 'some name';
const expectedResult = 'some-name';
const result = sanitizeFilename('linux', param);
expect(result).toBe(expectedResult);
});
});