Real unit test (isolation, no children render)
Calls:
- constructor
- render
| function counter(state = 0, action) { | |
| switch (action.type) { | |
| case 'INCREMENT': | |
| return state + 1 | |
| case 'DECREMENT': | |
| return state - 1 | |
| default: | |
| return state | |
| } | |
| } |
| function createStore(reducer, initialState) { | |
| var currentReducer = reducer; | |
| var currentState = initialState; | |
| var listener = () => {}; | |
| return { | |
| getState() { | |
| return currentState; | |
| }, | |
| dispatch(action) { |
| // Lazy (=on-demand) zip() | |
| for (const [i, x] of zip(naturalNumbers(), naturalNumbers())) { | |
| console.log(i, x); | |
| if (i >= 2) break; | |
| } | |
| // Output: | |
| // 0 0 | |
| // 1 1 | |
| // 2 2 |
| // UPDATE: In 2023, you should probably stop using this! The narrow version of Safari that | |
| // does not support `nomodule` is probably not being used anywhere. The code below is left | |
| // for posterity. | |
| /** | |
| * Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will | |
| * load <script nomodule> anyway. This snippet solve this problem, but only for script | |
| * tags that load external code, e.g.: <script nomodule src="nomodule.js"></script> | |
| * | |
| * Again: this will **not** prevent inline script, e.g.: |
| const composeMixins = (...fns) => ( | |
| obj = {}, | |
| piped = x => fns.reduce((o, fn) => fn(o), x) | |
| ) => piped(obj); | |
| const user = { | |
| name: 'kos', | |
| email: 'test@test.com', | |
| }; |
| console.log(1); | |
| (_ => console.log(2))(); | |
| eval('console.log(3);'); | |
| console.log.call(null, 4); | |
| console.log.apply(null, [5]); | |
| new Function('console.log(6)')(); | |
| Reflect.apply(console.log, null, [7]) | |
| Reflect.construct(function(){console.log(8)}, []); | |
| Function.prototype.apply.call(console.log, null, [9]); | |
| Function.prototype.call.call(console.log, null, 10); |
| # Name it whatever you want. I like `y` because in my keyboard layout it's close to `;` | |
| function y() { | |
| previous=$? | |
| if [ $previous -eq 0 ]; then | |
| osascript -e "display notification \"Done\" with title \"Terminal Task\"" && say "it is done"; | |
| else | |
| osascript -e "display notification \"Failed\" with title \"Terminal Task\"" && say "it went to the trees"; | |
| fi | |
| } |
| import React, { Component } from 'react' | |
| import logo from './logo.svg' | |
| import './App.css' | |
| import { Route, Link, Redirect } from './Zero' | |
| const paths = [ 'one', 'two', 'three' ] | |
| class App extends Component { | |
| render() { |
| const MODULE_DIR = /(.*([\/\\]node_modules|\.\.)[\/\\](@[^\/\\]+[\/\\])?[^\/\\]+)([\/\\].*)?$/g; | |
| { | |
| loader: 'babel-loader', | |
| test: /\.jsx?$/, | |
| include(filepath) { | |
| if (filepath.split(/[/\\]/).indexOf('node_modules')===-1) return true; | |
| let pkg, manifest = path.resolve(filepath.replace(MODULE_DIR, '$1'), 'package.json'); | |
| try { pkg = JSON.parse(fs.readFileSync(manifest)); } catch (e) {} | |
| return !!(pkg.module || pkg['jsnext:main']); |