-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetComponentsFiles.spec.ts
More file actions
44 lines (42 loc) · 1.43 KB
/
getComponentsFiles.spec.ts
File metadata and controls
44 lines (42 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import axios, { AxiosRequestConfig } from 'axios';
import fs, { PathOrFileDescriptor } from 'node:fs';
import { getComponentsFiles } from '../../helpers/getComponentsFiles';
describe('getComponentsFiles()', () => {
describe('passing an URL', () => {
it('expects to fetch the file using axios', () => {
const spy = jest
.spyOn(axios, 'get')
.mockImplementation((url: string, config?: AxiosRequestConfig<unknown> | undefined): Promise<unknown> => {
return new Promise((resolve) => {
// eslint-disable-next-line no-console
console.log(url, config, resolve);
});
});
getComponentsFiles('http://localhost', true);
expect(spy).toHaveBeenCalled();
});
});
describe('passing a local file path', () => {
it('expects to fetch the file using fs', () => {
const spy = jest
.spyOn(fs, 'readFileSync')
.mockImplementation(
(
filePath: PathOrFileDescriptor,
encoding: BufferEncoding | (unknown & { flag?: string | undefined }) | null | undefined
): string => {
// eslint-disable-next-line no-console
console.log(filePath, encoding);
return 'done';
}
);
getComponentsFiles('/route/to/file', false);
expect(spy).toHaveBeenCalled();
});
});
});