- Install:
- jest:
npm install --save-dev jest - ts-jest:
npm install --save-dev ts-jest @types/jest
- Modify package.json
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
| document.addEventListener('touchstart', handleTouchStart, false); | |
| document.addEventListener('touchmove', handleTouchMove, false); | |
| var xDown = null; | |
| var yDown = null; | |
| function getTouches(evt) { | |
| return evt.touches || // browser API | |
| evt.originalEvent.touches; // jQuery | |
| } |
| const offset = 100; | |
| let xDown, yDown; | |
| window.addEventListener('touchstart', e => { | |
| const firstTouch = getTouch(e); | |
| xDown = firstTouch.clientX; | |
| yDown = firstTouch.clientY; | |
| }); |
| @media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ } | |
| @media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ } | |
| @media (min-width:600px) { /* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */ } | |
| @media (min-width:801px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ } | |
| @media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ } | |
| @media (min-width:1281px) { /* hi-res laptops and desktops */ } |
| import React, { Component } from 'react'; | |
| export default function withPropsChecker(WrappedComponent) { | |
| return class PropsChecker extends Component { | |
| componentWillReceiveProps(nextProps) { | |
| Object.keys(nextProps) | |
| .filter(key => { | |
| return nextProps[key] !== this.props[key]; | |
| }) | |
| .map(key => { |
| const movies = { | |
| action: ['dark', 'aveng'], | |
| comedy: ['life', 'lights'], | |
| [Symbol.iterator]*() { | |
| for (let movies of Object.values(this)) { | |
| // option 1: | |
| for (let movie of movies) { | |
| yield movie; | |
| } | |
| // option 2 (see https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Statements/function* for details): |
| import React, { Component } from 'react'; | |
| class ErrorBoundary extends Component { | |
| state = { | |
| hasError: false, | |
| errorMessage: '' | |
| } | |
| componentDidCatch = (error, info) => { | |
| this.setState({hasError: true, errorMessage: error}); |
| const puppeteer = require('puppeteer'); | |
| let scrape = async () => { | |
| const browser = await puppeteer.launch({headless: false}); | |
| const page = await browser.newPage(); | |
| await page.goto('http://books.toscrape.com/'); | |
| await page.click('#default > div > div > div > div > section > div:nth-child(2) > ol > li:nth-child(1) > article > div.image_container > a > img'); | |
| await page.waitFor(1000); |