Title: why I don't need to import related modules?
Tags: javascript;reactjs;jestjs
Question: I'm new to React, sorry if my questions sound dumb. I'm using npx create-react-app to create React app. But I don't know what's going on behind the scenes:
Q1-If I throw an error in a component like:
import React, { Component } from "react";
render() {
throw new Error("something went wrong");
I didn't import the Error name feature from any modules, where does Error come from? How could I use it directly without importing any related modules like:
import Error from "XXX";
Q2-When an react app is created, there is a test file called app.test.js, inside this file, there is a function called it() as"
it('renders without crashing', () =&gt; {
...
so where does it from? and again why I doesn't need to import any module to use it?


Here is another answer: Error is pure JS functionality which is why you don't need to import as it part of your javaScript engine.
Learn more about this
It is part of your test framework. If you are using Jest/jasmine whatever. Whenever you run test cases, all test frameworks method is globally available in your current browser session where test cases are running. so does not require.

Here is another answer: Error is JavaScript's default object, you can read more about it here.
it is the global variable of jest framework.see this.
You don't have to import the global variables and methods which the framework or language provides.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:11/05/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><reactjs><jestjs>', 'Title': "why I don't need to import related modules?", 'ViewCount': 55, 'id': 58709955, 'user_AboutMe': None, 'user_AccountId': 13332616.0, 'user_DisplayName': 'amjad', 'user_Reputation': 3208.0, 'user_Views': 641.0, 'user_id': 9623401.0}}