Skip to content

Instantly share code, notes, and snippets.

Writing tests for validators

I've broken down the validation architecture in to its absolute simplest form so we can use it to understand and compare testing approaches.

The validation architecture

Let's say we have a set of simple validation functions that fail whatever you pass in:

validations.js

@joelove
joelove / form-validators.md
Created July 24, 2018 14:09
Form Validators

Form validators

Form validators are comprised of validation rules. Each of these rules receive:

  • The name of a field or collection to validate
  • A unique, human-readable key to describe the validation
  • A function that validates the field or collection
  • An optional function to validate the entire form data object
  • An optional function to combine the results of the main validation result and the form data validation result
@alexeygrigorev
alexeygrigorev / vimeo-download.py
Created September 17, 2016 09:09
Downloading segmented video from vimeo
import requests
import base64
from tqdm import tqdm
master_json_url = 'https://178skyfiregce-a.akamaihd.net/exp=1474107106~acl=%2F142089577%2F%2A~hmac=0d9becc441fc5385462d53bf59cf019c0184690862f49b414e9a2f1c5bafbe0d/142089577/video/426274424,426274425,426274423,426274422/master.json?base64_init=1'
base_url = master_json_url[:master_json_url.rfind('/', 0, -26) + 1]
resp = requests.get(master_json_url)
content = resp.json()
@nuflowx
nuflowx / Remove black bars from video
Last active July 29, 2016 01:09
Get rid of the black bars of embeded youtube or similar video with CSS media queries
If you don't want the black bars on a video in your site these might do the trick for you:
```
@media all and (min-aspect-ratio: 16/9) {
.video {
width: 100vw;
height: calc(100vw * (9/16));
}
}
@media all and (max-aspect-ratio: 16/9) {
@alexpchin
alexpchin / socket-cheatsheet.js
Created December 15, 2015 16:58
A quick cheatsheet for socket.io
// sending to sender-client only
socket.emit('message', "this is a test");
// sending to all clients, include sender
io.emit('message', "this is a test");
// sending to all clients except sender
socket.broadcast.emit('message', "this is a test");
// sending to all clients in 'game' room(channel) except sender
@patik
patik / how-to-squash-commits-in-git.md
Last active May 30, 2024 07:59
How to squash commits in git

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date: