Skip to content

Instantly share code, notes, and snippets.

yield Nightmare()
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('.searchsubmit')
import test from 'ava'
test('arrays are equal', t => {
t.deepEqual([1, 2], [1, 2])
})
@vzaidman
vzaidman / ChildComponent.js
Last active January 14, 2019 16:43
react-lecture-why-did-you-render/01-the-demo
import React, {Component} from 'react'
class ChildComponent extends Component {
componentDidMount() {
console.log('ChildComponent Component Did Mount')
}
componentWillUnmount() {
console.log('ChildComponent Un-mount :*(')
@vzaidman
vzaidman / unit-test-example.js
Created February 1, 2019 13:43
unit-test-example
expect(fn(5)).to.be(10)
@vzaidman
vzaidman / integration-test-example.js
Last active February 5, 2019 03:59
integration-test-example
const flyDroneButton = document.getElementById('fly-drone-button')
flyDroneButton.click()
assert(isDroneFlyingCommandSent())
//or even
drone.checkIfFlyingViaBluetooth()
.then(isFlying => assert(isFlying))
@vzaidman
vzaidman / functional-tests.test
Created February 1, 2019 13:47
functional-tests
Go to page "https://localhost:3303"
Type "test-user" in the field "#username"
Type "test-pass" in the field "#password"
Click on "#login"
Expect Page Url to be https://localhost:3303/dashboard
# Install Karma:
npm install karma --save-dev
# Install plugins that your project needs:
npm install karma-jasmine jasmine-core karma-chrome-launcher karma-firefox-launcher --save-dev
# Run on
npx karma start karma.conf.js --log-level debug --single-run
@vzaidman
vzaidman / hook-fix.js
Last active April 5, 2019 10:01
hook-fix.js- Track Redundant Re-renders That Caused By Hooks With "Why Did You Render" version 3
if (hookState.num !== newHookState.num){
setHookState(newHookState)
}
@vzaidman
vzaidman / useNumState.js
Created April 5, 2019 10:01
useNumState - Track Redundant Re-renders That Caused By Hooks With "Why Did You Render" version 3
function useNumState(defState){
const [state, setState] = React.useState(defState)
function smartSetState(newState){
if(state.num !== newState.num){
setState(newState)
}
}
return [state, smartSetState]
@vzaidman
vzaidman / useReducer.js
Created April 5, 2019 10:02
useReducer.js - Track Redundant Re-renders That Caused By Hooks With "Why Did You Render" version 3
function reducer(state, action){
switch(action.type){
case 'broken-set-count':
return {count: action.payload.count}
case 'set-count':
if(action.payload.count === state.count){
return state
}