This library is inspired by AutoFixture but written with TypeScript for TypeScript developers.
import {Fixture} from '@typefixture/core';
interface ITestInterface {
a: number;
b: string;
}
describe('Jest simple tests', () => {
it('Should create an object with interface', () => {
const fixture = new Fixture();
const generated = fixture.create<ITestInterface>();
expect(generated.a).toEqual(expect.any(Number));
expect(generated.b).toEqual(expect.any(String));
});
});
npm install @typefixture/core --save-dev
npm install @typefixture/jest --save-dev
npm install ts-morph --save-dev
In jest.config.js
...
globals: {
'ts-jest': {
astTransformers: [
'@typefixture/jest'
]
}
}
...
- This library is in PoC state.
- ts-morph dependency to be removed.
- Use --no-cache jest CLI option (i.e. npx jest --no-cache)