-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Realm.List inherited functions seem missing in jest test #1096
Comments
I met the same problem. what is the solution, in addition to the above method. Thanks. |
We ran into this exact issue today, but we needed |
@kneth, I don't think this issue is specific to jest per-se though it is very much related to how jest uses const assert = require('assert');
const vm = require('vm');
function main() {
const code = `
const Realm = require('realm');
const realm = new Realm({
schema: [
{
name: 'PersonList',
properties: {
list: 'PersonObject[]',
},
},
{
name: 'PersonObject',
properties: {
name: 'string',
age: 'double',
},
},
],
deleteRealmIfMigrationNeeded: true,
});
realm.write(() => realm.deleteAll());
let object;
realm.write(() => {
object = realm.create('PersonList', {list: [
{name: 'Ari', age: 10},
{name: 'Tim', age: 11},
{name: 'Bjarne', age: 12},
]});
});
const methods = [];
let current = object.list;
do {
methods.push(
...Object.getOwnPropertyNames(current).filter(prop => typeof object.list[prop] === 'function'));
} while ((current = Object.getPrototypeOf(current)));
realm.close();
new Set(methods);
`;
const methodsInNewContext = vm.runInNewContext(code, {console, require});
global.require = require;
const methodsInThisContext = vm.runInThisContext(code);
const difference = Array.from(
new Set(
[...methodsInThisContext].filter(x => !methodsInNewContext.has(x)))).sort();
assert.deepStrictEqual(difference, []);
}
main();
|
@kraenhansen You have a hypothesis why it isn't working, right? |
I believed we have a similar issue with 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. |
@peteroid We took some time to try and reproduce this issue and failed to reproduce it. Can you try updating Jest and Realm, to see if the issue is resolved? |
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. |
Summary
When I was testing my model under Realm using Jest, it seems some functions were missing. For instance,
map()
andkeys()
would be missing and the test will throw the error sayingTypeError: 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)
toRealm.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 objectActual results
Jest threw errors like
TypeError: xxx.map is not a function
Version
The text was updated successfully, but these errors were encountered: