TypeScript ES6 import module “File is not a module error”

Extended – to provide more details based on some comments The error Error TS2306: File ‘test.ts’ is not a module. Comes from the fact described here http://exploringjs.com/es6/ch_modules.html 17. Modules This chapter explains how the built-in modules work in ECMAScript 6. 17.1 Overview In ECMAScript 6, modules are stored in files. There is exactly one module … Read more

How to mock imported named function in Jest when module is unmocked

Use jest.requireActual() inside jest.mock() jest.requireActual(moduleName) Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. Example I prefer this concise usage where you require and spread within the returned object: // myModule.test.js import { otherFn } from ‘./myModule.js’ jest.mock(‘./myModule.js’, () => ({ …(jest.requireActual(‘./myModule.js’)), … Read more

In React ES6, why does the input field lose focus after typing a character?

it is because you are rendering the form in a function inside render(). Every time your state/prop change, the function returns a new form. it caused you to lose focus. Try putting what’s inside the function into your render directly. <main id=”main” role=”main”> <div className=”container-fluid”> <FormPostSingle /> </div> </main> ===> <main id=”main” role=”main”> <div className=”container-fluid”> … Read more

Does ECMAScript 6 have a convention for abstract classes? [duplicate]

ES2015 does not have Java-style classes with built-in affordances for your desired design pattern. However, it has some options which may be helpful, depending on exactly what you are trying to accomplish. If you would like a class that cannot be constructed, but whose subclasses can, then you can use new.target: class Abstract { constructor() … Read more

Why can I change a constant object in javascript

The documentation states: …constant cannot change through re-assignment …constant cannot be re-declared When you’re adding to an array or object you’re not re-assigning or re-declaring the constant, it’s already declared and assigned, you’re just adding to the “list” that the constant points to. So this works fine: const x = {}; x.foo = ‘bar’; console.log(x); … Read more

What is the temporal dead zone?

let and const have two broad differences from var: They are block scoped. Accessing a var before it is declared has the result undefined; accessing a let or const before it is declared throws ReferenceError: console.log(aVar); // undefined console.log(aLet); // Causes ReferenceError: Cannot access ‘aLet’ before initialization var aVar = 1; let aLet = 2; … Read more