Jest – Mock a constant property from a module for a specific test

File that exports a constant value that I want to mock: // utils/deviceTypeUtils file import DeviceInfo from ‘react-native-device-info’; export const isTablet = DeviceInfo.isTablet(); In my test file, I use this code to mock the constant isTablet: // file: deviceTypeUtils.spec const DeviceTypeUtilsMock = jest.requireMock(‘../utils/deviceTypeUtils’); jest.mock(‘../utils/deviceTypeUtils’, () => ({ isTablet: false, })); describe(‘mock const example’, () => … Read more

Property ‘innerText’ does not exist on type ‘Element’

You can fix it like this: const data = await page.$eval(selector, node => (node as HTMLElement).innerText); or: const data = await page.$eval(selector, node => (<HTMLElement>node).innerText); UPDATE: So, after some exchange on Github, it’s clear why the syntax from this question does not work. It actually defines anonymous generic function. <HTMLElement>(node: HTMLElement) => node.innerText Clearer example … Read more

Is there anyway to do nested Pick types in Typescript

Similar to Colins answer, but coming at it from the opposite direction. If you have an existing interface/type you need to pick apart you can use indexes: // Existing type type Tenant = { id:string; description:string; name:string; approvedUsers: Array<{ id:string; alias:string; }> } // Pick it apart type TenantManagePageQueryTenant = Pick<Tenant, ‘id’ | ‘description’ | … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)