\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Andrey (apk)} \pdfinfo{ /Title (javascript-unit-testing-tools.pdf) /Creator (Cheatography) /Author (Andrey (apk)) /Subject (JavaScript unit testing tools Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{JavaScript unit testing tools Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Andrey (apk)} via \textcolor{DarkBackground}{\uline{cheatography.com/6656/cs/6151/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Andrey (apk) \\ \uline{cheatography.com/apk} \\ \uline{\seqsplit{kucherenko}.org/} \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 21st November, 2015.\\ Updated 11th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Chai.js should}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.equal(expected)}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.eql(expected)}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.deep.equal(expected)} // same as .eql} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.be.a('string')}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.include(val)}} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{object.should.be.ok(val)} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{object.should.be.true} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{object.should.be.false} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{object.should.be.null} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.be.undefined}} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{object.should.be.empty} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.be.arguments}} \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.be.function}} \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.be.instanceOf}} \tn % Row Count 14 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{object.should.gt(5) \# or .above .greaterThan} \tn % Row Count 15 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{object.should.gte \# or .at.least} \tn % Row Count 16 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{object.should.lt(5) \# or .below} \tn % Row Count 17 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.respondTo('bar')}} \tn % Row Count 18 (+ 1) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{object.should.satisfy (n) -\textgreater{} n \textgreater{} 0} \tn % Row Count 19 (+ 1) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{object.should.have.members({[}2, 3, 4{]})} \tn % Row Count 20 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{object.should.have.keys({[}'foo'{]})} \tn % Row Count 21 (+ 1) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{object.should.have.key('foo')}} \tn % Row Count 22 (+ 1) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{object.should.exist} \tn % Row Count 23 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`require('chai').should();`} \newline `//actually call the function, add "should" method to prototype of object`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Chai.js expect}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).equal(expected)}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).eql(expected)}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).deep.equal(expected)} // same as .eql} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).be.a('string')}} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).include(val)}} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).be.ok(val)}} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(object).be.true} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expect(object).be.false} \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(object).be.null} \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).be.undefined}} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(object).be.empty} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).be.arguments}} \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).be.function}} \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).be.instanceOf}} \tn % Row Count 15 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(object).gt(5) \# or .above .greaterThan} \tn % Row Count 16 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expect(object).gte \# or .at.least} \tn % Row Count 17 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(object).lt(5) \# or .below} \tn % Row Count 18 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).respondTo('bar')}} \tn % Row Count 19 (+ 1) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(object).satisfy (n) -\textgreater{} n \textgreater{} 0} \tn % Row Count 20 (+ 1) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expect(object).have.members({[}2, 3, 4{]})} \tn % Row Count 21 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(object).have.keys({[}'foo'{]})} \tn % Row Count 22 (+ 1) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(object).have.key('foo')}} \tn % Row Count 23 (+ 1) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(object).exist} \tn % Row Count 24 (+ 1) % Row 23 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expect(object).(-\textgreater{} ...).throw /not a function/} \tn % Row Count 25 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`var expect = require('chai').expect;`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Chai.js asserts}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert(val)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.fail(actual, expected)} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.ok(val) // is truthy} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.equal(actual, expected) // 'compare with =='} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.strictEqual} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.deepEqual} \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.isTrue} \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.isFalse} \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.isNull} \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.isNotNull} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.isUndefined} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.isDefined} \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.isFunction} \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.isObject} \tn % Row Count 15 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.isArray} \tn % Row Count 16 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.isString} \tn % Row Count 17 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.isNumber} \tn % Row Count 18 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.isBoolean} \tn % Row Count 19 (+ 1) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.typeOf(/tea/, 'regexp') // \seqsplit{Object.prototype.toString()}} \tn % Row Count 21 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.instanceOf(chai, Tea)} \tn % Row Count 22 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.include({[} a,b,c {]}, a)} \tn % Row Count 23 (+ 1) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.match(val, /regexp/)} \tn % Row Count 24 (+ 1) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.property(obj, 'tea') // 'tea' in object} \tn % Row Count 25 (+ 1) % Row 23 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.deepProperty(obj, 'tea.green')} \tn % Row Count 26 (+ 1) % Row 24 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{assert.propertyVal(person}, 'name', 'John')} \tn % Row Count 27 (+ 1) % Row 25 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{assert.deepPropertyVal(post}, 'author.name', 'John')} \tn % Row Count 29 (+ 2) % Row 26 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.lengthOf(object, 3)} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Chai.js asserts (cont)}} \tn % Row 27 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.throws(function() \{ ... \})} \tn % Row Count 1 (+ 1) % Row 28 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.doesNotThrow} \tn % Row Count 2 (+ 1) % Row 29 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{assert.operator(1, '\textless{}', 2)} \tn % Row Count 3 (+ 1) % Row 30 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{assert.closeTo(actual, expected)} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`var assert = require('chai').assert`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon-chai}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(spy).called} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expect(spy).calledOnce} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expect(spy).calledTwice} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expect(spy).calledThrice} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).calledBefore(spy2)}} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).calledAfter(spy2)}} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).calledWithNew}} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).alwaysCalledWithNew}} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).calledOn(context)}} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).alwaysCalledOn(context)}} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).calledWith(...args)}} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).alwaysCalledWith(...args)}} \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).calledWithExactly(...args)}} \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).alwaysCalledWithExactly(...args)}} \tn % Row Count 14 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).calledWithMatch(...args)}} \tn % Row Count 15 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).alwaysCalledWithMatch(...args)}} \tn % Row Count 16 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).returned(val)}} \tn % Row Count 17 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).alwaysReturned(val)}} \tn % Row Count 18 (+ 1) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).threw(errorObjOrErrorTypeStringOrNothing)}} \tn % Row Count 20 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expect(spy).alwaysThrew(errorObjOrErrorTypeStringOrNothing)}} \tn % Row Count 22 (+ 2) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.been.called}} \tn % Row Count 23 (+ 1) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.been.calledOnce}} \tn % Row Count 24 (+ 1) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.been.calledTwice}} \tn % Row Count 25 (+ 1) % Row 23 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.been.calledThrice}} \tn % Row Count 26 (+ 1) % Row 24 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy1.should.have.been.calledBefore(spy2)}} \tn % Row Count 27 (+ 1) % Row 25 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy1.should.have.been.calledAfter(spy2)}} \tn % Row Count 28 (+ 1) % Row 26 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.been.calledWithNew}} \tn % Row Count 29 (+ 1) % Row 27 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.always.have.been.calledWithNew}} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon-chai (cont)}} \tn % Row 28 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.been.calledOn(context)}} \tn % Row Count 1 (+ 1) % Row 29 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.always.have.been.calledOn(context)}} \tn % Row Count 2 (+ 1) % Row 30 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.been.calledWith(...args)}} \tn % Row Count 3 (+ 1) % Row 31 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.always.have.been.calledWith(...args)}} \tn % Row Count 4 (+ 1) % Row 32 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.always.have.been.calledWithExactly(...args)}} \tn % Row Count 6 (+ 2) % Row 33 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.always.have.been.calledWithExactly(...args)}} \tn % Row Count 8 (+ 2) % Row 34 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.been.calledWithMatch(...args)}} \tn % Row Count 9 (+ 1) % Row 35 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.always.have.been.calledWithMatch(...args)}} \tn % Row Count 11 (+ 2) % Row 36 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.returned(returnVal)}} \tn % Row Count 12 (+ 1) % Row 37 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.always.returned(returnVal)}} \tn % Row Count 13 (+ 1) % Row 38 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing)}} \tn % Row Count 15 (+ 2) % Row 39 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing)}} \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{`var sinon = require('sinon');` \newline `require('chai').use(require('sinon-chai'));` \newline \newline Note that you can negate any assertion with Chai's .not. E. g. for notCalled use \seqsplit{spy.should.have.not.been.called.}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Mocha BDD}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{mocha.setup('bdd'); \newline \newline describe.only('something', function() \{ \newline beforeEach(function() \{ \newline \}); \newline \newline it.skip('should work', function() \{ \newline \}); \newline \newline it('should save', function(done) \{ \newline var user = new User(); \newline user.save(function(err) \{ \newline if (err) throw err; \newline done(); \newline \}); \newline \}); \newline \})} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Mocha TDD}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{mocha.setup('tdd'); \newline \newline suite('something', function() \{ \newline setup(function() \{ \newline \}); \newline \newline test('should work', function() \{ \newline \}); \newline \newline teardown(function() \{ \newline \}); \newline \});} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon.js Spy/stub properties}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{spy \newline .args //=\textgreater{} {[} {[}..{]}, {[}..{]} {]} one per call \newline .thisValues \newline .returnValues \newline \newline .called //=\textgreater{} true \newline .notCalled \newline .callCount \newline .calledOnce \newline .calledTwice \newline .calledThrice \newline \newline .getCalls() //=\textgreater{} Array \newline .getCall(0) \newline .firstCall} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon.JS Sandbox}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{beforeEach(function() \{ \newline global.env = \seqsplit{require('sinon').sandbox.create();} \newline \}); \newline \newline afterEach(function() \{ \newline global.env.restore(); \newline \});} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon.js Fake Server, XHR and date}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\$.get('/file.json', ...); \newline server.requests{[}0{]}.respond( \newline 200, \newline \{ "Content-Type": "application/json" \}, \newline JSON.stringify({[}\{ id: 1, text: "Provide examples", done: true \}{]}) \newline ); \newline \newline server.restore(); \newline \newline xhr = \seqsplit{sinon.useFakeXMLHttpRequest();} \newline xhr.restore(); \newline \newline sinon.useFakeTimers(+new Date(2011,9,1));} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon.js spies}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{fn = sinon.spy(); \newline \newline fn(); \newline fn.calledOnce == true \newline fn.callCount == 1} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon.js Spying/stubbing}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{sinon.spy(\$, 'ajax') \newline \newline \$.ajax(); \newline \$.ajax.calledOnce == true \newline \newline sinon.stub(\$, 'ajax', function () \{ ... \}); // function optional \newline \newline \$.ajax.calledWithMatch(\{ url: '/x' \}); \newline \$.ajax.restore();} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon.js mocks expectations}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{var mock = sinon.mock(obj);} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{var expectation = mock.expects("method");} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expectation.atLeast(number);}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expectation.atMost(number);}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expectation.never();} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expectation.once();} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expectation.twice();} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expectation.thrice();} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expectation.exactly(number);}} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expectation.withArgs(arg1}, arg2, ...);} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{expectation.withExactArgs(arg1}, arg2, ...);} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{expectation.on(obj);} \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{expectation.verify();} \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{mock.restore();} \tn % Row Count 14 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{mock.verify();} \tn % Row Count 15 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{`sinon.mock(jQuery).expects("ajax").atLeast(2).atMost(5);`} \newline `jQuery.ajax.verify();`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Sinon.js stubs}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{stub = \seqsplit{sinon.stub().returns(42);} \newline stub() == 42 \newline \newline stub \newline \seqsplit{.withArgs(42).returns(1);} \newline \seqsplit{.withArgs(43).throws("TypeError");} \newline \newline stub \newline .returns(1); \newline .throws("TypeError"); \newline .returnsArg(0); // Return 1st argument \newline .callsArg(0);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}