Closed clintonb closed 1 month ago
This also impacts usage of formData
since the Date
needs to be converted to a string
.
I can work around the mock issue with an override:
module.exports = {
api: {
mock: true,
override: {
useDates: true,
mock: {
format: {
date: () => faker.date.recent(),
'date-time': () => faker.date.recent(),
},
},
},
}
};
module.exports = {
api: {
mock: true,
override: {
useDates: true,
formData: {
path: './src/api/custom-form-data.ts',
name: 'customFormData',
},
},
}
};
export const customFormData = <Body>(body: Body): FormData => {
const formData = new FormData()
Object.entries(body).forEach(([key, value]) => {
// Ensure we encode dates as strings
if (value instanceof Date) {
value = value.toISOString()
}
formData.append(key, value)
})
return formData
}
export default customFormData
Nice solution!
What are the steps to reproduce this issue?
useDates: true
andmock: true
.What happens?
The mocks use faker for the mocked values, but convert the fake
Date
to astring
.What were you expecting to happen?
The mocked data should be a
Date
.What versions are you using?
Package Version: 6.31.0