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.

Realm.List inherited functions seem missing in jest test

See original GitHub issue

Summary

When I was testing my model under Realm using Jest, it seems some functions were missing. For instance, map() and keys() would be missing and the test will throw the error saying TypeError: xxx.map is not a function. However, this error only happens in the jest but not in the normal execution.

After some trials, I found that replacing the map function from xxx.map(fn) to Realm.List.prototype.map.call(xxx, fn) could be working in both the jest test and normal execution.

Expected results

map function should be defined in the List object

Actual results

Jest threw errors like TypeError: xxx.map is not a function

Version

  • realm: 1.3.1
  • node: 7.10.0
  • jest: 20.0.4

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
kraenhansencommented, Oct 17, 2019

@kraenhansen You have a hypothesis why it isn’t working, right?

I believed we have a similar issue with for(let ... of ...) loop on React Native. Originating from the way Realm JS is looping over the methods to export here: https://github.com/realm/realm-js/blob/master/lib/collection-methods.js#L49. I have a suspicion that some environments call the callback of forEach asynchronously.

But … reading over the Jest issues, that you @kneth linked to, this does indeed seem like a known Jest bug. Perhaps a workaround could be found, but it seems more valuable to get the root cause fixed.

0reactions
takameyercommented, Feb 16, 2022

The issues has been closed, as we are not able to reproduce it and no one in the community has reported that it is still an issue. If someone is seeing this issue, feel free to yell and we will reopen the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocking Inherited Classes with Jest - node.js - Stack Overflow
I think inheritance makes the solution much cleaner. But more difficult to test. The cleaner the code, the easier to test, to paraphrase...
Read more >
Jest Tutorial for Beginners: Getting Started With JavaScript ...
Learn the basics of testing JavaScript with this Jest tutorial for beginners! ... you inherit legacy code which comes without tests ...
Read more >
Troubleshooting - Jest
Troubleshooting. Uh oh, something went wrong? Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​.
Read more >
FAQs - styled-components
Commonly asked questions about styled-components.
Read more >
JUnit 5 User Guide
Such annotations are not inherited. @Tag. Used to declare tags for filtering tests, either at the class or method level; analogous to test...
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