diff --git a/src/__test__/ghii.test.ts b/src/__test__/ghii.test.ts index a72301a..965fda1 100644 --- a/src/__test__/ghii.test.ts +++ b/src/__test__/ghii.test.ts @@ -161,13 +161,14 @@ describe('Ghii Config', () => { describe('history and version', () => { it('have empty history and latestVersion if no snapshot is taken', () => { - const target = Ghii<{ a: { test: 'string' } }>().section('a', { + const target = Ghii<{ a: { test: 'string' | 'defaults' } }>().section('a', { validator: joi => joi.string(), + defaults: { test: 'defaults' }, }); expect(target.history()).toStrictEqual([]); expect(target.latestVersion()).toBeUndefined(); - expect(target.snapshot()).toBeUndefined(); + expect(target.snapshot()).toStrictEqual({ a: { test: 'defaults' } }); }); it('have history and latestVersion if snapshot is taken', () => { diff --git a/src/ghii.ts b/src/ghii.ts index efd9e2a..7403436 100644 --- a/src/ghii.ts +++ b/src/ghii.ts @@ -16,7 +16,7 @@ export type GhiiInstance = { loader: (this: GhiiInstance, loader: Loader) => GhiiInstance; takeSnapshot: () => Promise<{ [key in keyof O]: O[key] }>; history: () => SnapshotVersion[]; - snapshot: (newSnapshot?: Snapshot) => O | undefined; + snapshot: (newSnapshot?: Snapshot) => O; latestVersion: () => SnapshotVersion | undefined; waitForFirstSnapshot: (moduleToLoad: string) => Promise; on: ValueOf>, 'on'>>; @@ -122,7 +122,7 @@ export function ghii(): GhiiInstance { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion events.emit('ghii:version:new', latestVersion()!); } - return latestVersion()?.value; + return latestVersion()?.value ?? prepareDefaults(sections); } function waitForFirstSnapshot(moduleToLoad: string) {