-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/#203 support nullable nested objects #219
base: main
Are you sure you want to change the base?
Feat/#203 support nullable nested objects #219
Conversation
… accept 'Object' type re mswjs#203
…using exisiting type AnyObject Change the definition of ModelValueType from 'Object' to 'AnyObject' (an existing type of the library) re 203
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
node 'node_modules/.bin/jest' '/Users/aloysberger/FOSS/data/test/model/create.test.ts' -c '/Users/aloysberger/FOSS/data/test/jest.config.ts' -t 'supports nested nullable object' --runInBand re mswjs#203
…bjects Update tests to cover nested nullable objects re mswjs#203
return ( | ||
isPrimitiveValueType(value) || | ||
Array.isArray(value) || | ||
typeof value === 'object' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsure if this is too permissive?
Nice one, can we get it merged? |
Hi there! 👋 I've also tried to tackle that one. I think that there may be some parts missing, when for example we'd like to have some default value for nullable object property const db = factory({
user: {
id: primaryKey(faker.datatype.uuid),
address: nullable(() => ({
street: () => "Wall Street",
number: nullable<number>(() => null),
})),
},
});
const user = db.user.create(); we may want to have something like {
"id": "...",
"address": {
"street": "Wall Street",
"number": null
}
} for Also, if you run all tests, you may see that there are some issues with types in I created #231 with some investigation I've made some time ago and finished today. Maybe you could take a look there, because you're familiar with the problem and we could figure out some working solution together? |
Hi @roertbb, sorry I was quite busy, I'll have a look at your code and get back to you ASAP 👍 |
This is regarding issue #203
I have extended the existing
ModelValueType
and the functionisModelValueType
to allow forobject
type.I also added a new test case covering the scenario described in #203 .
It was indeed failing at the beginning, the object would be null no matter whether or not you passed to create an existing object.
This was caused by
isModelValueType
that would returnfalse
if the object was not a Primitive or an Array of Primitives.The test is now passing, and I've also tested it manually.
Note that this is my PR for this project and unfortunately the tests were not all green out of the box. So I manually checked where these functions/types were used to ensure I didn't break existing functionalities.
Please don't hesitate to let me know if anything needs to be changed.