Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
test(update test nullable object): update tests for nested nullable o…
Browse files Browse the repository at this point in the history
…bjects

Update tests to cover nested nullable objects

re mswjs#203
  • Loading branch information
Aloys Berger committed May 22, 2022
1 parent 6d19c2c commit d53d31c
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions test/model/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,49 +102,63 @@ test('supports nested nullable object', () => {
brand: string
model: string
}
type Bike = Car

const db = factory({
user: {
id: primaryKey(datatype.uuid),
name: name.findName,
car: nullable<Car>(() => null),
vehicule: {
car: nullable<Car>(() => null),
bike: nullable<Bike>(() => null),
},
},
})

const DIDDY = {
id: '🐵',
name: 'Diddy',
car: {
brand: 'Diddy Kong',
model: 'Super Racing Model with extra 🍌 carriage',
vehicule: {
car: {
brand: 'Diddy Kong',
model: 'Super Racing Model with extra 🍌 carriage',
},
},
}

const diddyUser = db.user.create({
id: DIDDY.id,
name: DIDDY.name,
car: DIDDY.car,
vehicule: { car: DIDDY.vehicule.car },
})

expect(diddyUser.id).toEqual(DIDDY.id)
expect(diddyUser.name).toEqual(DIDDY.name)
expect(diddyUser.car).toEqual(DIDDY.car)
expect(diddyUser.vehicule.car).toEqual(DIDDY.vehicule.car)
expect(diddyUser.vehicule.bike).toEqual(null)

const DONKEY = {
id: '🦍',
name: 'Donkey',
car: null,
vehicule: {
car: null,
bike: {
brand: 'Donkey Kong Choppers',
model: 'Chuck Norris, the fastest',
},
},
}

const donkeyUser = db.user.create({
id: DONKEY.id,
name: DONKEY.name,
car: DONKEY.car,
vehicule: DONKEY.vehicule,
})

expect(donkeyUser.id).toEqual(DONKEY.id)
expect(donkeyUser.name).toEqual(DONKEY.name)
expect(donkeyUser.car).toEqual(DONKEY.car)
expect(donkeyUser.vehicule.bike).toEqual(DONKEY.vehicule.bike)
expect(donkeyUser.vehicule.car).toEqual(null)
})

test('supports nested objects in the model definition', () => {
Expand Down

0 comments on commit d53d31c

Please sign in to comment.