mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
24 lines
843 B
TypeScript
24 lines
843 B
TypeScript
import * as fs from 'fs';
|
|
import { getOpenApiSpec } from './getOpenApiSpec';
|
|
|
|
jest.mock('fs');
|
|
|
|
const fsExistsSync = fs.existsSync as jest.MockedFunction<typeof fs.existsSync>;
|
|
const fsReadFileSync = fs.readFileSync as jest.MockedFunction<typeof fs.readFileSync>;
|
|
|
|
describe('getOpenApiSpec', () => {
|
|
it('should read the json file', () => {
|
|
fsExistsSync.mockReturnValue(true);
|
|
fsReadFileSync.mockReturnValue('{"message": "Hello World!"}');
|
|
const spec = getOpenApiSpec('spec.json');
|
|
expect(spec.message).toEqual('Hello World!');
|
|
});
|
|
|
|
it('should read the yaml file', () => {
|
|
fsExistsSync.mockReturnValue(true);
|
|
fsReadFileSync.mockReturnValue('message: "Hello World!"');
|
|
const spec = getOpenApiSpec('spec.yaml');
|
|
expect(spec.message).toEqual('Hello World!');
|
|
});
|
|
});
|