File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 1+ import { test } from 'node:test' ;
2+ import assert from 'node:assert' ;
3+ import { createFactory } from './main.ts' ;
4+
5+ type Person = {
6+ readonly name : string ;
7+ } ;
8+
9+ await test ( 'build() returns the given factory object as is' , ( ) => {
10+ const factory = createFactory < Person > ( ( ) => {
11+ return {
12+ name : 'John Doe'
13+ } ;
14+ } ) ;
15+
16+ const actual = factory . build ( ) ;
17+
18+ assert . deepStrictEqual ( actual , { name : 'John Doe' } ) ;
19+ } ) ;
Original file line number Diff line number Diff line change 1- export function main ( ) : string {
2- return '' ;
1+ type ObjectoryFactory < ObjectShape > = {
2+ readonly build : ( ) => ObjectShape ;
3+ } ;
4+
5+ type GeneratorFunction < ObjectShape > = ( ) => ObjectShape ;
6+
7+ export function createFactory < ObjectShape extends Record < string , unknown > > (
8+ generatorFunction : GeneratorFunction < ObjectShape >
9+ ) : ObjectoryFactory < ObjectShape > {
10+ return {
11+ build : generatorFunction
12+ } ;
313}
You can’t perform that action at this time.
0 commit comments