question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated Test Cases Failing Due to Formatting of Compared Values

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
aggmoulikcommented, Oct 29, 2021

redwood_info We can add the exceptions like this as it needed attention by developers and it will be easy to find.

1reaction
aggmoulikcommented, Oct 21, 2021

re: DateTime

Primsa returns DateTime as ISO 8601-formatted strings. So, you can convert the date to ISO String in JavaScript:

const isoString = new Date("2021-10-15T19:40:33Z").toISOString() //  Output: '2021-10-15T19:40:33.000Z'

The given output is the same received from Prisma.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found