Generated Test Cases Failing Due to Formatting of Compared Values
See original GitHub issueI 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (15 by maintainers)
Top Results From Across the Web
Enhance test.each message format · Issue #6413 · facebook/jest
Enhance test.each message format: positional placeholders such as %2$s ... the interpolated values are enough to identify the failing tests.
Read more >JavaScript ES6 Intl not working properly when running Jest tests
To make this work on a project created by using create-react-app you have to follow almost the same steps; the only step that...
Read more >Jest Test "Compared values have no visual difference."
The test fails with the error Compared values have no visual difference . To understand what is going on I recommend to log...
Read more >What is Test Data? Test Data Preparation Techniques with ...
In this tutorial, I will provide tips on how to prepare test data so any important test case will not be missed by...
Read more >Unit test reports - GitLab Docs
Newly failed tests: Test cases which passed on the base branch and failed on the ... to generate a JUnit report format XML...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.