Skip to content

Instantly share code, notes, and snippets.

View mheiber's full-sized avatar

Max Heiber mheiber

View GitHub Profile
// Test for Architecture 1
fetch = spy().andMockWith(function (args) {
// pattern matching and pretend games
})
assertSpyStuff
assertMoreSpyStuff
assertMoreSpyStuff
// Test for Architecture 2
assert.deepEqual(
buildRequest(x, y, z),
expectedRequest
)
assert.deepEqual(
parseResponse(response),
expectedParsedResponse

Are Mocks a Smell?

It's hard to write unit tests that are worth the costs our employers pay for them. I'll share two mostly-made-up diagrams then use them to justify writing code as data transformation.

Factual Diagrams

There are four types of code:

**Diagram 1: Types of Code**
@mheiber
mheiber / Similarities between MobX Observables and Rx Observables.md
Last active February 10, 2018 02:31
Similarities between MobX Observables and Rx Observables
MobX observable Rx Observable
has to do with things changing yes yes
"reactive" yes yes
@mheiber
mheiber / Differences between MobX Observables and Rx Observables.md
Last active February 10, 2018 03:32
Differences between MobX Observables and Rx Observables
MobX observable Rx Observable
common use case facilitating updating a UI when data changes composing frequently-updated data from multiple sources and/or implementing a lot of timing logic
better name is "sneaky KVO" "composable streams"
very similar to reactive data in Meteor and Vue Node streams if Node streams were always in object mode and had things like through2 and multipipe built in
implementation in JS requires
nnoremap <leader><space> :noh<return>
nnoremap <leader><leader> :b#<CR>
nnoremap <leader>S :source ~/.vimrc<CR>
nnoremap <leader>g :e ~/.vimrc<CR>
nnoremap <right> <C-w>10>
nnoremap <left> <C-w>10<
nnoremap <leader>1 :bp<Cr>
nnoremap <leader>2 :bp<Cr>
nnoremap <leader>] @:
:tnoremap <Esc> <C-\><C-n>
:tnoremap jj <C-\><C-n>
:tnoremap <C-w><C-w> <C-\><C-n><C-w><C-w>
:source ~/.vimrc
au TermOpen * setlocal nonumber norelativenumber
:nnoremap <leader>e <C-w><C-w>pa
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-commentary'
@mheiber
mheiber / private-names-in-nested-classes.js
Last active August 31, 2018 00:35
Private names in nested classes
class A {
#foo;
#bar;
method() {
class B {
#foo;
methodNested(a) {
a.#foo; // error: shadowed
a.#bar; // OK
}
@mheiber
mheiber / error cases for private names.md
Last active September 7, 2018 10:33
Error cases for private names

Three error cases for private name semantic errors:

  1. shadowing (the nested classes case). See also suggested error message.
  2. accessibility violation
  3. name not found

(1) and (2) are special cases of (3)

Confusing note on terminology: in the semantics, '#foo' is the description for a private name, what a Muggle would call a "spelling" and a philosophyer would call an "orthography." From a semantic point of view, the private name itself (#foo) is unforgeable and cannot be written down, even thought it's clear exactly where the private name node in the syntax is.

Rough algorithm for generating the most accurate error message for leftHandSide.#foo:

@mheiber
mheiber / bm.js
Last active October 5, 2018 13:34
closures
const main = () => {
const x = 2
const y = 3
;[1, 2, 3].forEach(v => {
console.log(v, y)
})
console.log(x, y)
}