Realm.List inherited functions seem missing in jest test
See original GitHub issueSummary
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:
- Created 6 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top 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 >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 >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 FreeTop 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
Top GitHub Comments
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 offorEach
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.
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.