TS auto mock
HomeInstallationCreate mockCreate mock listCreate hydrated mockOptional interfacesUnion typesNote from the teamRegister mockExtensionTypes supportedTypes not supportedConfigPerformanceDefinitely TypedLocal development

Create hydrated mock

Do you need to mock optional properties or union types that may be undefined?
Say hello to createHydratedMock, it will help you create mocks that will treat optional interfaces as they were not optional

We currently support optional token (?) and union types that contains undefined.

Optional interfaces

import { createHydratedMock } from 'ts-auto-mock';
interface Person {
id?: string;
details?: {
phone?: number
}
}
const mock = createHydratedMock<Person>();
mock.id // ""
mock.details // { phone: 0 }

Union types

import { createHydratedMock } from 'ts-auto-mock';
interface Person {
getName(): string | undefined;
getSurname(): undefined | string;
}
const mock = createHydratedMock<Person>();
mock.getName() // ''
mock.getSurname() // ''

Note from the team

We completely understand the need of this functionality, but we would like the usage to be much simpler.
We would like to use the existing createMock in combination of typescript Required interface

import { createMock } from 'ts-auto-mock';
interface Person {
id?: string;
}
type Required<T> = { // from typescript lib
[P in keyof T]-?: T[P];
};
const mock = createMock<Required<Person>>();
mock.id // ""

Unfortunately this doesn't work because we don't fully support map types.