Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,13 @@
expect(evaluateJsonModule('\uFEFF' + source)).toEqual(JSON.parse(source));
}

const value: $FlowFixMe = evaluateJsonModule(sources[0]);
const value = evaluateJsonModule(sources[0]);
if (typeof value !== 'object' || value === null) {

Check warning on line 208 in packages/metro/src/ModuleGraph/worker/__tests__/JsFileWrapping-test.js

View workflow job for this annotation

GitHub Actions / Type check, lint, format, smoke test

Always use `== null` or `!= null` to check for `null` AND `undefined` values (even if you just expect either of them). Within fb we treat them as equal and `== null` checks for both

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this warning is expected

throw new Error('Expected the JSON module to export an object');
}
expect(Object.keys(value)).toEqual(['__proto__', 'a']);
expect(value.x).toBeUndefined();
// `in` also sees inherited properties, so this catches a polluted prototype.
expect('x' in value).toBe(false);
});

test('keeps JSON without a `__proto__` key as an object literal', () => {
Expand Down
Loading