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

Commit

Permalink
test(nullable object): recreate issue scenario in the test
Browse files Browse the repository at this point in the history
when using nullable<MyObject>( ... ), it is impossible to provide an object. It returns 'null' no
matter whether an object has been provided or not.

re 203
  • Loading branch information
Aloys Berger committed May 22, 2022
1 parent 2c9d39c commit 9f9c1a6
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/model/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,56 @@ test('creates a new entity with nullable properties', () => {
expect(user.address.number).toEqual(null)
})

test('supports nested nullable object', () => {
type Car = {
brand: string
model: string
}

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

const DIDDY = {
id: '🐵',
name: 'Diddy',
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,
})

expect(diddyUser.id).toEqual(DIDDY.id)
expect(diddyUser.name).toEqual(DIDDY.name)
expect(diddyUser.car).toEqual(DIDDY.car)

const DONKEY = {
id: '🦍',
name: 'Donkey',
car: null,
}

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

expect(donkeyUser.id).toEqual(DONKEY.id)
expect(donkeyUser.name).toEqual(DONKEY.name)
expect(donkeyUser.car).toEqual(DONKEY.car)
})

test('supports nested objects in the model definition', () => {
const db = factory({
user: {
Expand Down

0 comments on commit 9f9c1a6

Please sign in to comment.