redwood: Generated Test Cases Failing Due to Formatting of Compared Values
I get the following when running a test case on a model that has a field defined as a float. The value expected and the value received appear to be almost the same, but reporting back with a different number of decimal places.
FAIL api api/src/services/sites/sites.test.ts (9.202 s)
● sites › creates a site
expect(received).toEqual(expected) // deep equality
Expected: 1498892.0256940164
Received: 1498892.025694016
35 | expect(result.country).toEqual('String')
36 | expect(result.state).toEqual('String')
> 37 | expect(result.latitude).toEqual(1498892.0256940164)
| ^
38 | expect(result.latitudeMin).toEqual(7235317.275571931)
39 | expect(result.latitudeSec).toEqual(3107701.7253994453)
40 | expect(result.longitude).toEqual(9815030.723403068)
at src/services/sites/sites.test.ts:37:29
at Object.<anonymous> (../node_modules/@redwoodjs/testing/config/jest/api/jest.setup.js:84:16)
model
model Site {
id Int @id @default(autoincrement())
name String
description String
country String
state String
latitude Float
latitudeMin Float
latitudeSec Float
longitude Float
longitudeMin Float
longitudeSec Float
events EventsOnSite[]
}
I experience a similar issue on Decimal fields. But in that case, its comparing a string to a decimal value.
FAIL api api/src/services/roles/roles.test.ts (8.072 s)
● roles › creates a role
expect(received).toEqual(expected) // deep equality
Expected: 7420440.088194787
Received: "7420440.088194787"
26 | expect(result.name).toEqual('String')
27 | expect(result.description).toEqual('String')
> 28 | expect(result.expectedPay).toEqual(7420440.088194787)
| ^
29 | })
30 |
31 | scenario('updates a role', async (scenario: StandardScenario) => {
at src/services/roles/roles.test.ts:28:32
at runMicrotasks (<anonymous>)
at Object.<anonymous> (../node_modules/@redwoodjs/testing/config/jest/api/jest.setup.js:84:16)
I haven’t made any edits to the generated files, which were created via yarn rw generate scaffold <model>
Windows 11 Redwood 0.37.4
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (15 by maintainers)
re: DateTime
Primsa returns DateTime as ISO 8601-formatted strings. So, you can convert the date to ISO String in JavaScript:
The given output is the same received from Prisma.
My first step would be to reproduce the issue on my end and will try to think of a solution for a better developer experience.
Looks like I get this problem on some DateTime fields too.
model