chai.js 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809
  1. !function (name, context, definition) {
  2. if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
  3. module.exports = definition();
  4. } else if (typeof define === 'function' && typeof define.amd === 'object') {
  5. define(function () {
  6. return definition();
  7. });
  8. } else {
  9. context[name] = definition();
  10. }
  11. }('chai', this, function () {
  12. function require(p) {
  13. var path = require.resolve(p)
  14. , mod = require.modules[path];
  15. if (!mod) throw new Error('failed to require "' + p + '"');
  16. if (!mod.exports) {
  17. mod.exports = {};
  18. mod.call(mod.exports, mod, mod.exports, require.relative(path));
  19. }
  20. return mod.exports;
  21. }
  22. require.modules = {};
  23. require.resolve = function (path) {
  24. var orig = path
  25. , reg = path + '.js'
  26. , index = path + '/index.js';
  27. return require.modules[reg] && reg
  28. || require.modules[index] && index
  29. || orig;
  30. };
  31. require.register = function (path, fn) {
  32. require.modules[path] = fn;
  33. };
  34. require.relative = function (parent) {
  35. return function(p){
  36. if ('.' != p.charAt(0)) return require(p);
  37. var path = parent.split('/')
  38. , segs = p.split('/');
  39. path.pop();
  40. for (var i = 0; i < segs.length; i++) {
  41. var seg = segs[i];
  42. if ('..' == seg) path.pop();
  43. else if ('.' != seg) path.push(seg);
  44. }
  45. return require(path.join('/'));
  46. };
  47. };
  48. require.alias = function (from, to) {
  49. var fn = require.modules[from];
  50. require.modules[to] = fn;
  51. };
  52. require.register("chai.js", function(module, exports, require){
  53. /*!
  54. * chai
  55. * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
  56. * MIT Licensed
  57. */
  58. var used = []
  59. , exports = module.exports = {};
  60. /*!
  61. * Chai version
  62. */
  63. exports.version = '1.4.2';
  64. /*!
  65. * Primary `Assertion` prototype
  66. */
  67. exports.Assertion = require('./chai/assertion');
  68. /*!
  69. * Assertion Error
  70. */
  71. exports.AssertionError = require('./chai/error');
  72. /*!
  73. * Utils for plugins (not exported)
  74. */
  75. var util = require('./chai/utils');
  76. /**
  77. * # .use(function)
  78. *
  79. * Provides a way to extend the internals of Chai
  80. *
  81. * @param {Function}
  82. * @returns {this} for chaining
  83. * @api public
  84. */
  85. exports.use = function (fn) {
  86. if (!~used.indexOf(fn)) {
  87. fn(this, util);
  88. used.push(fn);
  89. }
  90. return this;
  91. };
  92. /*!
  93. * Core Assertions
  94. */
  95. var core = require('./chai/core/assertions');
  96. exports.use(core);
  97. /*!
  98. * Expect interface
  99. */
  100. var expect = require('./chai/interface/expect');
  101. exports.use(expect);
  102. /*!
  103. * Should interface
  104. */
  105. var should = require('./chai/interface/should');
  106. exports.use(should);
  107. /*!
  108. * Assert interface
  109. */
  110. var assert = require('./chai/interface/assert');
  111. exports.use(assert);
  112. }); // module: chai.js
  113. require.register("chai/assertion.js", function(module, exports, require){
  114. /*!
  115. * chai
  116. * http://chaijs.com
  117. * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
  118. * MIT Licensed
  119. */
  120. /*!
  121. * Module dependencies.
  122. */
  123. var AssertionError = require('./error')
  124. , util = require('./utils')
  125. , flag = util.flag;
  126. /*!
  127. * Module export.
  128. */
  129. module.exports = Assertion;
  130. /*!
  131. * Assertion Constructor
  132. *
  133. * Creates object for chaining.
  134. *
  135. * @api private
  136. */
  137. function Assertion (obj, msg, stack) {
  138. flag(this, 'ssfi', stack || arguments.callee);
  139. flag(this, 'object', obj);
  140. flag(this, 'message', msg);
  141. }
  142. /*!
  143. * ### Assertion.includeStack
  144. *
  145. * User configurable property, influences whether stack trace
  146. * is included in Assertion error message. Default of false
  147. * suppresses stack trace in the error message
  148. *
  149. * Assertion.includeStack = true; // enable stack on error
  150. *
  151. * @api public
  152. */
  153. Assertion.includeStack = false;
  154. Assertion.addProperty = function (name, fn) {
  155. util.addProperty(this.prototype, name, fn);
  156. };
  157. Assertion.addMethod = function (name, fn) {
  158. util.addMethod(this.prototype, name, fn);
  159. };
  160. Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
  161. util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
  162. };
  163. Assertion.overwriteProperty = function (name, fn) {
  164. util.overwriteProperty(this.prototype, name, fn);
  165. };
  166. Assertion.overwriteMethod = function (name, fn) {
  167. util.overwriteMethod(this.prototype, name, fn);
  168. };
  169. /*!
  170. * ### .assert(expression, message, negateMessage, expected, actual)
  171. *
  172. * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
  173. *
  174. * @name assert
  175. * @param {Philosophical} expression to be tested
  176. * @param {String} message to display if fails
  177. * @param {String} negatedMessage to display if negated expression fails
  178. * @param {Mixed} expected value (remember to check for negation)
  179. * @param {Mixed} actual (optional) will default to `this.obj`
  180. * @api private
  181. */
  182. Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
  183. var ok = util.test(this, arguments);
  184. if (true !== showDiff) showDiff = false;
  185. if (!ok) {
  186. var msg = util.getMessage(this, arguments)
  187. , actual = util.getActual(this, arguments);
  188. throw new AssertionError({
  189. message: msg
  190. , actual: actual
  191. , expected: expected
  192. , stackStartFunction: (Assertion.includeStack) ? this.assert : flag(this, 'ssfi')
  193. , showDiff: showDiff
  194. });
  195. }
  196. };
  197. /*!
  198. * ### ._obj
  199. *
  200. * Quick reference to stored `actual` value for plugin developers.
  201. *
  202. * @api private
  203. */
  204. Object.defineProperty(Assertion.prototype, '_obj',
  205. { get: function () {
  206. return flag(this, 'object');
  207. }
  208. , set: function (val) {
  209. flag(this, 'object', val);
  210. }
  211. });
  212. }); // module: chai/assertion.js
  213. require.register("chai/core/assertions.js", function(module, exports, require){
  214. /*!
  215. * chai
  216. * http://chaijs.com
  217. * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
  218. * MIT Licensed
  219. */
  220. module.exports = function (chai, _) {
  221. var Assertion = chai.Assertion
  222. , toString = Object.prototype.toString
  223. , flag = _.flag;
  224. /**
  225. * ### Language Chains
  226. *
  227. * The following are provide as chainable getters to
  228. * improve the readability of your assertions. They
  229. * do not provide an testing capability unless they
  230. * have been overwritten by a plugin.
  231. *
  232. * **Chains**
  233. *
  234. * - to
  235. * - be
  236. * - been
  237. * - is
  238. * - that
  239. * - and
  240. * - have
  241. * - with
  242. * - at
  243. * - of
  244. *
  245. * @name language chains
  246. * @api public
  247. */
  248. [ 'to', 'be', 'been'
  249. , 'is', 'and', 'have'
  250. , 'with', 'that', 'at'
  251. , 'of' ].forEach(function (chain) {
  252. Assertion.addProperty(chain, function () {
  253. return this;
  254. });
  255. });
  256. /**
  257. * ### .not
  258. *
  259. * Negates any of assertions following in the chain.
  260. *
  261. * expect(foo).to.not.equal('bar');
  262. * expect(goodFn).to.not.throw(Error);
  263. * expect({ foo: 'baz' }).to.have.property('foo')
  264. * .and.not.equal('bar');
  265. *
  266. * @name not
  267. * @api public
  268. */
  269. Assertion.addProperty('not', function () {
  270. flag(this, 'negate', true);
  271. });
  272. /**
  273. * ### .deep
  274. *
  275. * Sets the `deep` flag, later used by the `equal` and
  276. * `property` assertions.
  277. *
  278. * expect(foo).to.deep.equal({ bar: 'baz' });
  279. * expect({ foo: { bar: { baz: 'quux' } } })
  280. * .to.have.deep.property('foo.bar.baz', 'quux');
  281. *
  282. * @name deep
  283. * @api public
  284. */
  285. Assertion.addProperty('deep', function () {
  286. flag(this, 'deep', true);
  287. });
  288. /**
  289. * ### .a(type)
  290. *
  291. * The `a` and `an` assertions are aliases that can be
  292. * used either as language chains or to assert a value's
  293. * type (as revealed by `Object.prototype.toString`).
  294. *
  295. * // typeof
  296. * expect('test').to.be.a('string');
  297. * expect({ foo: 'bar' }).to.be.an('object');
  298. * expect(null).to.be.a('null');
  299. * expect(undefined).to.be.an('undefined');
  300. *
  301. * // language chain
  302. * expect(foo).to.be.an.instanceof(Foo);
  303. *
  304. * @name a
  305. * @alias an
  306. * @param {String} type
  307. * @param {String} message _optional_
  308. * @api public
  309. */
  310. function an(type, msg) {
  311. if (msg) flag(this, 'message', msg);
  312. var obj = flag(this, 'object')
  313. , klassStart = type.charAt(0).toUpperCase()
  314. , klass = klassStart + type.slice(1)
  315. , article = ~[ 'A', 'E', 'I', 'O', 'U' ].indexOf(klassStart) ? 'an ' : 'a ';
  316. this.assert(
  317. '[object ' + klass + ']' === toString.call(obj)
  318. , 'expected #{this} to be ' + article + type
  319. , 'expected #{this} not to be ' + article + type
  320. );
  321. }
  322. Assertion.addChainableMethod('an', an);
  323. Assertion.addChainableMethod('a', an);
  324. /**
  325. * ### .include(value)
  326. *
  327. * The `include` and `contain` assertions can be used as either property
  328. * based language chains or as methods to assert the inclusion of an object
  329. * in an array or a substring in a string. When used as language chains,
  330. * they toggle the `contain` flag for the `keys` assertion.
  331. *
  332. * expect([1,2,3]).to.include(2);
  333. * expect('foobar').to.contain('foo');
  334. * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
  335. *
  336. * @name include
  337. * @alias contain
  338. * @param {Object|String|Number} obj
  339. * @param {String} message _optional_
  340. * @api public
  341. */
  342. function includeChainingBehavior () {
  343. flag(this, 'contains', true);
  344. }
  345. function include (val, msg) {
  346. if (msg) flag(this, 'message', msg);
  347. var obj = flag(this, 'object')
  348. this.assert(
  349. ~obj.indexOf(val)
  350. , 'expected #{this} to include ' + _.inspect(val)
  351. , 'expected #{this} to not include ' + _.inspect(val));
  352. }
  353. Assertion.addChainableMethod('include', include, includeChainingBehavior);
  354. Assertion.addChainableMethod('contain', include, includeChainingBehavior);
  355. /**
  356. * ### .ok
  357. *
  358. * Asserts that the target is truthy.
  359. *
  360. * expect('everthing').to.be.ok;
  361. * expect(1).to.be.ok;
  362. * expect(false).to.not.be.ok;
  363. * expect(undefined).to.not.be.ok;
  364. * expect(null).to.not.be.ok;
  365. *
  366. * @name ok
  367. * @api public
  368. */
  369. Assertion.addProperty('ok', function () {
  370. this.assert(
  371. flag(this, 'object')
  372. , 'expected #{this} to be truthy'
  373. , 'expected #{this} to be falsy');
  374. });
  375. /**
  376. * ### .true
  377. *
  378. * Asserts that the target is `true`.
  379. *
  380. * expect(true).to.be.true;
  381. * expect(1).to.not.be.true;
  382. *
  383. * @name true
  384. * @api public
  385. */
  386. Assertion.addProperty('true', function () {
  387. this.assert(
  388. true === flag(this, 'object')
  389. , 'expected #{this} to be true'
  390. , 'expected #{this} to be false'
  391. , this.negate ? false : true
  392. );
  393. });
  394. /**
  395. * ### .false
  396. *
  397. * Asserts that the target is `false`.
  398. *
  399. * expect(false).to.be.false;
  400. * expect(0).to.not.be.false;
  401. *
  402. * @name false
  403. * @api public
  404. */
  405. Assertion.addProperty('false', function () {
  406. this.assert(
  407. false === flag(this, 'object')
  408. , 'expected #{this} to be false'
  409. , 'expected #{this} to be true'
  410. , this.negate ? true : false
  411. );
  412. });
  413. /**
  414. * ### .null
  415. *
  416. * Asserts that the target is `null`.
  417. *
  418. * expect(null).to.be.null;
  419. * expect(undefined).not.to.be.null;
  420. *
  421. * @name null
  422. * @api public
  423. */
  424. Assertion.addProperty('null', function () {
  425. this.assert(
  426. null === flag(this, 'object')
  427. , 'expected #{this} to be null'
  428. , 'expected #{this} not to be null'
  429. );
  430. });
  431. /**
  432. * ### .undefined
  433. *
  434. * Asserts that the target is `undefined`.
  435. *
  436. * expect(undefined).to.be.undefined;
  437. * expect(null).to.not.be.undefined;
  438. *
  439. * @name undefined
  440. * @api public
  441. */
  442. Assertion.addProperty('undefined', function () {
  443. this.assert(
  444. undefined === flag(this, 'object')
  445. , 'expected #{this} to be undefined'
  446. , 'expected #{this} not to be undefined'
  447. );
  448. });
  449. /**
  450. * ### .exist
  451. *
  452. * Asserts that the target is neither `null` nor `undefined`.
  453. *
  454. * var foo = 'hi'
  455. * , bar = null
  456. * , baz;
  457. *
  458. * expect(foo).to.exist;
  459. * expect(bar).to.not.exist;
  460. * expect(baz).to.not.exist;
  461. *
  462. * @name exist
  463. * @api public
  464. */
  465. Assertion.addProperty('exist', function () {
  466. this.assert(
  467. null != flag(this, 'object')
  468. , 'expected #{this} to exist'
  469. , 'expected #{this} to not exist'
  470. );
  471. });
  472. /**
  473. * ### .empty
  474. *
  475. * Asserts that the target's length is `0`. For arrays, it checks
  476. * the `length` property. For objects, it gets the count of
  477. * enumerable keys.
  478. *
  479. * expect([]).to.be.empty;
  480. * expect('').to.be.empty;
  481. * expect({}).to.be.empty;
  482. *
  483. * @name empty
  484. * @api public
  485. */
  486. Assertion.addProperty('empty', function () {
  487. var obj = flag(this, 'object')
  488. , expected = obj;
  489. if (Array.isArray(obj) || 'string' === typeof object) {
  490. expected = obj.length;
  491. } else if (typeof obj === 'object') {
  492. expected = Object.keys(obj).length;
  493. }
  494. this.assert(
  495. !expected
  496. , 'expected #{this} to be empty'
  497. , 'expected #{this} not to be empty'
  498. );
  499. });
  500. /**
  501. * ### .arguments
  502. *
  503. * Asserts that the target is an arguments object.
  504. *
  505. * function test () {
  506. * expect(arguments).to.be.arguments;
  507. * }
  508. *
  509. * @name arguments
  510. * @alias Arguments
  511. * @api public
  512. */
  513. function checkArguments () {
  514. var obj = flag(this, 'object')
  515. , type = Object.prototype.toString.call(obj);
  516. this.assert(
  517. '[object Arguments]' === type
  518. , 'expected #{this} to be arguments but got ' + type
  519. , 'expected #{this} to not be arguments'
  520. );
  521. }
  522. Assertion.addProperty('arguments', checkArguments);
  523. Assertion.addProperty('Arguments', checkArguments);
  524. /**
  525. * ### .equal(value)
  526. *
  527. * Asserts that the target is strictly equal (`===`) to `value`.
  528. * Alternately, if the `deep` flag is set, asserts that
  529. * the target is deeply equal to `value`.
  530. *
  531. * expect('hello').to.equal('hello');
  532. * expect(42).to.equal(42);
  533. * expect(1).to.not.equal(true);
  534. * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
  535. * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
  536. *
  537. * @name equal
  538. * @alias equals
  539. * @alias eq
  540. * @alias deep.equal
  541. * @param {Mixed} value
  542. * @param {String} message _optional_
  543. * @api public
  544. */
  545. function assertEqual (val, msg) {
  546. if (msg) flag(this, 'message', msg);
  547. var obj = flag(this, 'object');
  548. if (flag(this, 'deep')) {
  549. return this.eql(val);
  550. } else {
  551. this.assert(
  552. val === obj
  553. , 'expected #{this} to equal #{exp}'
  554. , 'expected #{this} to not equal #{exp}'
  555. , val
  556. , this._obj
  557. , true
  558. );
  559. }
  560. }
  561. Assertion.addMethod('equal', assertEqual);
  562. Assertion.addMethod('equals', assertEqual);
  563. Assertion.addMethod('eq', assertEqual);
  564. /**
  565. * ### .eql(value)
  566. *
  567. * Asserts that the target is deeply equal to `value`.
  568. *
  569. * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
  570. * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
  571. *
  572. * @name eql
  573. * @param {Mixed} value
  574. * @param {String} message _optional_
  575. * @api public
  576. */
  577. Assertion.addMethod('eql', function (obj, msg) {
  578. if (msg) flag(this, 'message', msg);
  579. this.assert(
  580. _.eql(obj, flag(this, 'object'))
  581. , 'expected #{this} to deeply equal #{exp}'
  582. , 'expected #{this} to not deeply equal #{exp}'
  583. , obj
  584. , this._obj
  585. , true
  586. );
  587. });
  588. /**
  589. * ### .above(value)
  590. *
  591. * Asserts that the target is greater than `value`.
  592. *
  593. * expect(10).to.be.above(5);
  594. *
  595. * Can also be used in conjunction with `length` to
  596. * assert a minimum length. The benefit being a
  597. * more informative error message than if the length
  598. * was supplied directly.
  599. *
  600. * expect('foo').to.have.length.above(2);
  601. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  602. *
  603. * @name above
  604. * @alias gt
  605. * @alias greaterThan
  606. * @param {Number} value
  607. * @param {String} message _optional_
  608. * @api public
  609. */
  610. function assertAbove (n, msg) {
  611. if (msg) flag(this, 'message', msg);
  612. var obj = flag(this, 'object');
  613. if (flag(this, 'doLength')) {
  614. new Assertion(obj, msg).to.have.property('length');
  615. var len = obj.length;
  616. this.assert(
  617. len > n
  618. , 'expected #{this} to have a length above #{exp} but got #{act}'
  619. , 'expected #{this} to not have a length above #{exp}'
  620. , n
  621. , len
  622. );
  623. } else {
  624. this.assert(
  625. obj > n
  626. , 'expected #{this} to be above ' + n
  627. , 'expected #{this} to be at most ' + n
  628. );
  629. }
  630. }
  631. Assertion.addMethod('above', assertAbove);
  632. Assertion.addMethod('gt', assertAbove);
  633. Assertion.addMethod('greaterThan', assertAbove);
  634. /**
  635. * ### .least(value)
  636. *
  637. * Asserts that the target is greater than or equal to `value`.
  638. *
  639. * expect(10).to.be.at.least(10);
  640. *
  641. * Can also be used in conjunction with `length` to
  642. * assert a minimum length. The benefit being a
  643. * more informative error message than if the length
  644. * was supplied directly.
  645. *
  646. * expect('foo').to.have.length.of.at.least(2);
  647. * expect([ 1, 2, 3 ]).to.have.length.of.at.least(3);
  648. *
  649. * @name least
  650. * @alias gte
  651. * @param {Number} value
  652. * @param {String} message _optional_
  653. * @api public
  654. */
  655. function assertLeast (n, msg) {
  656. if (msg) flag(this, 'message', msg);
  657. var obj = flag(this, 'object');
  658. if (flag(this, 'doLength')) {
  659. new Assertion(obj, msg).to.have.property('length');
  660. var len = obj.length;
  661. this.assert(
  662. len >= n
  663. , 'expected #{this} to have a length at least #{exp} but got #{act}'
  664. , 'expected #{this} to not have a length below #{exp}'
  665. , n
  666. , len
  667. );
  668. } else {
  669. this.assert(
  670. obj >= n
  671. , 'expected #{this} to be at least ' + n
  672. , 'expected #{this} to be below ' + n
  673. );
  674. }
  675. }
  676. Assertion.addMethod('least', assertLeast);
  677. Assertion.addMethod('gte', assertLeast);
  678. /**
  679. * ### .below(value)
  680. *
  681. * Asserts that the target is less than `value`.
  682. *
  683. * expect(5).to.be.below(10);
  684. *
  685. * Can also be used in conjunction with `length` to
  686. * assert a maximum length. The benefit being a
  687. * more informative error message than if the length
  688. * was supplied directly.
  689. *
  690. * expect('foo').to.have.length.below(4);
  691. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  692. *
  693. * @name below
  694. * @alias lt
  695. * @alias lessThan
  696. * @param {Number} value
  697. * @param {String} message _optional_
  698. * @api public
  699. */
  700. function assertBelow (n, msg) {
  701. if (msg) flag(this, 'message', msg);
  702. var obj = flag(this, 'object');
  703. if (flag(this, 'doLength')) {
  704. new Assertion(obj, msg).to.have.property('length');
  705. var len = obj.length;
  706. this.assert(
  707. len < n
  708. , 'expected #{this} to have a length below #{exp} but got #{act}'
  709. , 'expected #{this} to not have a length below #{exp}'
  710. , n
  711. , len
  712. );
  713. } else {
  714. this.assert(
  715. obj < n
  716. , 'expected #{this} to be below ' + n
  717. , 'expected #{this} to be at least ' + n
  718. );
  719. }
  720. }
  721. Assertion.addMethod('below', assertBelow);
  722. Assertion.addMethod('lt', assertBelow);
  723. Assertion.addMethod('lessThan', assertBelow);
  724. /**
  725. * ### .most(value)
  726. *
  727. * Asserts that the target is less than or equal to `value`.
  728. *
  729. * expect(5).to.be.at.most(5);
  730. *
  731. * Can also be used in conjunction with `length` to
  732. * assert a maximum length. The benefit being a
  733. * more informative error message than if the length
  734. * was supplied directly.
  735. *
  736. * expect('foo').to.have.length.of.at.most(4);
  737. * expect([ 1, 2, 3 ]).to.have.length.of.at.most(3);
  738. *
  739. * @name most
  740. * @alias lte
  741. * @param {Number} value
  742. * @param {String} message _optional_
  743. * @api public
  744. */
  745. function assertMost (n, msg) {
  746. if (msg) flag(this, 'message', msg);
  747. var obj = flag(this, 'object');
  748. if (flag(this, 'doLength')) {
  749. new Assertion(obj, msg).to.have.property('length');
  750. var len = obj.length;
  751. this.assert(
  752. len <= n
  753. , 'expected #{this} to have a length at most #{exp} but got #{act}'
  754. , 'expected #{this} to not have a length above #{exp}'
  755. , n
  756. , len
  757. );
  758. } else {
  759. this.assert(
  760. obj <= n
  761. , 'expected #{this} to be at most ' + n
  762. , 'expected #{this} to be above ' + n
  763. );
  764. }
  765. }
  766. Assertion.addMethod('most', assertMost);
  767. Assertion.addMethod('lte', assertMost);
  768. /**
  769. * ### .within(start, finish)
  770. *
  771. * Asserts that the target is within a range.
  772. *
  773. * expect(7).to.be.within(5,10);
  774. *
  775. * Can also be used in conjunction with `length` to
  776. * assert a length range. The benefit being a
  777. * more informative error message than if the length
  778. * was supplied directly.
  779. *
  780. * expect('foo').to.have.length.within(2,4);
  781. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  782. *
  783. * @name within
  784. * @param {Number} start lowerbound inclusive
  785. * @param {Number} finish upperbound inclusive
  786. * @param {String} message _optional_
  787. * @api public
  788. */
  789. Assertion.addMethod('within', function (start, finish, msg) {
  790. if (msg) flag(this, 'message', msg);
  791. var obj = flag(this, 'object')
  792. , range = start + '..' + finish;
  793. if (flag(this, 'doLength')) {
  794. new Assertion(obj, msg).to.have.property('length');
  795. var len = obj.length;
  796. this.assert(
  797. len >= start && len <= finish
  798. , 'expected #{this} to have a length within ' + range
  799. , 'expected #{this} to not have a length within ' + range
  800. );
  801. } else {
  802. this.assert(
  803. obj >= start && obj <= finish
  804. , 'expected #{this} to be within ' + range
  805. , 'expected #{this} to not be within ' + range
  806. );
  807. }
  808. });
  809. /**
  810. * ### .instanceof(constructor)
  811. *
  812. * Asserts that the target is an instance of `constructor`.
  813. *
  814. * var Tea = function (name) { this.name = name; }
  815. * , Chai = new Tea('chai');
  816. *
  817. * expect(Chai).to.be.an.instanceof(Tea);
  818. * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
  819. *
  820. * @name instanceof
  821. * @param {Constructor} constructor
  822. * @param {String} message _optional_
  823. * @alias instanceOf
  824. * @api public
  825. */
  826. function assertInstanceOf (constructor, msg) {
  827. if (msg) flag(this, 'message', msg);
  828. var name = _.getName(constructor);
  829. this.assert(
  830. flag(this, 'object') instanceof constructor
  831. , 'expected #{this} to be an instance of ' + name
  832. , 'expected #{this} to not be an instance of ' + name
  833. );
  834. };
  835. Assertion.addMethod('instanceof', assertInstanceOf);
  836. Assertion.addMethod('instanceOf', assertInstanceOf);
  837. /**
  838. * ### .property(name, [value])
  839. *
  840. * Asserts that the target has a property `name`, optionally asserting that
  841. * the value of that property is strictly equal to `value`.
  842. * If the `deep` flag is set, you can use dot- and bracket-notation for deep
  843. * references into objects and arrays.
  844. *
  845. * // simple referencing
  846. * var obj = { foo: 'bar' };
  847. * expect(obj).to.have.property('foo');
  848. * expect(obj).to.have.property('foo', 'bar');
  849. *
  850. * // deep referencing
  851. * var deepObj = {
  852. * green: { tea: 'matcha' }
  853. * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
  854. * };
  855. * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
  856. * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
  857. * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
  858. *
  859. * You can also use an array as the starting point of a `deep.property`
  860. * assertion, or traverse nested arrays.
  861. *
  862. * var arr = [
  863. * [ 'chai', 'matcha', 'konacha' ]
  864. * , [ { tea: 'chai' }
  865. * , { tea: 'matcha' }
  866. * , { tea: 'konacha' } ]
  867. * ];
  868. *
  869. * expect(arr).to.have.deep.property('[0][1]', 'matcha');
  870. * expect(arr).to.have.deep.property('[1][2].tea', 'konacha');
  871. *
  872. * Furthermore, `property` changes the subject of the assertion
  873. * to be the value of that property from the original object. This
  874. * permits for further chainable assertions on that property.
  875. *
  876. * expect(obj).to.have.property('foo')
  877. * .that.is.a('string');
  878. * expect(deepObj).to.have.property('green')
  879. * .that.is.an('object')
  880. * .that.deep.equals({ tea: 'matcha' });
  881. * expect(deepObj).to.have.property('teas')
  882. * .that.is.an('array')
  883. * .with.deep.property('[2]')
  884. * .that.deep.equals({ tea: 'konacha' });
  885. *
  886. * @name property
  887. * @alias deep.property
  888. * @param {String} name
  889. * @param {Mixed} value (optional)
  890. * @param {String} message _optional_
  891. * @returns value of property for chaining
  892. * @api public
  893. */
  894. Assertion.addMethod('property', function (name, val, msg) {
  895. if (msg) flag(this, 'message', msg);
  896. var descriptor = flag(this, 'deep') ? 'deep property ' : 'property '
  897. , negate = flag(this, 'negate')
  898. , obj = flag(this, 'object')
  899. , value = flag(this, 'deep')
  900. ? _.getPathValue(name, obj)
  901. : obj[name];
  902. if (negate && undefined !== val) {
  903. if (undefined === value) {
  904. msg = (msg != null) ? msg + ': ' : '';
  905. throw new Error(msg + _.inspect(obj) + ' has no ' + descriptor + _.inspect(name));
  906. }
  907. } else {
  908. this.assert(
  909. undefined !== value
  910. , 'expected #{this} to have a ' + descriptor + _.inspect(name)
  911. , 'expected #{this} to not have ' + descriptor + _.inspect(name));
  912. }
  913. if (undefined !== val) {
  914. this.assert(
  915. val === value
  916. , 'expected #{this} to have a ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
  917. , 'expected #{this} to not have a ' + descriptor + _.inspect(name) + ' of #{act}'
  918. , val
  919. , value
  920. );
  921. }
  922. flag(this, 'object', value);
  923. });
  924. /**
  925. * ### .ownProperty(name)
  926. *
  927. * Asserts that the target has an own property `name`.
  928. *
  929. * expect('test').to.have.ownProperty('length');
  930. *
  931. * @name ownProperty
  932. * @alias haveOwnProperty
  933. * @param {String} name
  934. * @param {String} message _optional_
  935. * @api public
  936. */
  937. function assertOwnProperty (name, msg) {
  938. if (msg) flag(this, 'message', msg);
  939. var obj = flag(this, 'object');
  940. this.assert(
  941. obj.hasOwnProperty(name)
  942. , 'expected #{this} to have own property ' + _.inspect(name)
  943. , 'expected #{this} to not have own property ' + _.inspect(name)
  944. );
  945. }
  946. Assertion.addMethod('ownProperty', assertOwnProperty);
  947. Assertion.addMethod('haveOwnProperty', assertOwnProperty);
  948. /**
  949. * ### .length(value)
  950. *
  951. * Asserts that the target's `length` property has
  952. * the expected value.
  953. *
  954. * expect([ 1, 2, 3]).to.have.length(3);
  955. * expect('foobar').to.have.length(6);
  956. *
  957. * Can also be used as a chain precursor to a value
  958. * comparison for the length property.
  959. *
  960. * expect('foo').to.have.length.above(2);
  961. * expect([ 1, 2, 3 ]).to.have.length.above(2);
  962. * expect('foo').to.have.length.below(4);
  963. * expect([ 1, 2, 3 ]).to.have.length.below(4);
  964. * expect('foo').to.have.length.within(2,4);
  965. * expect([ 1, 2, 3 ]).to.have.length.within(2,4);
  966. *
  967. * @name length
  968. * @alias lengthOf
  969. * @param {Number} length
  970. * @param {String} message _optional_
  971. * @api public
  972. */
  973. function assertLengthChain () {
  974. flag(this, 'doLength', true);
  975. }
  976. function assertLength (n, msg) {
  977. if (msg) flag(this, 'message', msg);
  978. var obj = flag(this, 'object');
  979. new Assertion(obj, msg).to.have.property('length');
  980. var len = obj.length;
  981. this.assert(
  982. len == n
  983. , 'expected #{this} to have a length of #{exp} but got #{act}'
  984. , 'expected #{this} to not have a length of #{act}'
  985. , n
  986. , len
  987. );
  988. }
  989. Assertion.addChainableMethod('length', assertLength, assertLengthChain);
  990. Assertion.addMethod('lengthOf', assertLength, assertLengthChain);
  991. /**
  992. * ### .match(regexp)
  993. *
  994. * Asserts that the target matches a regular expression.
  995. *
  996. * expect('foobar').to.match(/^foo/);
  997. *
  998. * @name match
  999. * @param {RegExp} RegularExpression
  1000. * @param {String} message _optional_
  1001. * @api public
  1002. */
  1003. Assertion.addMethod('match', function (re, msg) {
  1004. if (msg) flag(this, 'message', msg);
  1005. var obj = flag(this, 'object');
  1006. this.assert(
  1007. re.exec(obj)
  1008. , 'expected #{this} to match ' + re
  1009. , 'expected #{this} not to match ' + re
  1010. );
  1011. });
  1012. /**
  1013. * ### .string(string)
  1014. *
  1015. * Asserts that the string target contains another string.
  1016. *
  1017. * expect('foobar').to.have.string('bar');
  1018. *
  1019. * @name string
  1020. * @param {String} string
  1021. * @param {String} message _optional_
  1022. * @api public
  1023. */
  1024. Assertion.addMethod('string', function (str, msg) {
  1025. if (msg) flag(this, 'message', msg);
  1026. var obj = flag(this, 'object');
  1027. new Assertion(obj, msg).is.a('string');
  1028. this.assert(
  1029. ~obj.indexOf(str)
  1030. , 'expected #{this} to contain ' + _.inspect(str)
  1031. , 'expected #{this} to not contain ' + _.inspect(str)
  1032. );
  1033. });
  1034. /**
  1035. * ### .keys(key1, [key2], [...])
  1036. *
  1037. * Asserts that the target has exactly the given keys, or
  1038. * asserts the inclusion of some keys when using the
  1039. * `include` or `contain` modifiers.
  1040. *
  1041. * expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
  1042. * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
  1043. *
  1044. * @name keys
  1045. * @alias key
  1046. * @param {String...|Array} keys
  1047. * @api public
  1048. */
  1049. function assertKeys (keys) {
  1050. var obj = flag(this, 'object')
  1051. , str
  1052. , ok = true;
  1053. keys = keys instanceof Array
  1054. ? keys
  1055. : Array.prototype.slice.call(arguments);
  1056. if (!keys.length) throw new Error('keys required');
  1057. var actual = Object.keys(obj)
  1058. , len = keys.length;
  1059. // Inclusion
  1060. ok = keys.every(function(key){
  1061. return ~actual.indexOf(key);
  1062. });
  1063. // Strict
  1064. if (!flag(this, 'negate') && !flag(this, 'contains')) {
  1065. ok = ok && keys.length == actual.length;
  1066. }
  1067. // Key string
  1068. if (len > 1) {
  1069. keys = keys.map(function(key){
  1070. return _.inspect(key);
  1071. });
  1072. var last = keys.pop();
  1073. str = keys.join(', ') + ', and ' + last;
  1074. } else {
  1075. str = _.inspect(keys[0]);
  1076. }
  1077. // Form
  1078. str = (len > 1 ? 'keys ' : 'key ') + str;
  1079. // Have / include
  1080. str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
  1081. // Assertion
  1082. this.assert(
  1083. ok
  1084. , 'expected #{this} to ' + str
  1085. , 'expected #{this} to not ' + str
  1086. );
  1087. }
  1088. Assertion.addMethod('keys', assertKeys);
  1089. Assertion.addMethod('key', assertKeys);
  1090. /**
  1091. * ### .throw(constructor)
  1092. *
  1093. * Asserts that the function target will throw a specific error, or specific type of error
  1094. * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
  1095. * for the error's message.
  1096. *
  1097. * var err = new ReferenceError('This is a bad function.');
  1098. * var fn = function () { throw err; }
  1099. * expect(fn).to.throw(ReferenceError);
  1100. * expect(fn).to.throw(Error);
  1101. * expect(fn).to.throw(/bad function/);
  1102. * expect(fn).to.not.throw('good function');
  1103. * expect(fn).to.throw(ReferenceError, /bad function/);
  1104. * expect(fn).to.throw(err);
  1105. * expect(fn).to.not.throw(new RangeError('Out of range.'));
  1106. *
  1107. * Please note that when a throw expectation is negated, it will check each
  1108. * parameter independently, starting with error constructor type. The appropriate way
  1109. * to check for the existence of a type of error but for a message that does not match
  1110. * is to use `and`.
  1111. *
  1112. * expect(fn).to.throw(ReferenceError)
  1113. * .and.not.throw(/good function/);
  1114. *
  1115. * @name throw
  1116. * @alias throws
  1117. * @alias Throw
  1118. * @param {ErrorConstructor} constructor
  1119. * @param {String|RegExp} expected error message
  1120. * @param {String} message _optional_
  1121. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  1122. * @api public
  1123. */
  1124. function assertThrows (constructor, errMsg, msg) {
  1125. if (msg) flag(this, 'message', msg);
  1126. var obj = flag(this, 'object');
  1127. new Assertion(obj, msg).is.a('function');
  1128. var thrown = false
  1129. , desiredError = null
  1130. , name = null
  1131. , thrownError = null;
  1132. if (arguments.length === 0) {
  1133. errMsg = null;
  1134. constructor = null;
  1135. } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
  1136. errMsg = constructor;
  1137. constructor = null;
  1138. } else if (constructor && constructor instanceof Error) {
  1139. desiredError = constructor;
  1140. constructor = null;
  1141. errMsg = null;
  1142. } else if (typeof constructor === 'function') {
  1143. name = (new constructor()).name;
  1144. } else {
  1145. constructor = null;
  1146. }
  1147. try {
  1148. obj();
  1149. } catch (err) {
  1150. // first, check desired error
  1151. if (desiredError) {
  1152. this.assert(
  1153. err === desiredError
  1154. , 'expected #{this} to throw ' + _.inspect(desiredError) + ' but ' + _.inspect(err) + ' was thrown'
  1155. , 'expected #{this} to not throw ' + _.inspect(desiredError)
  1156. );
  1157. return this;
  1158. }
  1159. // next, check constructor
  1160. if (constructor) {
  1161. this.assert(
  1162. err instanceof constructor
  1163. , 'expected #{this} to throw ' + name + ' but ' + _.inspect(err) + ' was thrown'
  1164. , 'expected #{this} to not throw ' + name + ' but ' + _.inspect(err) + ' was thrown');
  1165. if (!errMsg) return this;
  1166. }
  1167. // next, check message
  1168. if (err.message && errMsg && errMsg instanceof RegExp) {
  1169. this.assert(
  1170. errMsg.exec(err.message)
  1171. , 'expected #{this} to throw error matching ' + errMsg + ' but got ' + _.inspect(err.message)
  1172. , 'expected #{this} to throw error not matching ' + errMsg
  1173. );
  1174. return this;
  1175. } else if (err.message && errMsg && 'string' === typeof errMsg) {
  1176. this.assert(
  1177. ~err.message.indexOf(errMsg)
  1178. , 'expected #{this} to throw error including #{exp} but got #{act}'
  1179. , 'expected #{this} to throw error not including #{act}'
  1180. , errMsg
  1181. , err.message
  1182. );
  1183. return this;
  1184. } else {
  1185. thrown = true;
  1186. thrownError = err;
  1187. }
  1188. }
  1189. var expectedThrown = name ? name : desiredError ? _.inspect(desiredError) : 'an error';
  1190. var actuallyGot = ''
  1191. if (thrown) {
  1192. actuallyGot = ' but ' + _.inspect(thrownError) + ' was thrown'
  1193. }
  1194. this.assert(
  1195. thrown === true
  1196. , 'expected #{this} to throw ' + expectedThrown + actuallyGot
  1197. , 'expected #{this} to not throw ' + expectedThrown + actuallyGot
  1198. );
  1199. };
  1200. Assertion.addMethod('throw', assertThrows);
  1201. Assertion.addMethod('throws', assertThrows);
  1202. Assertion.addMethod('Throw', assertThrows);
  1203. /**
  1204. * ### .respondTo(method)
  1205. *
  1206. * Asserts that the object or class target will respond to a method.
  1207. *
  1208. * Klass.prototype.bar = function(){};
  1209. * expect(Klass).to.respondTo('bar');
  1210. * expect(obj).to.respondTo('bar');
  1211. *
  1212. * To check if a constructor will respond to a static function,
  1213. * set the `itself` flag.
  1214. *
  1215. * Klass.baz = function(){};
  1216. * expect(Klass).itself.to.respondTo('baz');
  1217. *
  1218. * @name respondTo
  1219. * @param {String} method
  1220. * @param {String} message _optional_
  1221. * @api public
  1222. */
  1223. Assertion.addMethod('respondTo', function (method, msg) {
  1224. if (msg) flag(this, 'message', msg);
  1225. var obj = flag(this, 'object')
  1226. , itself = flag(this, 'itself')
  1227. , context = ('function' === typeof obj && !itself)
  1228. ? obj.prototype[method]
  1229. : obj[method];
  1230. this.assert(
  1231. 'function' === typeof context
  1232. , 'expected #{this} to respond to ' + _.inspect(method)
  1233. , 'expected #{this} to not respond to ' + _.inspect(method)
  1234. );
  1235. });
  1236. /**
  1237. * ### .itself
  1238. *
  1239. * Sets the `itself` flag, later used by the `respondTo` assertion.
  1240. *
  1241. * function Foo() {}
  1242. * Foo.bar = function() {}
  1243. * Foo.prototype.baz = function() {}
  1244. *
  1245. * expect(Foo).itself.to.respondTo('bar');
  1246. * expect(Foo).itself.not.to.respondTo('baz');
  1247. *
  1248. * @name itself
  1249. * @api public
  1250. */
  1251. Assertion.addProperty('itself', function () {
  1252. flag(this, 'itself', true);
  1253. });
  1254. /**
  1255. * ### .satisfy(method)
  1256. *
  1257. * Asserts that the target passes a given truth test.
  1258. *
  1259. * expect(1).to.satisfy(function(num) { return num > 0; });
  1260. *
  1261. * @name satisfy
  1262. * @param {Function} matcher
  1263. * @param {String} message _optional_
  1264. * @api public
  1265. */
  1266. Assertion.addMethod('satisfy', function (matcher, msg) {
  1267. if (msg) flag(this, 'message', msg);
  1268. var obj = flag(this, 'object');
  1269. this.assert(
  1270. matcher(obj)
  1271. , 'expected #{this} to satisfy ' + _.inspect(matcher)
  1272. , 'expected #{this} to not satisfy' + _.inspect(matcher)
  1273. , this.negate ? false : true
  1274. , matcher(obj)
  1275. );
  1276. });
  1277. /**
  1278. * ### .closeTo(expected, delta)
  1279. *
  1280. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  1281. *
  1282. * expect(1.5).to.be.closeTo(1, 0.5);
  1283. *
  1284. * @name closeTo
  1285. * @param {Number} expected
  1286. * @param {Number} delta
  1287. * @param {String} message _optional_
  1288. * @api public
  1289. */
  1290. Assertion.addMethod('closeTo', function (expected, delta, msg) {
  1291. if (msg) flag(this, 'message', msg);
  1292. var obj = flag(this, 'object');
  1293. this.assert(
  1294. Math.abs(obj - expected) <= delta
  1295. , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
  1296. , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
  1297. );
  1298. });
  1299. };
  1300. }); // module: chai/core/assertions.js
  1301. require.register("chai/error.js", function(module, exports, require){
  1302. /*!
  1303. * chai
  1304. * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
  1305. * MIT Licensed
  1306. */
  1307. /*!
  1308. * Main export
  1309. */
  1310. module.exports = AssertionError;
  1311. /**
  1312. * # AssertionError (constructor)
  1313. *
  1314. * Create a new assertion error based on the Javascript
  1315. * `Error` prototype.
  1316. *
  1317. * **Options**
  1318. * - message
  1319. * - actual
  1320. * - expected
  1321. * - operator
  1322. * - startStackFunction
  1323. *
  1324. * @param {Object} options
  1325. * @api public
  1326. */
  1327. function AssertionError (options) {
  1328. options = options || {};
  1329. this.message = options.message;
  1330. this.actual = options.actual;
  1331. this.expected = options.expected;
  1332. this.operator = options.operator;
  1333. this.showDiff = options.showDiff;
  1334. if (options.stackStartFunction && Error.captureStackTrace) {
  1335. var stackStartFunction = options.stackStartFunction;
  1336. Error.captureStackTrace(this, stackStartFunction);
  1337. }
  1338. }
  1339. /*!
  1340. * Inherit from Error
  1341. */
  1342. AssertionError.prototype = Object.create(Error.prototype);
  1343. AssertionError.prototype.name = 'AssertionError';
  1344. AssertionError.prototype.constructor = AssertionError;
  1345. /**
  1346. * # toString()
  1347. *
  1348. * Override default to string method
  1349. */
  1350. AssertionError.prototype.toString = function() {
  1351. return this.message;
  1352. };
  1353. }); // module: chai/error.js
  1354. require.register("chai/interface/assert.js", function(module, exports, require){
  1355. /*!
  1356. * chai
  1357. * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
  1358. * MIT Licensed
  1359. */
  1360. module.exports = function (chai, util) {
  1361. /*!
  1362. * Chai dependencies.
  1363. */
  1364. var Assertion = chai.Assertion
  1365. , flag = util.flag;
  1366. /*!
  1367. * Module export.
  1368. */
  1369. /**
  1370. * ### assert(expression, message)
  1371. *
  1372. * Write your own test expressions.
  1373. *
  1374. * assert('foo' !== 'bar', 'foo is not bar');
  1375. * assert(Array.isArray([]), 'empty arrays are arrays');
  1376. *
  1377. * @param {Mixed} expression to test for truthiness
  1378. * @param {String} message to display on error
  1379. * @name assert
  1380. * @api public
  1381. */
  1382. var assert = chai.assert = function (express, errmsg) {
  1383. var test = new Assertion(null);
  1384. test.assert(
  1385. express
  1386. , errmsg
  1387. , '[ negation message unavailable ]'
  1388. );
  1389. };
  1390. /**
  1391. * ### .fail(actual, expected, [message], [operator])
  1392. *
  1393. * Throw a failure. Node.js `assert` module-compatible.
  1394. *
  1395. * @name fail
  1396. * @param {Mixed} actual
  1397. * @param {Mixed} expected
  1398. * @param {String} message
  1399. * @param {String} operator
  1400. * @api public
  1401. */
  1402. assert.fail = function (actual, expected, message, operator) {
  1403. throw new chai.AssertionError({
  1404. actual: actual
  1405. , expected: expected
  1406. , message: message
  1407. , operator: operator
  1408. , stackStartFunction: assert.fail
  1409. });
  1410. };
  1411. /**
  1412. * ### .ok(object, [message])
  1413. *
  1414. * Asserts that `object` is truthy.
  1415. *
  1416. * assert.ok('everything', 'everything is ok');
  1417. * assert.ok(false, 'this will fail');
  1418. *
  1419. * @name ok
  1420. * @param {Mixed} object to test
  1421. * @param {String} message
  1422. * @api public
  1423. */
  1424. assert.ok = function (val, msg) {
  1425. new Assertion(val, msg).is.ok;
  1426. };
  1427. /**
  1428. * ### .equal(actual, expected, [message])
  1429. *
  1430. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  1431. *
  1432. * assert.equal(3, '3', '== coerces values to strings');
  1433. *
  1434. * @name equal
  1435. * @param {Mixed} actual
  1436. * @param {Mixed} expected
  1437. * @param {String} message
  1438. * @api public
  1439. */
  1440. assert.equal = function (act, exp, msg) {
  1441. var test = new Assertion(act, msg);
  1442. test.assert(
  1443. exp == flag(test, 'object')
  1444. , 'expected #{this} to equal #{exp}'
  1445. , 'expected #{this} to not equal #{act}'
  1446. , exp
  1447. , act
  1448. );
  1449. };
  1450. /**
  1451. * ### .notEqual(actual, expected, [message])
  1452. *
  1453. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  1454. *
  1455. * assert.notEqual(3, 4, 'these numbers are not equal');
  1456. *
  1457. * @name notEqual
  1458. * @param {Mixed} actual
  1459. * @param {Mixed} expected
  1460. * @param {String} message
  1461. * @api public
  1462. */
  1463. assert.notEqual = function (act, exp, msg) {
  1464. var test = new Assertion(act, msg);
  1465. test.assert(
  1466. exp != flag(test, 'object')
  1467. , 'expected #{this} to not equal #{exp}'
  1468. , 'expected #{this} to equal #{act}'
  1469. , exp
  1470. , act
  1471. );
  1472. };
  1473. /**
  1474. * ### .strictEqual(actual, expected, [message])
  1475. *
  1476. * Asserts strict equality (`===`) of `actual` and `expected`.
  1477. *
  1478. * assert.strictEqual(true, true, 'these booleans are strictly equal');
  1479. *
  1480. * @name strictEqual
  1481. * @param {Mixed} actual
  1482. * @param {Mixed} expected
  1483. * @param {String} message
  1484. * @api public
  1485. */
  1486. assert.strictEqual = function (act, exp, msg) {
  1487. new Assertion(act, msg).to.equal(exp);
  1488. };
  1489. /**
  1490. * ### .notStrictEqual(actual, expected, [message])
  1491. *
  1492. * Asserts strict inequality (`!==`) of `actual` and `expected`.
  1493. *
  1494. * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
  1495. *
  1496. * @name notStrictEqual
  1497. * @param {Mixed} actual
  1498. * @param {Mixed} expected
  1499. * @param {String} message
  1500. * @api public
  1501. */
  1502. assert.notStrictEqual = function (act, exp, msg) {
  1503. new Assertion(act, msg).to.not.equal(exp);
  1504. };
  1505. /**
  1506. * ### .deepEqual(actual, expected, [message])
  1507. *
  1508. * Asserts that `actual` is deeply equal to `expected`.
  1509. *
  1510. * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
  1511. *
  1512. * @name deepEqual
  1513. * @param {Mixed} actual
  1514. * @param {Mixed} expected
  1515. * @param {String} message
  1516. * @api public
  1517. */
  1518. assert.deepEqual = function (act, exp, msg) {
  1519. new Assertion(act, msg).to.eql(exp);
  1520. };
  1521. /**
  1522. * ### .notDeepEqual(actual, expected, [message])
  1523. *
  1524. * Assert that `actual` is not deeply equal to `expected`.
  1525. *
  1526. * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
  1527. *
  1528. * @name notDeepEqual
  1529. * @param {Mixed} actual
  1530. * @param {Mixed} expected
  1531. * @param {String} message
  1532. * @api public
  1533. */
  1534. assert.notDeepEqual = function (act, exp, msg) {
  1535. new Assertion(act, msg).to.not.eql(exp);
  1536. };
  1537. /**
  1538. * ### .isTrue(value, [message])
  1539. *
  1540. * Asserts that `value` is true.
  1541. *
  1542. * var teaServed = true;
  1543. * assert.isTrue(teaServed, 'the tea has been served');
  1544. *
  1545. * @name isTrue
  1546. * @param {Mixed} value
  1547. * @param {String} message
  1548. * @api public
  1549. */
  1550. assert.isTrue = function (val, msg) {
  1551. new Assertion(val, msg).is['true'];
  1552. };
  1553. /**
  1554. * ### .isFalse(value, [message])
  1555. *
  1556. * Asserts that `value` is false.
  1557. *
  1558. * var teaServed = false;
  1559. * assert.isFalse(teaServed, 'no tea yet? hmm...');
  1560. *
  1561. * @name isFalse
  1562. * @param {Mixed} value
  1563. * @param {String} message
  1564. * @api public
  1565. */
  1566. assert.isFalse = function (val, msg) {
  1567. new Assertion(val, msg).is['false'];
  1568. };
  1569. /**
  1570. * ### .isNull(value, [message])
  1571. *
  1572. * Asserts that `value` is null.
  1573. *
  1574. * assert.isNull(err, 'there was no error');
  1575. *
  1576. * @name isNull
  1577. * @param {Mixed} value
  1578. * @param {String} message
  1579. * @api public
  1580. */
  1581. assert.isNull = function (val, msg) {
  1582. new Assertion(val, msg).to.equal(null);
  1583. };
  1584. /**
  1585. * ### .isNotNull(value, [message])
  1586. *
  1587. * Asserts that `value` is not null.
  1588. *
  1589. * var tea = 'tasty chai';
  1590. * assert.isNotNull(tea, 'great, time for tea!');
  1591. *
  1592. * @name isNotNull
  1593. * @param {Mixed} value
  1594. * @param {String} message
  1595. * @api public
  1596. */
  1597. assert.isNotNull = function (val, msg) {
  1598. new Assertion(val, msg).to.not.equal(null);
  1599. };
  1600. /**
  1601. * ### .isUndefined(value, [message])
  1602. *
  1603. * Asserts that `value` is `undefined`.
  1604. *
  1605. * var tea;
  1606. * assert.isUndefined(tea, 'no tea defined');
  1607. *
  1608. * @name isUndefined
  1609. * @param {Mixed} value
  1610. * @param {String} message
  1611. * @api public
  1612. */
  1613. assert.isUndefined = function (val, msg) {
  1614. new Assertion(val, msg).to.equal(undefined);
  1615. };
  1616. /**
  1617. * ### .isDefined(value, [message])
  1618. *
  1619. * Asserts that `value` is not `undefined`.
  1620. *
  1621. * var tea = 'cup of chai';
  1622. * assert.isDefined(tea, 'tea has been defined');
  1623. *
  1624. * @name isUndefined
  1625. * @param {Mixed} value
  1626. * @param {String} message
  1627. * @api public
  1628. */
  1629. assert.isDefined = function (val, msg) {
  1630. new Assertion(val, msg).to.not.equal(undefined);
  1631. };
  1632. /**
  1633. * ### .isFunction(value, [message])
  1634. *
  1635. * Asserts that `value` is a function.
  1636. *
  1637. * function serveTea() { return 'cup of tea'; };
  1638. * assert.isFunction(serveTea, 'great, we can have tea now');
  1639. *
  1640. * @name isFunction
  1641. * @param {Mixed} value
  1642. * @param {String} message
  1643. * @api public
  1644. */
  1645. assert.isFunction = function (val, msg) {
  1646. new Assertion(val, msg).to.be.a('function');
  1647. };
  1648. /**
  1649. * ### .isNotFunction(value, [message])
  1650. *
  1651. * Asserts that `value` is _not_ a function.
  1652. *
  1653. * var serveTea = [ 'heat', 'pour', 'sip' ];
  1654. * assert.isNotFunction(serveTea, 'great, we have listed the steps');
  1655. *
  1656. * @name isNotFunction
  1657. * @param {Mixed} value
  1658. * @param {String} message
  1659. * @api public
  1660. */
  1661. assert.isNotFunction = function (val, msg) {
  1662. new Assertion(val, msg).to.not.be.a('function');
  1663. };
  1664. /**
  1665. * ### .isObject(value, [message])
  1666. *
  1667. * Asserts that `value` is an object (as revealed by
  1668. * `Object.prototype.toString`).
  1669. *
  1670. * var selection = { name: 'Chai', serve: 'with spices' };
  1671. * assert.isObject(selection, 'tea selection is an object');
  1672. *
  1673. * @name isObject
  1674. * @param {Mixed} value
  1675. * @param {String} message
  1676. * @api public
  1677. */
  1678. assert.isObject = function (val, msg) {
  1679. new Assertion(val, msg).to.be.a('object');
  1680. };
  1681. /**
  1682. * ### .isNotObject(value, [message])
  1683. *
  1684. * Asserts that `value` is _not_ an object.
  1685. *
  1686. * var selection = 'chai'
  1687. * assert.isObject(selection, 'tea selection is not an object');
  1688. * assert.isObject(null, 'null is not an object');
  1689. *
  1690. * @name isNotObject
  1691. * @param {Mixed} value
  1692. * @param {String} message
  1693. * @api public
  1694. */
  1695. assert.isNotObject = function (val, msg) {
  1696. new Assertion(val, msg).to.not.be.a('object');
  1697. };
  1698. /**
  1699. * ### .isArray(value, [message])
  1700. *
  1701. * Asserts that `value` is an array.
  1702. *
  1703. * var menu = [ 'green', 'chai', 'oolong' ];
  1704. * assert.isArray(menu, 'what kind of tea do we want?');
  1705. *
  1706. * @name isArray
  1707. * @param {Mixed} value
  1708. * @param {String} message
  1709. * @api public
  1710. */
  1711. assert.isArray = function (val, msg) {
  1712. new Assertion(val, msg).to.be.an('array');
  1713. };
  1714. /**
  1715. * ### .isNotArray(value, [message])
  1716. *
  1717. * Asserts that `value` is _not_ an array.
  1718. *
  1719. * var menu = 'green|chai|oolong';
  1720. * assert.isNotArray(menu, 'what kind of tea do we want?');
  1721. *
  1722. * @name isNotArray
  1723. * @param {Mixed} value
  1724. * @param {String} message
  1725. * @api public
  1726. */
  1727. assert.isNotArray = function (val, msg) {
  1728. new Assertion(val, msg).to.not.be.an('array');
  1729. };
  1730. /**
  1731. * ### .isString(value, [message])
  1732. *
  1733. * Asserts that `value` is a string.
  1734. *
  1735. * var teaOrder = 'chai';
  1736. * assert.isString(teaOrder, 'order placed');
  1737. *
  1738. * @name isString
  1739. * @param {Mixed} value
  1740. * @param {String} message
  1741. * @api public
  1742. */
  1743. assert.isString = function (val, msg) {
  1744. new Assertion(val, msg).to.be.a('string');
  1745. };
  1746. /**
  1747. * ### .isNotString(value, [message])
  1748. *
  1749. * Asserts that `value` is _not_ a string.
  1750. *
  1751. * var teaOrder = 4;
  1752. * assert.isNotString(teaOrder, 'order placed');
  1753. *
  1754. * @name isNotString
  1755. * @param {Mixed} value
  1756. * @param {String} message
  1757. * @api public
  1758. */
  1759. assert.isNotString = function (val, msg) {
  1760. new Assertion(val, msg).to.not.be.a('string');
  1761. };
  1762. /**
  1763. * ### .isNumber(value, [message])
  1764. *
  1765. * Asserts that `value` is a number.
  1766. *
  1767. * var cups = 2;
  1768. * assert.isNumber(cups, 'how many cups');
  1769. *
  1770. * @name isNumber
  1771. * @param {Number} value
  1772. * @param {String} message
  1773. * @api public
  1774. */
  1775. assert.isNumber = function (val, msg) {
  1776. new Assertion(val, msg).to.be.a('number');
  1777. };
  1778. /**
  1779. * ### .isNotNumber(value, [message])
  1780. *
  1781. * Asserts that `value` is _not_ a number.
  1782. *
  1783. * var cups = '2 cups please';
  1784. * assert.isNotNumber(cups, 'how many cups');
  1785. *
  1786. * @name isNotNumber
  1787. * @param {Mixed} value
  1788. * @param {String} message
  1789. * @api public
  1790. */
  1791. assert.isNotNumber = function (val, msg) {
  1792. new Assertion(val, msg).to.not.be.a('number');
  1793. };
  1794. /**
  1795. * ### .isBoolean(value, [message])
  1796. *
  1797. * Asserts that `value` is a boolean.
  1798. *
  1799. * var teaReady = true
  1800. * , teaServed = false;
  1801. *
  1802. * assert.isBoolean(teaReady, 'is the tea ready');
  1803. * assert.isBoolean(teaServed, 'has tea been served');
  1804. *
  1805. * @name isBoolean
  1806. * @param {Mixed} value
  1807. * @param {String} message
  1808. * @api public
  1809. */
  1810. assert.isBoolean = function (val, msg) {
  1811. new Assertion(val, msg).to.be.a('boolean');
  1812. };
  1813. /**
  1814. * ### .isNotBoolean(value, [message])
  1815. *
  1816. * Asserts that `value` is _not_ a boolean.
  1817. *
  1818. * var teaReady = 'yep'
  1819. * , teaServed = 'nope';
  1820. *
  1821. * assert.isNotBoolean(teaReady, 'is the tea ready');
  1822. * assert.isNotBoolean(teaServed, 'has tea been served');
  1823. *
  1824. * @name isNotBoolean
  1825. * @param {Mixed} value
  1826. * @param {String} message
  1827. * @api public
  1828. */
  1829. assert.isNotBoolean = function (val, msg) {
  1830. new Assertion(val, msg).to.not.be.a('boolean');
  1831. };
  1832. /**
  1833. * ### .typeOf(value, name, [message])
  1834. *
  1835. * Asserts that `value`'s type is `name`, as determined by
  1836. * `Object.prototype.toString`.
  1837. *
  1838. * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
  1839. * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
  1840. * assert.typeOf('tea', 'string', 'we have a string');
  1841. * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
  1842. * assert.typeOf(null, 'null', 'we have a null');
  1843. * assert.typeOf(undefined, 'undefined', 'we have an undefined');
  1844. *
  1845. * @name typeOf
  1846. * @param {Mixed} value
  1847. * @param {String} name
  1848. * @param {String} message
  1849. * @api public
  1850. */
  1851. assert.typeOf = function (val, type, msg) {
  1852. new Assertion(val, msg).to.be.a(type);
  1853. };
  1854. /**
  1855. * ### .notTypeOf(value, name, [message])
  1856. *
  1857. * Asserts that `value`'s type is _not_ `name`, as determined by
  1858. * `Object.prototype.toString`.
  1859. *
  1860. * assert.notTypeOf('tea', 'number', 'strings are not numbers');
  1861. *
  1862. * @name notTypeOf
  1863. * @param {Mixed} value
  1864. * @param {String} typeof name
  1865. * @param {String} message
  1866. * @api public
  1867. */
  1868. assert.notTypeOf = function (val, type, msg) {
  1869. new Assertion(val, msg).to.not.be.a(type);
  1870. };
  1871. /**
  1872. * ### .instanceOf(object, constructor, [message])
  1873. *
  1874. * Asserts that `value` is an instance of `constructor`.
  1875. *
  1876. * var Tea = function (name) { this.name = name; }
  1877. * , chai = new Tea('chai');
  1878. *
  1879. * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
  1880. *
  1881. * @name instanceOf
  1882. * @param {Object} object
  1883. * @param {Constructor} constructor
  1884. * @param {String} message
  1885. * @api public
  1886. */
  1887. assert.instanceOf = function (val, type, msg) {
  1888. new Assertion(val, msg).to.be.instanceOf(type);
  1889. };
  1890. /**
  1891. * ### .notInstanceOf(object, constructor, [message])
  1892. *
  1893. * Asserts `value` is not an instance of `constructor`.
  1894. *
  1895. * var Tea = function (name) { this.name = name; }
  1896. * , chai = new String('chai');
  1897. *
  1898. * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
  1899. *
  1900. * @name notInstanceOf
  1901. * @param {Object} object
  1902. * @param {Constructor} constructor
  1903. * @param {String} message
  1904. * @api public
  1905. */
  1906. assert.notInstanceOf = function (val, type, msg) {
  1907. new Assertion(val, msg).to.not.be.instanceOf(type);
  1908. };
  1909. /**
  1910. * ### .include(haystack, needle, [message])
  1911. *
  1912. * Asserts that `haystack` includes `needle`. Works
  1913. * for strings and arrays.
  1914. *
  1915. * assert.include('foobar', 'bar', 'foobar contains string "bar"');
  1916. * assert.include([ 1, 2, 3 ], 3, 'array contains value');
  1917. *
  1918. * @name include
  1919. * @param {Array|String} haystack
  1920. * @param {Mixed} needle
  1921. * @param {String} message
  1922. * @api public
  1923. */
  1924. assert.include = function (exp, inc, msg) {
  1925. var obj = new Assertion(exp, msg);
  1926. if (Array.isArray(exp)) {
  1927. obj.to.include(inc);
  1928. } else if ('string' === typeof exp) {
  1929. obj.to.contain.string(inc);
  1930. }
  1931. };
  1932. /**
  1933. * ### .match(value, regexp, [message])
  1934. *
  1935. * Asserts that `value` matches the regular expression `regexp`.
  1936. *
  1937. * assert.match('foobar', /^foo/, 'regexp matches');
  1938. *
  1939. * @name match
  1940. * @param {Mixed} value
  1941. * @param {RegExp} regexp
  1942. * @param {String} message
  1943. * @api public
  1944. */
  1945. assert.match = function (exp, re, msg) {
  1946. new Assertion(exp, msg).to.match(re);
  1947. };
  1948. /**
  1949. * ### .notMatch(value, regexp, [message])
  1950. *
  1951. * Asserts that `value` does not match the regular expression `regexp`.
  1952. *
  1953. * assert.notMatch('foobar', /^foo/, 'regexp does not match');
  1954. *
  1955. * @name notMatch
  1956. * @param {Mixed} value
  1957. * @param {RegExp} regexp
  1958. * @param {String} message
  1959. * @api public
  1960. */
  1961. assert.notMatch = function (exp, re, msg) {
  1962. new Assertion(exp, msg).to.not.match(re);
  1963. };
  1964. /**
  1965. * ### .property(object, property, [message])
  1966. *
  1967. * Asserts that `object` has a property named by `property`.
  1968. *
  1969. * assert.property({ tea: { green: 'matcha' }}, 'tea');
  1970. *
  1971. * @name property
  1972. * @param {Object} object
  1973. * @param {String} property
  1974. * @param {String} message
  1975. * @api public
  1976. */
  1977. assert.property = function (obj, prop, msg) {
  1978. new Assertion(obj, msg).to.have.property(prop);
  1979. };
  1980. /**
  1981. * ### .notProperty(object, property, [message])
  1982. *
  1983. * Asserts that `object` does _not_ have a property named by `property`.
  1984. *
  1985. * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
  1986. *
  1987. * @name notProperty
  1988. * @param {Object} object
  1989. * @param {String} property
  1990. * @param {String} message
  1991. * @api public
  1992. */
  1993. assert.notProperty = function (obj, prop, msg) {
  1994. new Assertion(obj, msg).to.not.have.property(prop);
  1995. };
  1996. /**
  1997. * ### .deepProperty(object, property, [message])
  1998. *
  1999. * Asserts that `object` has a property named by `property`, which can be a
  2000. * string using dot- and bracket-notation for deep reference.
  2001. *
  2002. * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
  2003. *
  2004. * @name deepProperty
  2005. * @param {Object} object
  2006. * @param {String} property
  2007. * @param {String} message
  2008. * @api public
  2009. */
  2010. assert.deepProperty = function (obj, prop, msg) {
  2011. new Assertion(obj, msg).to.have.deep.property(prop);
  2012. };
  2013. /**
  2014. * ### .notDeepProperty(object, property, [message])
  2015. *
  2016. * Asserts that `object` does _not_ have a property named by `property`, which
  2017. * can be a string using dot- and bracket-notation for deep reference.
  2018. *
  2019. * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
  2020. *
  2021. * @name notDeepProperty
  2022. * @param {Object} object
  2023. * @param {String} property
  2024. * @param {String} message
  2025. * @api public
  2026. */
  2027. assert.notDeepProperty = function (obj, prop, msg) {
  2028. new Assertion(obj, msg).to.not.have.deep.property(prop);
  2029. };
  2030. /**
  2031. * ### .propertyVal(object, property, value, [message])
  2032. *
  2033. * Asserts that `object` has a property named by `property` with value given
  2034. * by `value`.
  2035. *
  2036. * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
  2037. *
  2038. * @name propertyVal
  2039. * @param {Object} object
  2040. * @param {String} property
  2041. * @param {Mixed} value
  2042. * @param {String} message
  2043. * @api public
  2044. */
  2045. assert.propertyVal = function (obj, prop, val, msg) {
  2046. new Assertion(obj, msg).to.have.property(prop, val);
  2047. };
  2048. /**
  2049. * ### .propertyNotVal(object, property, value, [message])
  2050. *
  2051. * Asserts that `object` has a property named by `property`, but with a value
  2052. * different from that given by `value`.
  2053. *
  2054. * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
  2055. *
  2056. * @name propertyNotVal
  2057. * @param {Object} object
  2058. * @param {String} property
  2059. * @param {Mixed} value
  2060. * @param {String} message
  2061. * @api public
  2062. */
  2063. assert.propertyNotVal = function (obj, prop, val, msg) {
  2064. new Assertion(obj, msg).to.not.have.property(prop, val);
  2065. };
  2066. /**
  2067. * ### .deepPropertyVal(object, property, value, [message])
  2068. *
  2069. * Asserts that `object` has a property named by `property` with value given
  2070. * by `value`. `property` can use dot- and bracket-notation for deep
  2071. * reference.
  2072. *
  2073. * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
  2074. *
  2075. * @name deepPropertyVal
  2076. * @param {Object} object
  2077. * @param {String} property
  2078. * @param {Mixed} value
  2079. * @param {String} message
  2080. * @api public
  2081. */
  2082. assert.deepPropertyVal = function (obj, prop, val, msg) {
  2083. new Assertion(obj, msg).to.have.deep.property(prop, val);
  2084. };
  2085. /**
  2086. * ### .deepPropertyNotVal(object, property, value, [message])
  2087. *
  2088. * Asserts that `object` has a property named by `property`, but with a value
  2089. * different from that given by `value`. `property` can use dot- and
  2090. * bracket-notation for deep reference.
  2091. *
  2092. * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
  2093. *
  2094. * @name deepPropertyNotVal
  2095. * @param {Object} object
  2096. * @param {String} property
  2097. * @param {Mixed} value
  2098. * @param {String} message
  2099. * @api public
  2100. */
  2101. assert.deepPropertyNotVal = function (obj, prop, val, msg) {
  2102. new Assertion(obj, msg).to.not.have.deep.property(prop, val);
  2103. };
  2104. /**
  2105. * ### .lengthOf(object, length, [message])
  2106. *
  2107. * Asserts that `object` has a `length` property with the expected value.
  2108. *
  2109. * assert.lengthOf([1,2,3], 3, 'array has length of 3');
  2110. * assert.lengthOf('foobar', 5, 'string has length of 6');
  2111. *
  2112. * @name lengthOf
  2113. * @param {Mixed} object
  2114. * @param {Number} length
  2115. * @param {String} message
  2116. * @api public
  2117. */
  2118. assert.lengthOf = function (exp, len, msg) {
  2119. new Assertion(exp, msg).to.have.length(len);
  2120. };
  2121. /**
  2122. * ### .throws(function, [constructor/string/regexp], [string/regexp], [message])
  2123. *
  2124. * Asserts that `function` will throw an error that is an instance of
  2125. * `constructor`, or alternately that it will throw an error with message
  2126. * matching `regexp`.
  2127. *
  2128. * assert.throw(fn, 'function throws a reference error');
  2129. * assert.throw(fn, /function throws a reference error/);
  2130. * assert.throw(fn, ReferenceError);
  2131. * assert.throw(fn, ReferenceError, 'function throws a reference error');
  2132. * assert.throw(fn, ReferenceError, /function throws a reference error/);
  2133. *
  2134. * @name throws
  2135. * @alias throw
  2136. * @alias Throw
  2137. * @param {Function} function
  2138. * @param {ErrorConstructor} constructor
  2139. * @param {RegExp} regexp
  2140. * @param {String} message
  2141. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  2142. * @api public
  2143. */
  2144. assert.Throw = function (fn, errt, errs, msg) {
  2145. if ('string' === typeof errt || errt instanceof RegExp) {
  2146. errs = errt;
  2147. errt = null;
  2148. }
  2149. new Assertion(fn, msg).to.Throw(errt, errs);
  2150. };
  2151. /**
  2152. * ### .doesNotThrow(function, [constructor/regexp], [message])
  2153. *
  2154. * Asserts that `function` will _not_ throw an error that is an instance of
  2155. * `constructor`, or alternately that it will not throw an error with message
  2156. * matching `regexp`.
  2157. *
  2158. * assert.doesNotThrow(fn, Error, 'function does not throw');
  2159. *
  2160. * @name doesNotThrow
  2161. * @param {Function} function
  2162. * @param {ErrorConstructor} constructor
  2163. * @param {RegExp} regexp
  2164. * @param {String} message
  2165. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  2166. * @api public
  2167. */
  2168. assert.doesNotThrow = function (fn, type, msg) {
  2169. if ('string' === typeof type) {
  2170. msg = type;
  2171. type = null;
  2172. }
  2173. new Assertion(fn, msg).to.not.Throw(type);
  2174. };
  2175. /**
  2176. * ### .operator(val1, operator, val2, [message])
  2177. *
  2178. * Compares two values using `operator`.
  2179. *
  2180. * assert.operator(1, '<', 2, 'everything is ok');
  2181. * assert.operator(1, '>', 2, 'this will fail');
  2182. *
  2183. * @name operator
  2184. * @param {Mixed} val1
  2185. * @param {String} operator
  2186. * @param {Mixed} val2
  2187. * @param {String} message
  2188. * @api public
  2189. */
  2190. assert.operator = function (val, operator, val2, msg) {
  2191. if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
  2192. throw new Error('Invalid operator "' + operator + '"');
  2193. }
  2194. var test = new Assertion(eval(val + operator + val2), msg);
  2195. test.assert(
  2196. true === flag(test, 'object')
  2197. , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
  2198. , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
  2199. };
  2200. /**
  2201. * ### .closeTo(actual, expected, delta, [message])
  2202. *
  2203. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  2204. *
  2205. * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
  2206. *
  2207. * @name closeTo
  2208. * @param {Number} actual
  2209. * @param {Number} expected
  2210. * @param {Number} delta
  2211. * @param {String} message
  2212. * @api public
  2213. */
  2214. assert.closeTo = function (act, exp, delta, msg) {
  2215. new Assertion(act, msg).to.be.closeTo(exp, delta);
  2216. };
  2217. /*!
  2218. * Undocumented / untested
  2219. */
  2220. assert.ifError = function (val, msg) {
  2221. new Assertion(val, msg).to.not.be.ok;
  2222. };
  2223. /*!
  2224. * Aliases.
  2225. */
  2226. (function alias(name, as){
  2227. assert[as] = assert[name];
  2228. return alias;
  2229. })
  2230. ('Throw', 'throw')
  2231. ('Throw', 'throws');
  2232. };
  2233. }); // module: chai/interface/assert.js
  2234. require.register("chai/interface/expect.js", function(module, exports, require){
  2235. /*!
  2236. * chai
  2237. * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
  2238. * MIT Licensed
  2239. */
  2240. module.exports = function (chai, util) {
  2241. chai.expect = function (val, message) {
  2242. return new chai.Assertion(val, message);
  2243. };
  2244. };
  2245. }); // module: chai/interface/expect.js
  2246. require.register("chai/interface/should.js", function(module, exports, require){
  2247. /*!
  2248. * chai
  2249. * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
  2250. * MIT Licensed
  2251. */
  2252. module.exports = function (chai, util) {
  2253. var Assertion = chai.Assertion;
  2254. function loadShould () {
  2255. // modify Object.prototype to have `should`
  2256. Object.defineProperty(Object.prototype, 'should',
  2257. {
  2258. set: function (value) {
  2259. // See https://github.com/chaijs/chai/issues/86: this makes
  2260. // `whatever.should = someValue` actually set `someValue`, which is
  2261. // especially useful for `global.should = require('chai').should()`.
  2262. //
  2263. // Note that we have to use [[DefineProperty]] instead of [[Put]]
  2264. // since otherwise we would trigger this very setter!
  2265. Object.defineProperty(this, 'should', {
  2266. value: value,
  2267. enumerable: true,
  2268. configurable: true,
  2269. writable: true
  2270. });
  2271. }
  2272. , get: function(){
  2273. if (this instanceof String || this instanceof Number) {
  2274. return new Assertion(this.constructor(this));
  2275. } else if (this instanceof Boolean) {
  2276. return new Assertion(this == true);
  2277. }
  2278. return new Assertion(this);
  2279. }
  2280. , configurable: true
  2281. });
  2282. var should = {};
  2283. should.equal = function (val1, val2, msg) {
  2284. new Assertion(val1, msg).to.equal(val2);
  2285. };
  2286. should.Throw = function (fn, errt, errs, msg) {
  2287. new Assertion(fn, msg).to.Throw(errt, errs);
  2288. };
  2289. should.exist = function (val, msg) {
  2290. new Assertion(val, msg).to.exist;
  2291. }
  2292. // negation
  2293. should.not = {}
  2294. should.not.equal = function (val1, val2, msg) {
  2295. new Assertion(val1, msg).to.not.equal(val2);
  2296. };
  2297. should.not.Throw = function (fn, errt, errs, msg) {
  2298. new Assertion(fn, msg).to.not.Throw(errt, errs);
  2299. };
  2300. should.not.exist = function (val, msg) {
  2301. new Assertion(val, msg).to.not.exist;
  2302. }
  2303. should['throw'] = should['Throw'];
  2304. should.not['throw'] = should.not['Throw'];
  2305. return should;
  2306. };
  2307. chai.should = loadShould;
  2308. chai.Should = loadShould;
  2309. };
  2310. }); // module: chai/interface/should.js
  2311. require.register("chai/utils/addChainableMethod.js", function(module, exports, require){
  2312. /*!
  2313. * Chai - addChainingMethod utility
  2314. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  2315. * MIT Licensed
  2316. */
  2317. /*!
  2318. * Module dependencies
  2319. */
  2320. var transferFlags = require('./transferFlags');
  2321. /**
  2322. * ### addChainableMethod (ctx, name, method, chainingBehavior)
  2323. *
  2324. * Adds a method to an object, such that the method can also be chained.
  2325. *
  2326. * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
  2327. * var obj = utils.flag(this, 'object');
  2328. * new chai.Assertion(obj).to.be.equal(str);
  2329. * });
  2330. *
  2331. * Can also be accessed directly from `chai.Assertion`.
  2332. *
  2333. * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
  2334. *
  2335. * The result can then be used as both a method assertion, executing both `method` and
  2336. * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
  2337. *
  2338. * expect(fooStr).to.be.foo('bar');
  2339. * expect(fooStr).to.be.foo.equal('foo');
  2340. *
  2341. * @param {Object} ctx object to which the method is added
  2342. * @param {String} name of method to add
  2343. * @param {Function} method function to be used for `name`, when called
  2344. * @param {Function} chainingBehavior function to be called every time the property is accessed
  2345. * @name addChainableMethod
  2346. * @api public
  2347. */
  2348. module.exports = function (ctx, name, method, chainingBehavior) {
  2349. if (typeof chainingBehavior !== 'function')
  2350. chainingBehavior = function () { };
  2351. Object.defineProperty(ctx, name,
  2352. { get: function () {
  2353. chainingBehavior.call(this);
  2354. var assert = function () {
  2355. var result = method.apply(this, arguments);
  2356. return result === undefined ? this : result;
  2357. };
  2358. // Re-enumerate every time to better accomodate plugins.
  2359. var asserterNames = Object.getOwnPropertyNames(ctx);
  2360. asserterNames.forEach(function (asserterName) {
  2361. var pd = Object.getOwnPropertyDescriptor(ctx, asserterName)
  2362. , functionProtoPD = Object.getOwnPropertyDescriptor(Function.prototype, asserterName);
  2363. // Avoid trying to overwrite things that we can't, like `length` and `arguments`.
  2364. if (functionProtoPD && !functionProtoPD.configurable) return;
  2365. if (asserterName === 'arguments') return; // @see chaijs/chai/issues/69
  2366. Object.defineProperty(assert, asserterName, pd);
  2367. });
  2368. transferFlags(this, assert);
  2369. return assert;
  2370. }
  2371. , configurable: true
  2372. });
  2373. };
  2374. }); // module: chai/utils/addChainableMethod.js
  2375. require.register("chai/utils/addMethod.js", function(module, exports, require){
  2376. /*!
  2377. * Chai - addMethod utility
  2378. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  2379. * MIT Licensed
  2380. */
  2381. /**
  2382. * ### .addMethod (ctx, name, method)
  2383. *
  2384. * Adds a method to the prototype of an object.
  2385. *
  2386. * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
  2387. * var obj = utils.flag(this, 'object');
  2388. * new chai.Assertion(obj).to.be.equal(str);
  2389. * });
  2390. *
  2391. * Can also be accessed directly from `chai.Assertion`.
  2392. *
  2393. * chai.Assertion.addMethod('foo', fn);
  2394. *
  2395. * Then can be used as any other assertion.
  2396. *
  2397. * expect(fooStr).to.be.foo('bar');
  2398. *
  2399. * @param {Object} ctx object to which the method is added
  2400. * @param {String} name of method to add
  2401. * @param {Function} method function to be used for name
  2402. * @name addMethod
  2403. * @api public
  2404. */
  2405. module.exports = function (ctx, name, method) {
  2406. ctx[name] = function () {
  2407. var result = method.apply(this, arguments);
  2408. return result === undefined ? this : result;
  2409. };
  2410. };
  2411. }); // module: chai/utils/addMethod.js
  2412. require.register("chai/utils/addProperty.js", function(module, exports, require){
  2413. /*!
  2414. * Chai - addProperty utility
  2415. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  2416. * MIT Licensed
  2417. */
  2418. /**
  2419. * ### addProperty (ctx, name, getter)
  2420. *
  2421. * Adds a property to the prototype of an object.
  2422. *
  2423. * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
  2424. * var obj = utils.flag(this, 'object');
  2425. * new chai.Assertion(obj).to.be.instanceof(Foo);
  2426. * });
  2427. *
  2428. * Can also be accessed directly from `chai.Assertion`.
  2429. *
  2430. * chai.Assertion.addProperty('foo', fn);
  2431. *
  2432. * Then can be used as any other assertion.
  2433. *
  2434. * expect(myFoo).to.be.foo;
  2435. *
  2436. * @param {Object} ctx object to which the property is added
  2437. * @param {String} name of property to add
  2438. * @param {Function} getter function to be used for name
  2439. * @name addProperty
  2440. * @api public
  2441. */
  2442. module.exports = function (ctx, name, getter) {
  2443. Object.defineProperty(ctx, name,
  2444. { get: function () {
  2445. var result = getter.call(this);
  2446. return result === undefined ? this : result;
  2447. }
  2448. , configurable: true
  2449. });
  2450. };
  2451. }); // module: chai/utils/addProperty.js
  2452. require.register("chai/utils/eql.js", function(module, exports, require){
  2453. // This is (almost) directly from Node.js assert
  2454. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
  2455. module.exports = _deepEqual;
  2456. // for the browser
  2457. var Buffer;
  2458. try {
  2459. Buffer = require('buffer').Buffer;
  2460. } catch (ex) {
  2461. Buffer = {
  2462. isBuffer: function () { return false; }
  2463. };
  2464. }
  2465. function _deepEqual(actual, expected, memos) {
  2466. // 7.1. All identical values are equivalent, as determined by ===.
  2467. if (actual === expected) {
  2468. return true;
  2469. } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
  2470. if (actual.length != expected.length) return false;
  2471. for (var i = 0; i < actual.length; i++) {
  2472. if (actual[i] !== expected[i]) return false;
  2473. }
  2474. return true;
  2475. // 7.2. If the expected value is a Date object, the actual value is
  2476. // equivalent if it is also a Date object that refers to the same time.
  2477. } else if (actual instanceof Date && expected instanceof Date) {
  2478. return actual.getTime() === expected.getTime();
  2479. // 7.3. Other pairs that do not both pass typeof value == 'object',
  2480. // equivalence is determined by ==.
  2481. } else if (typeof actual != 'object' && typeof expected != 'object') {
  2482. return actual === expected;
  2483. // 7.4. For all other Object pairs, including Array objects, equivalence is
  2484. // determined by having the same number of owned properties (as verified
  2485. // with Object.prototype.hasOwnProperty.call), the same set of keys
  2486. // (although not necessarily the same order), equivalent values for every
  2487. // corresponding key, and an identical 'prototype' property. Note: this
  2488. // accounts for both named and indexed properties on Arrays.
  2489. } else {
  2490. return objEquiv(actual, expected, memos);
  2491. }
  2492. }
  2493. function isUndefinedOrNull(value) {
  2494. return value === null || value === undefined;
  2495. }
  2496. function isArguments(object) {
  2497. return Object.prototype.toString.call(object) == '[object Arguments]';
  2498. }
  2499. function objEquiv(a, b, memos) {
  2500. if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
  2501. return false;
  2502. // an identical 'prototype' property.
  2503. if (a.prototype !== b.prototype) return false;
  2504. // check if we have already compared a and b
  2505. var i;
  2506. if (memos) {
  2507. for(i = 0; i < memos.length; i++) {
  2508. if ((memos[i][0] === a && memos[i][1] === b) ||
  2509. (memos[i][0] === b && memos[i][1] === a))
  2510. return true;
  2511. }
  2512. } else {
  2513. memos = [];
  2514. }
  2515. //~~~I've managed to break Object.keys through screwy arguments passing.
  2516. // Converting to array solves the problem.
  2517. if (isArguments(a)) {
  2518. if (!isArguments(b)) {
  2519. return false;
  2520. }
  2521. a = pSlice.call(a);
  2522. b = pSlice.call(b);
  2523. return _deepEqual(a, b, memos);
  2524. }
  2525. try {
  2526. var ka = Object.keys(a),
  2527. kb = Object.keys(b),
  2528. key;
  2529. } catch (e) {//happens when one is a string literal and the other isn't
  2530. return false;
  2531. }
  2532. // having the same number of owned properties (keys incorporates
  2533. // hasOwnProperty)
  2534. if (ka.length != kb.length)
  2535. return false;
  2536. //the same set of keys (although not necessarily the same order),
  2537. ka.sort();
  2538. kb.sort();
  2539. //~~~cheap key test
  2540. for (i = ka.length - 1; i >= 0; i--) {
  2541. if (ka[i] != kb[i])
  2542. return false;
  2543. }
  2544. // remember objects we have compared to guard against circular references
  2545. memos.push([ a, b ]);
  2546. //equivalent values for every corresponding key, and
  2547. //~~~possibly expensive deep test
  2548. for (i = ka.length - 1; i >= 0; i--) {
  2549. key = ka[i];
  2550. if (!_deepEqual(a[key], b[key], memos)) return false;
  2551. }
  2552. return true;
  2553. }
  2554. }); // module: chai/utils/eql.js
  2555. require.register("chai/utils/flag.js", function(module, exports, require){
  2556. /*!
  2557. * Chai - flag utility
  2558. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  2559. * MIT Licensed
  2560. */
  2561. /**
  2562. * ### flag(object ,key, [value])
  2563. *
  2564. * Get or set a flag value on an object. If a
  2565. * value is provided it will be set, else it will
  2566. * return the currently set value or `undefined` if
  2567. * the value is not set.
  2568. *
  2569. * utils.flag(this, 'foo', 'bar'); // setter
  2570. * utils.flag(this, 'foo'); // getter, returns `bar`
  2571. *
  2572. * @param {Object} object (constructed Assertion
  2573. * @param {String} key
  2574. * @param {Mixed} value (optional)
  2575. * @name flag
  2576. * @api private
  2577. */
  2578. module.exports = function (obj, key, value) {
  2579. var flags = obj.__flags || (obj.__flags = Object.create(null));
  2580. if (arguments.length === 3) {
  2581. flags[key] = value;
  2582. } else {
  2583. return flags[key];
  2584. }
  2585. };
  2586. }); // module: chai/utils/flag.js
  2587. require.register("chai/utils/getActual.js", function(module, exports, require){
  2588. /*!
  2589. * Chai - getActual utility
  2590. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  2591. * MIT Licensed
  2592. */
  2593. /**
  2594. * # getActual(object, [actual])
  2595. *
  2596. * Returns the `actual` value for an Assertion
  2597. *
  2598. * @param {Object} object (constructed Assertion)
  2599. * @param {Arguments} chai.Assertion.prototype.assert arguments
  2600. */
  2601. module.exports = function (obj, args) {
  2602. var actual = args[4];
  2603. return 'undefined' !== typeof actual ? actual : obj._obj;
  2604. };
  2605. }); // module: chai/utils/getActual.js
  2606. require.register("chai/utils/getMessage.js", function(module, exports, require){
  2607. /*!
  2608. * Chai - message composition utility
  2609. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  2610. * MIT Licensed
  2611. */
  2612. /*!
  2613. * Module dependancies
  2614. */
  2615. var flag = require('./flag')
  2616. , getActual = require('./getActual')
  2617. , inspect = require('./inspect')
  2618. , objDisplay = require('./objDisplay');
  2619. /**
  2620. * ### .getMessage(object, message, negateMessage)
  2621. *
  2622. * Construct the error message based on flags
  2623. * and template tags. Template tags will return
  2624. * a stringified inspection of the object referenced.
  2625. *
  2626. * Messsage template tags:
  2627. * - `#{this}` current asserted object
  2628. * - `#{act}` actual value
  2629. * - `#{exp}` expected value
  2630. *
  2631. * @param {Object} object (constructed Assertion)
  2632. * @param {Arguments} chai.Assertion.prototype.assert arguments
  2633. * @name getMessage
  2634. * @api public
  2635. */
  2636. module.exports = function (obj, args) {
  2637. var negate = flag(obj, 'negate')
  2638. , val = flag(obj, 'object')
  2639. , expected = args[3]
  2640. , actual = getActual(obj, args)
  2641. , msg = negate ? args[2] : args[1]
  2642. , flagMsg = flag(obj, 'message');
  2643. msg = msg || '';
  2644. msg = msg
  2645. .replace(/#{this}/g, objDisplay(val))
  2646. .replace(/#{act}/g, objDisplay(actual))
  2647. .replace(/#{exp}/g, objDisplay(expected));
  2648. return flagMsg ? flagMsg + ': ' + msg : msg;
  2649. };
  2650. }); // module: chai/utils/getMessage.js
  2651. require.register("chai/utils/getName.js", function(module, exports, require){
  2652. /*!
  2653. * Chai - getName utility
  2654. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  2655. * MIT Licensed
  2656. */
  2657. /**
  2658. * # getName(func)
  2659. *
  2660. * Gets the name of a function, in a cross-browser way.
  2661. *
  2662. * @param {Function} a function (usually a constructor)
  2663. */
  2664. module.exports = function (func) {
  2665. if (func.name) return func.name;
  2666. var match = /^\s?function ([^(]*)\(/.exec(func);
  2667. return match && match[1] ? match[1] : "";
  2668. };
  2669. }); // module: chai/utils/getName.js
  2670. require.register("chai/utils/getPathValue.js", function(module, exports, require){
  2671. /*!
  2672. * Chai - getPathValue utility
  2673. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  2674. * @see https://github.com/logicalparadox/filtr
  2675. * MIT Licensed
  2676. */
  2677. /**
  2678. * ### .getPathValue(path, object)
  2679. *
  2680. * This allows the retrieval of values in an
  2681. * object given a string path.
  2682. *
  2683. * var obj = {
  2684. * prop1: {
  2685. * arr: ['a', 'b', 'c']
  2686. * , str: 'Hello'
  2687. * }
  2688. * , prop2: {
  2689. * arr: [ { nested: 'Universe' } ]
  2690. * , str: 'Hello again!'
  2691. * }
  2692. * }
  2693. *
  2694. * The following would be the results.
  2695. *
  2696. * getPathValue('prop1.str', obj); // Hello
  2697. * getPathValue('prop1.att[2]', obj); // b
  2698. * getPathValue('prop2.arr[0].nested', obj); // Universe
  2699. *
  2700. * @param {String} path
  2701. * @param {Object} object
  2702. * @returns {Object} value or `undefined`
  2703. * @name getPathValue
  2704. * @api public
  2705. */
  2706. var getPathValue = module.exports = function (path, obj) {
  2707. var parsed = parsePath(path);
  2708. return _getPathValue(parsed, obj);
  2709. };
  2710. /*!
  2711. * ## parsePath(path)
  2712. *
  2713. * Helper function used to parse string object
  2714. * paths. Use in conjunction with `_getPathValue`.
  2715. *
  2716. * var parsed = parsePath('myobject.property.subprop');
  2717. *
  2718. * ### Paths:
  2719. *
  2720. * * Can be as near infinitely deep and nested
  2721. * * Arrays are also valid using the formal `myobject.document[3].property`.
  2722. *
  2723. * @param {String} path
  2724. * @returns {Object} parsed
  2725. * @api private
  2726. */
  2727. function parsePath (path) {
  2728. var str = path.replace(/\[/g, '.[')
  2729. , parts = str.match(/(\\\.|[^.]+?)+/g);
  2730. return parts.map(function (value) {
  2731. var re = /\[(\d+)\]$/
  2732. , mArr = re.exec(value)
  2733. if (mArr) return { i: parseFloat(mArr[1]) };
  2734. else return { p: value };
  2735. });
  2736. };
  2737. /*!
  2738. * ## _getPathValue(parsed, obj)
  2739. *
  2740. * Helper companion function for `.parsePath` that returns
  2741. * the value located at the parsed address.
  2742. *
  2743. * var value = getPathValue(parsed, obj);
  2744. *
  2745. * @param {Object} parsed definition from `parsePath`.
  2746. * @param {Object} object to search against
  2747. * @returns {Object|Undefined} value
  2748. * @api private
  2749. */
  2750. function _getPathValue (parsed, obj) {
  2751. var tmp = obj
  2752. , res;
  2753. for (var i = 0, l = parsed.length; i < l; i++) {
  2754. var part = parsed[i];
  2755. if (tmp) {
  2756. if ('undefined' !== typeof part.p)
  2757. tmp = tmp[part.p];
  2758. else if ('undefined' !== typeof part.i)
  2759. tmp = tmp[part.i];
  2760. if (i == (l - 1)) res = tmp;
  2761. } else {
  2762. res = undefined;
  2763. }
  2764. }
  2765. return res;
  2766. };
  2767. }); // module: chai/utils/getPathValue.js
  2768. require.register("chai/utils/index.js", function(module, exports, require){
  2769. /*!
  2770. * chai
  2771. * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
  2772. * MIT Licensed
  2773. */
  2774. /*!
  2775. * Main exports
  2776. */
  2777. var exports = module.exports = {};
  2778. /*!
  2779. * test utility
  2780. */
  2781. exports.test = require('./test');
  2782. /*!
  2783. * message utility
  2784. */
  2785. exports.getMessage = require('./getMessage');
  2786. /*!
  2787. * actual utility
  2788. */
  2789. exports.getActual = require('./getActual');
  2790. /*!
  2791. * Inspect util
  2792. */
  2793. exports.inspect = require('./inspect');
  2794. /*!
  2795. * Object Display util
  2796. */
  2797. exports.objDisplay = require('./objDisplay');
  2798. /*!
  2799. * Flag utility
  2800. */
  2801. exports.flag = require('./flag');
  2802. /*!
  2803. * Flag transferring utility
  2804. */
  2805. exports.transferFlags = require('./transferFlags');
  2806. /*!
  2807. * Deep equal utility
  2808. */
  2809. exports.eql = require('./eql');
  2810. /*!
  2811. * Deep path value
  2812. */
  2813. exports.getPathValue = require('./getPathValue');
  2814. /*!
  2815. * Function name
  2816. */
  2817. exports.getName = require('./getName');
  2818. /*!
  2819. * add Property
  2820. */
  2821. exports.addProperty = require('./addProperty');
  2822. /*!
  2823. * add Method
  2824. */
  2825. exports.addMethod = require('./addMethod');
  2826. /*!
  2827. * overwrite Property
  2828. */
  2829. exports.overwriteProperty = require('./overwriteProperty');
  2830. /*!
  2831. * overwrite Method
  2832. */
  2833. exports.overwriteMethod = require('./overwriteMethod');
  2834. /*!
  2835. * Add a chainable method
  2836. */
  2837. exports.addChainableMethod = require('./addChainableMethod');
  2838. }); // module: chai/utils/index.js
  2839. require.register("chai/utils/inspect.js", function(module, exports, require){
  2840. // This is (almost) directly from Node.js utils
  2841. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
  2842. var getName = require('./getName');
  2843. module.exports = inspect;
  2844. /**
  2845. * Echos the value of a value. Trys to print the value out
  2846. * in the best way possible given the different types.
  2847. *
  2848. * @param {Object} obj The object to print out.
  2849. * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
  2850. * properties of objects.
  2851. * @param {Number} depth Depth in which to descend in object. Default is 2.
  2852. * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
  2853. * output. Default is false (no coloring).
  2854. */
  2855. function inspect(obj, showHidden, depth, colors) {
  2856. var ctx = {
  2857. showHidden: showHidden,
  2858. seen: [],
  2859. stylize: function (str) { return str; }
  2860. };
  2861. return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
  2862. }
  2863. // https://gist.github.com/1044128/
  2864. var getOuterHTML = function(element) {
  2865. if ('outerHTML' in element) return element.outerHTML;
  2866. var ns = "http://www.w3.org/1999/xhtml";
  2867. var container = document.createElementNS(ns, '_');
  2868. var elemProto = (window.HTMLElement || window.Element).prototype;
  2869. var xmlSerializer = new XMLSerializer();
  2870. var html;
  2871. if (document.xmlVersion) {
  2872. return xmlSerializer.serializeToString(element);
  2873. } else {
  2874. container.appendChild(element.cloneNode(false));
  2875. html = container.innerHTML.replace('><', '>' + element.innerHTML + '<');
  2876. container.innerHTML = '';
  2877. return html;
  2878. }
  2879. };
  2880. // Returns true if object is a DOM element.
  2881. var isDOMElement = function (object) {
  2882. if (typeof HTMLElement === 'object') {
  2883. return object instanceof HTMLElement;
  2884. } else {
  2885. return object &&
  2886. typeof object === 'object' &&
  2887. object.nodeType === 1 &&
  2888. typeof object.nodeName === 'string';
  2889. }
  2890. };
  2891. function formatValue(ctx, value, recurseTimes) {
  2892. // Provide a hook for user-specified inspect functions.
  2893. // Check that value is an object with an inspect function on it
  2894. if (value && typeof value.inspect === 'function' &&
  2895. // Filter out the util module, it's inspect function is special
  2896. value.inspect !== exports.inspect &&
  2897. // Also filter out any prototype objects using the circular check.
  2898. !(value.constructor && value.constructor.prototype === value)) {
  2899. return value.inspect(recurseTimes);
  2900. }
  2901. // Primitive types cannot have properties
  2902. var primitive = formatPrimitive(ctx, value);
  2903. if (primitive) {
  2904. return primitive;
  2905. }
  2906. // If it's DOM elem, get outer HTML.
  2907. if (isDOMElement(value)) {
  2908. return getOuterHTML(value);
  2909. }
  2910. // Look up the keys of the object.
  2911. var visibleKeys = Object.keys(value);
  2912. var keys = ctx.showHidden ? Object.getOwnPropertyNames(value) : visibleKeys;
  2913. // Some type of object without properties can be shortcutted.
  2914. // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
  2915. // a `stack` plus `description` property; ignore those for consistency.
  2916. if (keys.length === 0 || (isError(value) && (
  2917. (keys.length === 1 && keys[0] === 'stack') ||
  2918. (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
  2919. ))) {
  2920. if (typeof value === 'function') {
  2921. var name = getName(value);
  2922. var nameSuffix = name ? ': ' + name : '';
  2923. return ctx.stylize('[Function' + nameSuffix + ']', 'special');
  2924. }
  2925. if (isRegExp(value)) {
  2926. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  2927. }
  2928. if (isDate(value)) {
  2929. return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
  2930. }
  2931. if (isError(value)) {
  2932. return formatError(value);
  2933. }
  2934. }
  2935. var base = '', array = false, braces = ['{', '}'];
  2936. // Make Array say that they are Array
  2937. if (isArray(value)) {
  2938. array = true;
  2939. braces = ['[', ']'];
  2940. }
  2941. // Make functions say that they are functions
  2942. if (typeof value === 'function') {
  2943. var name = getName(value);
  2944. var nameSuffix = name ? ': ' + name : '';
  2945. base = ' [Function' + nameSuffix + ']';
  2946. }
  2947. // Make RegExps say that they are RegExps
  2948. if (isRegExp(value)) {
  2949. base = ' ' + RegExp.prototype.toString.call(value);
  2950. }
  2951. // Make dates with properties first say the date
  2952. if (isDate(value)) {
  2953. base = ' ' + Date.prototype.toUTCString.call(value);
  2954. }
  2955. // Make error with message first say the error
  2956. if (isError(value)) {
  2957. return formatError(value);
  2958. }
  2959. if (keys.length === 0 && (!array || value.length == 0)) {
  2960. return braces[0] + base + braces[1];
  2961. }
  2962. if (recurseTimes < 0) {
  2963. if (isRegExp(value)) {
  2964. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  2965. } else {
  2966. return ctx.stylize('[Object]', 'special');
  2967. }
  2968. }
  2969. ctx.seen.push(value);
  2970. var output;
  2971. if (array) {
  2972. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  2973. } else {
  2974. output = keys.map(function(key) {
  2975. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  2976. });
  2977. }
  2978. ctx.seen.pop();
  2979. return reduceToSingleString(output, base, braces);
  2980. }
  2981. function formatPrimitive(ctx, value) {
  2982. switch (typeof value) {
  2983. case 'undefined':
  2984. return ctx.stylize('undefined', 'undefined');
  2985. case 'string':
  2986. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  2987. .replace(/'/g, "\\'")
  2988. .replace(/\\"/g, '"') + '\'';
  2989. return ctx.stylize(simple, 'string');
  2990. case 'number':
  2991. return ctx.stylize('' + value, 'number');
  2992. case 'boolean':
  2993. return ctx.stylize('' + value, 'boolean');
  2994. }
  2995. // For some reason typeof null is "object", so special case here.
  2996. if (value === null) {
  2997. return ctx.stylize('null', 'null');
  2998. }
  2999. }
  3000. function formatError(value) {
  3001. return '[' + Error.prototype.toString.call(value) + ']';
  3002. }
  3003. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  3004. var output = [];
  3005. for (var i = 0, l = value.length; i < l; ++i) {
  3006. if (Object.prototype.hasOwnProperty.call(value, String(i))) {
  3007. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  3008. String(i), true));
  3009. } else {
  3010. output.push('');
  3011. }
  3012. }
  3013. keys.forEach(function(key) {
  3014. if (!key.match(/^\d+$/)) {
  3015. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  3016. key, true));
  3017. }
  3018. });
  3019. return output;
  3020. }
  3021. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  3022. var name, str;
  3023. if (value.__lookupGetter__) {
  3024. if (value.__lookupGetter__(key)) {
  3025. if (value.__lookupSetter__(key)) {
  3026. str = ctx.stylize('[Getter/Setter]', 'special');
  3027. } else {
  3028. str = ctx.stylize('[Getter]', 'special');
  3029. }
  3030. } else {
  3031. if (value.__lookupSetter__(key)) {
  3032. str = ctx.stylize('[Setter]', 'special');
  3033. }
  3034. }
  3035. }
  3036. if (visibleKeys.indexOf(key) < 0) {
  3037. name = '[' + key + ']';
  3038. }
  3039. if (!str) {
  3040. if (ctx.seen.indexOf(value[key]) < 0) {
  3041. if (recurseTimes === null) {
  3042. str = formatValue(ctx, value[key], null);
  3043. } else {
  3044. str = formatValue(ctx, value[key], recurseTimes - 1);
  3045. }
  3046. if (str.indexOf('\n') > -1) {
  3047. if (array) {
  3048. str = str.split('\n').map(function(line) {
  3049. return ' ' + line;
  3050. }).join('\n').substr(2);
  3051. } else {
  3052. str = '\n' + str.split('\n').map(function(line) {
  3053. return ' ' + line;
  3054. }).join('\n');
  3055. }
  3056. }
  3057. } else {
  3058. str = ctx.stylize('[Circular]', 'special');
  3059. }
  3060. }
  3061. if (typeof name === 'undefined') {
  3062. if (array && key.match(/^\d+$/)) {
  3063. return str;
  3064. }
  3065. name = JSON.stringify('' + key);
  3066. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  3067. name = name.substr(1, name.length - 2);
  3068. name = ctx.stylize(name, 'name');
  3069. } else {
  3070. name = name.replace(/'/g, "\\'")
  3071. .replace(/\\"/g, '"')
  3072. .replace(/(^"|"$)/g, "'");
  3073. name = ctx.stylize(name, 'string');
  3074. }
  3075. }
  3076. return name + ': ' + str;
  3077. }
  3078. function reduceToSingleString(output, base, braces) {
  3079. var numLinesEst = 0;
  3080. var length = output.reduce(function(prev, cur) {
  3081. numLinesEst++;
  3082. if (cur.indexOf('\n') >= 0) numLinesEst++;
  3083. return prev + cur.length + 1;
  3084. }, 0);
  3085. if (length > 60) {
  3086. return braces[0] +
  3087. (base === '' ? '' : base + '\n ') +
  3088. ' ' +
  3089. output.join(',\n ') +
  3090. ' ' +
  3091. braces[1];
  3092. }
  3093. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  3094. }
  3095. function isArray(ar) {
  3096. return Array.isArray(ar) ||
  3097. (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  3098. }
  3099. function isRegExp(re) {
  3100. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  3101. }
  3102. function isDate(d) {
  3103. return typeof d === 'object' && objectToString(d) === '[object Date]';
  3104. }
  3105. function isError(e) {
  3106. return typeof e === 'object' && objectToString(e) === '[object Error]';
  3107. }
  3108. function objectToString(o) {
  3109. return Object.prototype.toString.call(o);
  3110. }
  3111. }); // module: chai/utils/inspect.js
  3112. require.register("chai/utils/objDisplay.js", function(module, exports, require){
  3113. /*!
  3114. * Chai - flag utility
  3115. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  3116. * MIT Licensed
  3117. */
  3118. /*!
  3119. * Module dependancies
  3120. */
  3121. var inspect = require('./inspect');
  3122. /**
  3123. * ### .objDisplay (object)
  3124. *
  3125. * Determines if an object or an array matches
  3126. * criteria to be inspected in-line for error
  3127. * messages or should be truncated.
  3128. *
  3129. * @param {Mixed} javascript object to inspect
  3130. * @name objDisplay
  3131. * @api public
  3132. */
  3133. module.exports = function (obj) {
  3134. var str = inspect(obj)
  3135. , type = Object.prototype.toString.call(obj);
  3136. if (str.length >= 40) {
  3137. if (type === '[object Array]') {
  3138. return '[ Array(' + obj.length + ') ]';
  3139. } else if (type === '[object Object]') {
  3140. var keys = Object.keys(obj)
  3141. , kstr = keys.length > 2
  3142. ? keys.splice(0, 2).join(', ') + ', ...'
  3143. : keys.join(', ');
  3144. return '{ Object (' + kstr + ') }';
  3145. } else {
  3146. return str;
  3147. }
  3148. } else {
  3149. return str;
  3150. }
  3151. };
  3152. }); // module: chai/utils/objDisplay.js
  3153. require.register("chai/utils/overwriteMethod.js", function(module, exports, require){
  3154. /*!
  3155. * Chai - overwriteMethod utility
  3156. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  3157. * MIT Licensed
  3158. */
  3159. /**
  3160. * ### overwriteMethod (ctx, name, fn)
  3161. *
  3162. * Overwites an already existing method and provides
  3163. * access to previous function. Must return function
  3164. * to be used for name.
  3165. *
  3166. * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
  3167. * return function (str) {
  3168. * var obj = utils.flag(this, 'object');
  3169. * if (obj instanceof Foo) {
  3170. * new chai.Assertion(obj.value).to.equal(str);
  3171. * } else {
  3172. * _super.apply(this, arguments);
  3173. * }
  3174. * }
  3175. * });
  3176. *
  3177. * Can also be accessed directly from `chai.Assertion`.
  3178. *
  3179. * chai.Assertion.overwriteMethod('foo', fn);
  3180. *
  3181. * Then can be used as any other assertion.
  3182. *
  3183. * expect(myFoo).to.equal('bar');
  3184. *
  3185. * @param {Object} ctx object whose method is to be overwritten
  3186. * @param {String} name of method to overwrite
  3187. * @param {Function} method function that returns a function to be used for name
  3188. * @name overwriteMethod
  3189. * @api public
  3190. */
  3191. module.exports = function (ctx, name, method) {
  3192. var _method = ctx[name]
  3193. , _super = function () { return this; };
  3194. if (_method && 'function' === typeof _method)
  3195. _super = _method;
  3196. ctx[name] = function () {
  3197. var result = method(_super).apply(this, arguments);
  3198. return result === undefined ? this : result;
  3199. }
  3200. };
  3201. }); // module: chai/utils/overwriteMethod.js
  3202. require.register("chai/utils/overwriteProperty.js", function(module, exports, require){
  3203. /*!
  3204. * Chai - overwriteProperty utility
  3205. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  3206. * MIT Licensed
  3207. */
  3208. /**
  3209. * ### overwriteProperty (ctx, name, fn)
  3210. *
  3211. * Overwites an already existing property getter and provides
  3212. * access to previous value. Must return function to use as getter.
  3213. *
  3214. * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
  3215. * return function () {
  3216. * var obj = utils.flag(this, 'object');
  3217. * if (obj instanceof Foo) {
  3218. * new chai.Assertion(obj.name).to.equal('bar');
  3219. * } else {
  3220. * _super.call(this);
  3221. * }
  3222. * }
  3223. * });
  3224. *
  3225. *
  3226. * Can also be accessed directly from `chai.Assertion`.
  3227. *
  3228. * chai.Assertion.overwriteProperty('foo', fn);
  3229. *
  3230. * Then can be used as any other assertion.
  3231. *
  3232. * expect(myFoo).to.be.ok;
  3233. *
  3234. * @param {Object} ctx object whose property is to be overwritten
  3235. * @param {String} name of property to overwrite
  3236. * @param {Function} getter function that returns a getter function to be used for name
  3237. * @name overwriteProperty
  3238. * @api public
  3239. */
  3240. module.exports = function (ctx, name, getter) {
  3241. var _get = Object.getOwnPropertyDescriptor(ctx, name)
  3242. , _super = function () {};
  3243. if (_get && 'function' === typeof _get.get)
  3244. _super = _get.get
  3245. Object.defineProperty(ctx, name,
  3246. { get: function () {
  3247. var result = getter(_super).call(this);
  3248. return result === undefined ? this : result;
  3249. }
  3250. , configurable: true
  3251. });
  3252. };
  3253. }); // module: chai/utils/overwriteProperty.js
  3254. require.register("chai/utils/test.js", function(module, exports, require){
  3255. /*!
  3256. * Chai - test utility
  3257. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  3258. * MIT Licensed
  3259. */
  3260. /*!
  3261. * Module dependancies
  3262. */
  3263. var flag = require('./flag');
  3264. /**
  3265. * # test(object, expression)
  3266. *
  3267. * Test and object for expression.
  3268. *
  3269. * @param {Object} object (constructed Assertion)
  3270. * @param {Arguments} chai.Assertion.prototype.assert arguments
  3271. */
  3272. module.exports = function (obj, args) {
  3273. var negate = flag(obj, 'negate')
  3274. , expr = args[0];
  3275. return negate ? !expr : expr;
  3276. };
  3277. }); // module: chai/utils/test.js
  3278. require.register("chai/utils/transferFlags.js", function(module, exports, require){
  3279. /*!
  3280. * Chai - transferFlags utility
  3281. * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
  3282. * MIT Licensed
  3283. */
  3284. /**
  3285. * ### transferFlags(assertion, object, includeAll = true)
  3286. *
  3287. * Transfer all the flags for `assertion` to `object`. If
  3288. * `includeAll` is set to `false`, then the base Chai
  3289. * assertion flags (namely `object`, `ssfi`, and `message`)
  3290. * will not be transferred.
  3291. *
  3292. *
  3293. * var newAssertion = new Assertion();
  3294. * utils.transferFlags(assertion, newAssertion);
  3295. *
  3296. * var anotherAsseriton = new Assertion(myObj);
  3297. * utils.transferFlags(assertion, anotherAssertion, false);
  3298. *
  3299. * @param {Assertion} assertion the assertion to transfer the flags from
  3300. * @param {Object} object the object to transfer the flags too; usually a new assertion
  3301. * @param {Boolean} includeAll
  3302. * @name getAllFlags
  3303. * @api private
  3304. */
  3305. module.exports = function (assertion, object, includeAll) {
  3306. var flags = assertion.__flags || (assertion.__flags = Object.create(null));
  3307. if (!object.__flags) {
  3308. object.__flags = Object.create(null);
  3309. }
  3310. includeAll = arguments.length === 3 ? includeAll : true;
  3311. for (var flag in flags) {
  3312. if (includeAll ||
  3313. (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
  3314. object.__flags[flag] = flags[flag];
  3315. }
  3316. }
  3317. };
  3318. }); // module: chai/utils/transferFlags.js
  3319. require.alias("./chai.js", "chai");
  3320. return require('chai');
  3321. });