Jest / Enzyme – How to test at different viewports?

Background Information: jsdom does not implement window.resizeBy() or window.resizeTo() jsdom defines the window innerWidth and innerHeight to be 1024 x 768 It is possible to simulate a window resize using jsdom by manually setting window.innerWidth and window.innerHeight and firing the resize event Here is an example: comp.js import * as React from ‘react’; export default … Read more

How to mock navigator.clipboard.writeText() in Jest?

Jest tests are running in JSdom environment and not all of the properties are defined, but so you should define the function before spying on it. Here is an example: const writeText = jest.fn() Object.assign(navigator, { clipboard: { writeText, }, }); describe(“Clipboard”, () => { describe(“writeText”, () => { beforeAll(() => { navigator.clipboard.writeText.mockResolvedValue(undefined) // or … Read more

Scrape a webpage and navigate by clicking buttons

Zombie.js and Node.io run on JSDOM, hence your options are either going with JSDOM (or any equivalent wrapper), a headless browser (PhantomJS, SlimerJS) or Cheerio. JSDOM is fairly slow because it has to recreate DOM and CSSOM in Node.js. PhantomJS/SlimerJS are proper headless browsers, thus performances are ok and those are also very reliable. Cheerio … Read more

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