Skip to content

Commit

Permalink
test: Mocked sub-object airport example
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian-McBride committed Jun 30, 2023
1 parent 2d82779 commit 6d910a1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/zod-mock/src/lib/zod-mock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,36 @@ describe('zod-mock', () => {
expect(first).toEqual(second);
expect(first).not.toEqual(third);
});

it(`Will mock sub objections properly`, () => {
const airline = z.object({
flightNumber: z.string(),
departure: z.object({
airport: z.string(),
time: z.date(),
}),
arrival: z.object({
airport: z.string(),
time: z.date(),
}),
});

const flight = z.object({
operating_airline: airline,
marketing_airline: airline,
});

const mockedFlight = generateMock(flight, {
stringMap: {
airport: () => faker.airline.airport().iataCode,
},
});

expect(mockedFlight.operating_airline.departure.airport.length).toEqual(3);
expect(mockedFlight.operating_airline.arrival.airport.length).toEqual(3);
expect(mockedFlight.marketing_airline.departure.airport.length).toEqual(3);
expect(mockedFlight.marketing_airline.arrival.airport.length).toEqual(3);
expect(mockedFlight.operating_airline.departure.time).toBeInstanceOf(Date);
expect(mockedFlight.operating_airline.flightNumber.length).toBeLessThan(5);
});
});

0 comments on commit 6d910a1

Please sign in to comment.