chai.js 341 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.chai = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  2. module.exports = require('./lib/chai');
  3. },{"./lib/chai":2}],2:[function(require,module,exports){
  4. /*!
  5. * chai
  6. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  7. * MIT Licensed
  8. */
  9. var used = [];
  10. /*!
  11. * Chai version
  12. */
  13. exports.version = '4.3.3';
  14. /*!
  15. * Assertion Error
  16. */
  17. exports.AssertionError = require('assertion-error');
  18. /*!
  19. * Utils for plugins (not exported)
  20. */
  21. var util = require('./chai/utils');
  22. /**
  23. * # .use(function)
  24. *
  25. * Provides a way to extend the internals of Chai.
  26. *
  27. * @param {Function}
  28. * @returns {this} for chaining
  29. * @api public
  30. */
  31. exports.use = function (fn) {
  32. if (!~used.indexOf(fn)) {
  33. fn(exports, util);
  34. used.push(fn);
  35. }
  36. return exports;
  37. };
  38. /*!
  39. * Utility Functions
  40. */
  41. exports.util = util;
  42. /*!
  43. * Configuration
  44. */
  45. var config = require('./chai/config');
  46. exports.config = config;
  47. /*!
  48. * Primary `Assertion` prototype
  49. */
  50. var assertion = require('./chai/assertion');
  51. exports.use(assertion);
  52. /*!
  53. * Core Assertions
  54. */
  55. var core = require('./chai/core/assertions');
  56. exports.use(core);
  57. /*!
  58. * Expect interface
  59. */
  60. var expect = require('./chai/interface/expect');
  61. exports.use(expect);
  62. /*!
  63. * Should interface
  64. */
  65. var should = require('./chai/interface/should');
  66. exports.use(should);
  67. /*!
  68. * Assert interface
  69. */
  70. var assert = require('./chai/interface/assert');
  71. exports.use(assert);
  72. },{"./chai/assertion":3,"./chai/config":4,"./chai/core/assertions":5,"./chai/interface/assert":6,"./chai/interface/expect":7,"./chai/interface/should":8,"./chai/utils":23,"assertion-error":34}],3:[function(require,module,exports){
  73. /*!
  74. * chai
  75. * http://chaijs.com
  76. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  77. * MIT Licensed
  78. */
  79. var config = require('./config');
  80. module.exports = function (_chai, util) {
  81. /*!
  82. * Module dependencies.
  83. */
  84. var AssertionError = _chai.AssertionError
  85. , flag = util.flag;
  86. /*!
  87. * Module export.
  88. */
  89. _chai.Assertion = Assertion;
  90. /*!
  91. * Assertion Constructor
  92. *
  93. * Creates object for chaining.
  94. *
  95. * `Assertion` objects contain metadata in the form of flags. Three flags can
  96. * be assigned during instantiation by passing arguments to this constructor:
  97. *
  98. * - `object`: This flag contains the target of the assertion. For example, in
  99. * the assertion `expect(numKittens).to.equal(7);`, the `object` flag will
  100. * contain `numKittens` so that the `equal` assertion can reference it when
  101. * needed.
  102. *
  103. * - `message`: This flag contains an optional custom error message to be
  104. * prepended to the error message that's generated by the assertion when it
  105. * fails.
  106. *
  107. * - `ssfi`: This flag stands for "start stack function indicator". It
  108. * contains a function reference that serves as the starting point for
  109. * removing frames from the stack trace of the error that's created by the
  110. * assertion when it fails. The goal is to provide a cleaner stack trace to
  111. * end users by removing Chai's internal functions. Note that it only works
  112. * in environments that support `Error.captureStackTrace`, and only when
  113. * `Chai.config.includeStack` hasn't been set to `false`.
  114. *
  115. * - `lockSsfi`: This flag controls whether or not the given `ssfi` flag
  116. * should retain its current value, even as assertions are chained off of
  117. * this object. This is usually set to `true` when creating a new assertion
  118. * from within another assertion. It's also temporarily set to `true` before
  119. * an overwritten assertion gets called by the overwriting assertion.
  120. *
  121. * @param {Mixed} obj target of the assertion
  122. * @param {String} msg (optional) custom error message
  123. * @param {Function} ssfi (optional) starting point for removing stack frames
  124. * @param {Boolean} lockSsfi (optional) whether or not the ssfi flag is locked
  125. * @api private
  126. */
  127. function Assertion (obj, msg, ssfi, lockSsfi) {
  128. flag(this, 'ssfi', ssfi || Assertion);
  129. flag(this, 'lockSsfi', lockSsfi);
  130. flag(this, 'object', obj);
  131. flag(this, 'message', msg);
  132. return util.proxify(this);
  133. }
  134. Object.defineProperty(Assertion, 'includeStack', {
  135. get: function() {
  136. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  137. return config.includeStack;
  138. },
  139. set: function(value) {
  140. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  141. config.includeStack = value;
  142. }
  143. });
  144. Object.defineProperty(Assertion, 'showDiff', {
  145. get: function() {
  146. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  147. return config.showDiff;
  148. },
  149. set: function(value) {
  150. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  151. config.showDiff = value;
  152. }
  153. });
  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. Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
  170. util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
  171. };
  172. /**
  173. * ### .assert(expression, message, negateMessage, expected, actual, showDiff)
  174. *
  175. * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
  176. *
  177. * @name assert
  178. * @param {Philosophical} expression to be tested
  179. * @param {String|Function} message or function that returns message to display if expression fails
  180. * @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
  181. * @param {Mixed} expected value (remember to check for negation)
  182. * @param {Mixed} actual (optional) will default to `this.obj`
  183. * @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
  184. * @api private
  185. */
  186. Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
  187. var ok = util.test(this, arguments);
  188. if (false !== showDiff) showDiff = true;
  189. if (undefined === expected && undefined === _actual) showDiff = false;
  190. if (true !== config.showDiff) showDiff = false;
  191. if (!ok) {
  192. msg = util.getMessage(this, arguments);
  193. var actual = util.getActual(this, arguments);
  194. var assertionErrorObjectProperties = {
  195. actual: actual
  196. , expected: expected
  197. , showDiff: showDiff
  198. };
  199. var operator = util.getOperator(this, arguments);
  200. if (operator) {
  201. assertionErrorObjectProperties.operator = operator;
  202. }
  203. throw new AssertionError(
  204. msg,
  205. assertionErrorObjectProperties,
  206. (config.includeStack) ? this.assert : flag(this, 'ssfi'));
  207. }
  208. };
  209. /*!
  210. * ### ._obj
  211. *
  212. * Quick reference to stored `actual` value for plugin developers.
  213. *
  214. * @api private
  215. */
  216. Object.defineProperty(Assertion.prototype, '_obj',
  217. { get: function () {
  218. return flag(this, 'object');
  219. }
  220. , set: function (val) {
  221. flag(this, 'object', val);
  222. }
  223. });
  224. };
  225. },{"./config":4}],4:[function(require,module,exports){
  226. module.exports = {
  227. /**
  228. * ### config.includeStack
  229. *
  230. * User configurable property, influences whether stack trace
  231. * is included in Assertion error message. Default of false
  232. * suppresses stack trace in the error message.
  233. *
  234. * chai.config.includeStack = true; // enable stack on error
  235. *
  236. * @param {Boolean}
  237. * @api public
  238. */
  239. includeStack: false,
  240. /**
  241. * ### config.showDiff
  242. *
  243. * User configurable property, influences whether or not
  244. * the `showDiff` flag should be included in the thrown
  245. * AssertionErrors. `false` will always be `false`; `true`
  246. * will be true when the assertion has requested a diff
  247. * be shown.
  248. *
  249. * @param {Boolean}
  250. * @api public
  251. */
  252. showDiff: true,
  253. /**
  254. * ### config.truncateThreshold
  255. *
  256. * User configurable property, sets length threshold for actual and
  257. * expected values in assertion errors. If this threshold is exceeded, for
  258. * example for large data structures, the value is replaced with something
  259. * like `[ Array(3) ]` or `{ Object (prop1, prop2) }`.
  260. *
  261. * Set it to zero if you want to disable truncating altogether.
  262. *
  263. * This is especially userful when doing assertions on arrays: having this
  264. * set to a reasonable large value makes the failure messages readily
  265. * inspectable.
  266. *
  267. * chai.config.truncateThreshold = 0; // disable truncating
  268. *
  269. * @param {Number}
  270. * @api public
  271. */
  272. truncateThreshold: 40,
  273. /**
  274. * ### config.useProxy
  275. *
  276. * User configurable property, defines if chai will use a Proxy to throw
  277. * an error when a non-existent property is read, which protects users
  278. * from typos when using property-based assertions.
  279. *
  280. * Set it to false if you want to disable this feature.
  281. *
  282. * chai.config.useProxy = false; // disable use of Proxy
  283. *
  284. * This feature is automatically disabled regardless of this config value
  285. * in environments that don't support proxies.
  286. *
  287. * @param {Boolean}
  288. * @api public
  289. */
  290. useProxy: true,
  291. /**
  292. * ### config.proxyExcludedKeys
  293. *
  294. * User configurable property, defines which properties should be ignored
  295. * instead of throwing an error if they do not exist on the assertion.
  296. * This is only applied if the environment Chai is running in supports proxies and
  297. * if the `useProxy` configuration setting is enabled.
  298. * By default, `then` and `inspect` will not throw an error if they do not exist on the
  299. * assertion object because the `.inspect` property is read by `util.inspect` (for example, when
  300. * using `console.log` on the assertion object) and `.then` is necessary for promise type-checking.
  301. *
  302. * // By default these keys will not throw an error if they do not exist on the assertion object
  303. * chai.config.proxyExcludedKeys = ['then', 'inspect'];
  304. *
  305. * @param {Array}
  306. * @api public
  307. */
  308. proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON']
  309. };
  310. },{}],5:[function(require,module,exports){
  311. /*!
  312. * chai
  313. * http://chaijs.com
  314. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  315. * MIT Licensed
  316. */
  317. module.exports = function (chai, _) {
  318. var Assertion = chai.Assertion
  319. , AssertionError = chai.AssertionError
  320. , flag = _.flag;
  321. /**
  322. * ### Language Chains
  323. *
  324. * The following are provided as chainable getters to improve the readability
  325. * of your assertions.
  326. *
  327. * **Chains**
  328. *
  329. * - to
  330. * - be
  331. * - been
  332. * - is
  333. * - that
  334. * - which
  335. * - and
  336. * - has
  337. * - have
  338. * - with
  339. * - at
  340. * - of
  341. * - same
  342. * - but
  343. * - does
  344. * - still
  345. * - also
  346. *
  347. * @name language chains
  348. * @namespace BDD
  349. * @api public
  350. */
  351. [ 'to', 'be', 'been', 'is'
  352. , 'and', 'has', 'have', 'with'
  353. , 'that', 'which', 'at', 'of'
  354. , 'same', 'but', 'does', 'still', "also" ].forEach(function (chain) {
  355. Assertion.addProperty(chain);
  356. });
  357. /**
  358. * ### .not
  359. *
  360. * Negates all assertions that follow in the chain.
  361. *
  362. * expect(function () {}).to.not.throw();
  363. * expect({a: 1}).to.not.have.property('b');
  364. * expect([1, 2]).to.be.an('array').that.does.not.include(3);
  365. *
  366. * Just because you can negate any assertion with `.not` doesn't mean you
  367. * should. With great power comes great responsibility. It's often best to
  368. * assert that the one expected output was produced, rather than asserting
  369. * that one of countless unexpected outputs wasn't produced. See individual
  370. * assertions for specific guidance.
  371. *
  372. * expect(2).to.equal(2); // Recommended
  373. * expect(2).to.not.equal(1); // Not recommended
  374. *
  375. * @name not
  376. * @namespace BDD
  377. * @api public
  378. */
  379. Assertion.addProperty('not', function () {
  380. flag(this, 'negate', true);
  381. });
  382. /**
  383. * ### .deep
  384. *
  385. * Causes all `.equal`, `.include`, `.members`, `.keys`, and `.property`
  386. * assertions that follow in the chain to use deep equality instead of strict
  387. * (`===`) equality. See the `deep-eql` project page for info on the deep
  388. * equality algorithm: https://github.com/chaijs/deep-eql.
  389. *
  390. * // Target object deeply (but not strictly) equals `{a: 1}`
  391. * expect({a: 1}).to.deep.equal({a: 1});
  392. * expect({a: 1}).to.not.equal({a: 1});
  393. *
  394. * // Target array deeply (but not strictly) includes `{a: 1}`
  395. * expect([{a: 1}]).to.deep.include({a: 1});
  396. * expect([{a: 1}]).to.not.include({a: 1});
  397. *
  398. * // Target object deeply (but not strictly) includes `x: {a: 1}`
  399. * expect({x: {a: 1}}).to.deep.include({x: {a: 1}});
  400. * expect({x: {a: 1}}).to.not.include({x: {a: 1}});
  401. *
  402. * // Target array deeply (but not strictly) has member `{a: 1}`
  403. * expect([{a: 1}]).to.have.deep.members([{a: 1}]);
  404. * expect([{a: 1}]).to.not.have.members([{a: 1}]);
  405. *
  406. * // Target set deeply (but not strictly) has key `{a: 1}`
  407. * expect(new Set([{a: 1}])).to.have.deep.keys([{a: 1}]);
  408. * expect(new Set([{a: 1}])).to.not.have.keys([{a: 1}]);
  409. *
  410. * // Target object deeply (but not strictly) has property `x: {a: 1}`
  411. * expect({x: {a: 1}}).to.have.deep.property('x', {a: 1});
  412. * expect({x: {a: 1}}).to.not.have.property('x', {a: 1});
  413. *
  414. * @name deep
  415. * @namespace BDD
  416. * @api public
  417. */
  418. Assertion.addProperty('deep', function () {
  419. flag(this, 'deep', true);
  420. });
  421. /**
  422. * ### .nested
  423. *
  424. * Enables dot- and bracket-notation in all `.property` and `.include`
  425. * assertions that follow in the chain.
  426. *
  427. * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]');
  428. * expect({a: {b: ['x', 'y']}}).to.nested.include({'a.b[1]': 'y'});
  429. *
  430. * If `.` or `[]` are part of an actual property name, they can be escaped by
  431. * adding two backslashes before them.
  432. *
  433. * expect({'.a': {'[b]': 'x'}}).to.have.nested.property('\\.a.\\[b\\]');
  434. * expect({'.a': {'[b]': 'x'}}).to.nested.include({'\\.a.\\[b\\]': 'x'});
  435. *
  436. * `.nested` cannot be combined with `.own`.
  437. *
  438. * @name nested
  439. * @namespace BDD
  440. * @api public
  441. */
  442. Assertion.addProperty('nested', function () {
  443. flag(this, 'nested', true);
  444. });
  445. /**
  446. * ### .own
  447. *
  448. * Causes all `.property` and `.include` assertions that follow in the chain
  449. * to ignore inherited properties.
  450. *
  451. * Object.prototype.b = 2;
  452. *
  453. * expect({a: 1}).to.have.own.property('a');
  454. * expect({a: 1}).to.have.property('b');
  455. * expect({a: 1}).to.not.have.own.property('b');
  456. *
  457. * expect({a: 1}).to.own.include({a: 1});
  458. * expect({a: 1}).to.include({b: 2}).but.not.own.include({b: 2});
  459. *
  460. * `.own` cannot be combined with `.nested`.
  461. *
  462. * @name own
  463. * @namespace BDD
  464. * @api public
  465. */
  466. Assertion.addProperty('own', function () {
  467. flag(this, 'own', true);
  468. });
  469. /**
  470. * ### .ordered
  471. *
  472. * Causes all `.members` assertions that follow in the chain to require that
  473. * members be in the same order.
  474. *
  475. * expect([1, 2]).to.have.ordered.members([1, 2])
  476. * .but.not.have.ordered.members([2, 1]);
  477. *
  478. * When `.include` and `.ordered` are combined, the ordering begins at the
  479. * start of both arrays.
  480. *
  481. * expect([1, 2, 3]).to.include.ordered.members([1, 2])
  482. * .but.not.include.ordered.members([2, 3]);
  483. *
  484. * @name ordered
  485. * @namespace BDD
  486. * @api public
  487. */
  488. Assertion.addProperty('ordered', function () {
  489. flag(this, 'ordered', true);
  490. });
  491. /**
  492. * ### .any
  493. *
  494. * Causes all `.keys` assertions that follow in the chain to only require that
  495. * the target have at least one of the given keys. This is the opposite of
  496. * `.all`, which requires that the target have all of the given keys.
  497. *
  498. * expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');
  499. *
  500. * See the `.keys` doc for guidance on when to use `.any` or `.all`.
  501. *
  502. * @name any
  503. * @namespace BDD
  504. * @api public
  505. */
  506. Assertion.addProperty('any', function () {
  507. flag(this, 'any', true);
  508. flag(this, 'all', false);
  509. });
  510. /**
  511. * ### .all
  512. *
  513. * Causes all `.keys` assertions that follow in the chain to require that the
  514. * target have all of the given keys. This is the opposite of `.any`, which
  515. * only requires that the target have at least one of the given keys.
  516. *
  517. * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
  518. *
  519. * Note that `.all` is used by default when neither `.all` nor `.any` are
  520. * added earlier in the chain. However, it's often best to add `.all` anyway
  521. * because it improves readability.
  522. *
  523. * See the `.keys` doc for guidance on when to use `.any` or `.all`.
  524. *
  525. * @name all
  526. * @namespace BDD
  527. * @api public
  528. */
  529. Assertion.addProperty('all', function () {
  530. flag(this, 'all', true);
  531. flag(this, 'any', false);
  532. });
  533. /**
  534. * ### .a(type[, msg])
  535. *
  536. * Asserts that the target's type is equal to the given string `type`. Types
  537. * are case insensitive. See the `type-detect` project page for info on the
  538. * type detection algorithm: https://github.com/chaijs/type-detect.
  539. *
  540. * expect('foo').to.be.a('string');
  541. * expect({a: 1}).to.be.an('object');
  542. * expect(null).to.be.a('null');
  543. * expect(undefined).to.be.an('undefined');
  544. * expect(new Error).to.be.an('error');
  545. * expect(Promise.resolve()).to.be.a('promise');
  546. * expect(new Float32Array).to.be.a('float32array');
  547. * expect(Symbol()).to.be.a('symbol');
  548. *
  549. * `.a` supports objects that have a custom type set via `Symbol.toStringTag`.
  550. *
  551. * var myObj = {
  552. * [Symbol.toStringTag]: 'myCustomType'
  553. * };
  554. *
  555. * expect(myObj).to.be.a('myCustomType').but.not.an('object');
  556. *
  557. * It's often best to use `.a` to check a target's type before making more
  558. * assertions on the same target. That way, you avoid unexpected behavior from
  559. * any assertion that does different things based on the target's type.
  560. *
  561. * expect([1, 2, 3]).to.be.an('array').that.includes(2);
  562. * expect([]).to.be.an('array').that.is.empty;
  563. *
  564. * Add `.not` earlier in the chain to negate `.a`. However, it's often best to
  565. * assert that the target is the expected type, rather than asserting that it
  566. * isn't one of many unexpected types.
  567. *
  568. * expect('foo').to.be.a('string'); // Recommended
  569. * expect('foo').to.not.be.an('array'); // Not recommended
  570. *
  571. * `.a` accepts an optional `msg` argument which is a custom error message to
  572. * show when the assertion fails. The message can also be given as the second
  573. * argument to `expect`.
  574. *
  575. * expect(1).to.be.a('string', 'nooo why fail??');
  576. * expect(1, 'nooo why fail??').to.be.a('string');
  577. *
  578. * `.a` can also be used as a language chain to improve the readability of
  579. * your assertions.
  580. *
  581. * expect({b: 2}).to.have.a.property('b');
  582. *
  583. * The alias `.an` can be used interchangeably with `.a`.
  584. *
  585. * @name a
  586. * @alias an
  587. * @param {String} type
  588. * @param {String} msg _optional_
  589. * @namespace BDD
  590. * @api public
  591. */
  592. function an (type, msg) {
  593. if (msg) flag(this, 'message', msg);
  594. type = type.toLowerCase();
  595. var obj = flag(this, 'object')
  596. , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
  597. this.assert(
  598. type === _.type(obj).toLowerCase()
  599. , 'expected #{this} to be ' + article + type
  600. , 'expected #{this} not to be ' + article + type
  601. );
  602. }
  603. Assertion.addChainableMethod('an', an);
  604. Assertion.addChainableMethod('a', an);
  605. /**
  606. * ### .include(val[, msg])
  607. *
  608. * When the target is a string, `.include` asserts that the given string `val`
  609. * is a substring of the target.
  610. *
  611. * expect('foobar').to.include('foo');
  612. *
  613. * When the target is an array, `.include` asserts that the given `val` is a
  614. * member of the target.
  615. *
  616. * expect([1, 2, 3]).to.include(2);
  617. *
  618. * When the target is an object, `.include` asserts that the given object
  619. * `val`'s properties are a subset of the target's properties.
  620. *
  621. * expect({a: 1, b: 2, c: 3}).to.include({a: 1, b: 2});
  622. *
  623. * When the target is a Set or WeakSet, `.include` asserts that the given `val` is a
  624. * member of the target. SameValueZero equality algorithm is used.
  625. *
  626. * expect(new Set([1, 2])).to.include(2);
  627. *
  628. * When the target is a Map, `.include` asserts that the given `val` is one of
  629. * the values of the target. SameValueZero equality algorithm is used.
  630. *
  631. * expect(new Map([['a', 1], ['b', 2]])).to.include(2);
  632. *
  633. * Because `.include` does different things based on the target's type, it's
  634. * important to check the target's type before using `.include`. See the `.a`
  635. * doc for info on testing a target's type.
  636. *
  637. * expect([1, 2, 3]).to.be.an('array').that.includes(2);
  638. *
  639. * By default, strict (`===`) equality is used to compare array members and
  640. * object properties. Add `.deep` earlier in the chain to use deep equality
  641. * instead (WeakSet targets are not supported). See the `deep-eql` project
  642. * page for info on the deep equality algorithm: https://github.com/chaijs/deep-eql.
  643. *
  644. * // Target array deeply (but not strictly) includes `{a: 1}`
  645. * expect([{a: 1}]).to.deep.include({a: 1});
  646. * expect([{a: 1}]).to.not.include({a: 1});
  647. *
  648. * // Target object deeply (but not strictly) includes `x: {a: 1}`
  649. * expect({x: {a: 1}}).to.deep.include({x: {a: 1}});
  650. * expect({x: {a: 1}}).to.not.include({x: {a: 1}});
  651. *
  652. * By default, all of the target's properties are searched when working with
  653. * objects. This includes properties that are inherited and/or non-enumerable.
  654. * Add `.own` earlier in the chain to exclude the target's inherited
  655. * properties from the search.
  656. *
  657. * Object.prototype.b = 2;
  658. *
  659. * expect({a: 1}).to.own.include({a: 1});
  660. * expect({a: 1}).to.include({b: 2}).but.not.own.include({b: 2});
  661. *
  662. * Note that a target object is always only searched for `val`'s own
  663. * enumerable properties.
  664. *
  665. * `.deep` and `.own` can be combined.
  666. *
  667. * expect({a: {b: 2}}).to.deep.own.include({a: {b: 2}});
  668. *
  669. * Add `.nested` earlier in the chain to enable dot- and bracket-notation when
  670. * referencing nested properties.
  671. *
  672. * expect({a: {b: ['x', 'y']}}).to.nested.include({'a.b[1]': 'y'});
  673. *
  674. * If `.` or `[]` are part of an actual property name, they can be escaped by
  675. * adding two backslashes before them.
  676. *
  677. * expect({'.a': {'[b]': 2}}).to.nested.include({'\\.a.\\[b\\]': 2});
  678. *
  679. * `.deep` and `.nested` can be combined.
  680. *
  681. * expect({a: {b: [{c: 3}]}}).to.deep.nested.include({'a.b[0]': {c: 3}});
  682. *
  683. * `.own` and `.nested` cannot be combined.
  684. *
  685. * Add `.not` earlier in the chain to negate `.include`.
  686. *
  687. * expect('foobar').to.not.include('taco');
  688. * expect([1, 2, 3]).to.not.include(4);
  689. *
  690. * However, it's dangerous to negate `.include` when the target is an object.
  691. * The problem is that it creates uncertain expectations by asserting that the
  692. * target object doesn't have all of `val`'s key/value pairs but may or may
  693. * not have some of them. It's often best to identify the exact output that's
  694. * expected, and then write an assertion that only accepts that exact output.
  695. *
  696. * When the target object isn't even expected to have `val`'s keys, it's
  697. * often best to assert exactly that.
  698. *
  699. * expect({c: 3}).to.not.have.any.keys('a', 'b'); // Recommended
  700. * expect({c: 3}).to.not.include({a: 1, b: 2}); // Not recommended
  701. *
  702. * When the target object is expected to have `val`'s keys, it's often best to
  703. * assert that each of the properties has its expected value, rather than
  704. * asserting that each property doesn't have one of many unexpected values.
  705. *
  706. * expect({a: 3, b: 4}).to.include({a: 3, b: 4}); // Recommended
  707. * expect({a: 3, b: 4}).to.not.include({a: 1, b: 2}); // Not recommended
  708. *
  709. * `.include` accepts an optional `msg` argument which is a custom error
  710. * message to show when the assertion fails. The message can also be given as
  711. * the second argument to `expect`.
  712. *
  713. * expect([1, 2, 3]).to.include(4, 'nooo why fail??');
  714. * expect([1, 2, 3], 'nooo why fail??').to.include(4);
  715. *
  716. * `.include` can also be used as a language chain, causing all `.members` and
  717. * `.keys` assertions that follow in the chain to require the target to be a
  718. * superset of the expected set, rather than an identical set. Note that
  719. * `.members` ignores duplicates in the subset when `.include` is added.
  720. *
  721. * // Target object's keys are a superset of ['a', 'b'] but not identical
  722. * expect({a: 1, b: 2, c: 3}).to.include.all.keys('a', 'b');
  723. * expect({a: 1, b: 2, c: 3}).to.not.have.all.keys('a', 'b');
  724. *
  725. * // Target array is a superset of [1, 2] but not identical
  726. * expect([1, 2, 3]).to.include.members([1, 2]);
  727. * expect([1, 2, 3]).to.not.have.members([1, 2]);
  728. *
  729. * // Duplicates in the subset are ignored
  730. * expect([1, 2, 3]).to.include.members([1, 2, 2, 2]);
  731. *
  732. * Note that adding `.any` earlier in the chain causes the `.keys` assertion
  733. * to ignore `.include`.
  734. *
  735. * // Both assertions are identical
  736. * expect({a: 1}).to.include.any.keys('a', 'b');
  737. * expect({a: 1}).to.have.any.keys('a', 'b');
  738. *
  739. * The aliases `.includes`, `.contain`, and `.contains` can be used
  740. * interchangeably with `.include`.
  741. *
  742. * @name include
  743. * @alias contain
  744. * @alias includes
  745. * @alias contains
  746. * @param {Mixed} val
  747. * @param {String} msg _optional_
  748. * @namespace BDD
  749. * @api public
  750. */
  751. function SameValueZero(a, b) {
  752. return (_.isNaN(a) && _.isNaN(b)) || a === b;
  753. }
  754. function includeChainingBehavior () {
  755. flag(this, 'contains', true);
  756. }
  757. function include (val, msg) {
  758. if (msg) flag(this, 'message', msg);
  759. var obj = flag(this, 'object')
  760. , objType = _.type(obj).toLowerCase()
  761. , flagMsg = flag(this, 'message')
  762. , negate = flag(this, 'negate')
  763. , ssfi = flag(this, 'ssfi')
  764. , isDeep = flag(this, 'deep')
  765. , descriptor = isDeep ? 'deep ' : '';
  766. flagMsg = flagMsg ? flagMsg + ': ' : '';
  767. var included = false;
  768. switch (objType) {
  769. case 'string':
  770. included = obj.indexOf(val) !== -1;
  771. break;
  772. case 'weakset':
  773. if (isDeep) {
  774. throw new AssertionError(
  775. flagMsg + 'unable to use .deep.include with WeakSet',
  776. undefined,
  777. ssfi
  778. );
  779. }
  780. included = obj.has(val);
  781. break;
  782. case 'map':
  783. var isEql = isDeep ? _.eql : SameValueZero;
  784. obj.forEach(function (item) {
  785. included = included || isEql(item, val);
  786. });
  787. break;
  788. case 'set':
  789. if (isDeep) {
  790. obj.forEach(function (item) {
  791. included = included || _.eql(item, val);
  792. });
  793. } else {
  794. included = obj.has(val);
  795. }
  796. break;
  797. case 'array':
  798. if (isDeep) {
  799. included = obj.some(function (item) {
  800. return _.eql(item, val);
  801. })
  802. } else {
  803. included = obj.indexOf(val) !== -1;
  804. }
  805. break;
  806. default:
  807. // This block is for asserting a subset of properties in an object.
  808. // `_.expectTypes` isn't used here because `.include` should work with
  809. // objects with a custom `@@toStringTag`.
  810. if (val !== Object(val)) {
  811. throw new AssertionError(
  812. flagMsg + 'the given combination of arguments ('
  813. + objType + ' and '
  814. + _.type(val).toLowerCase() + ')'
  815. + ' is invalid for this assertion. '
  816. + 'You can use an array, a map, an object, a set, a string, '
  817. + 'or a weakset instead of a '
  818. + _.type(val).toLowerCase(),
  819. undefined,
  820. ssfi
  821. );
  822. }
  823. var props = Object.keys(val)
  824. , firstErr = null
  825. , numErrs = 0;
  826. props.forEach(function (prop) {
  827. var propAssertion = new Assertion(obj);
  828. _.transferFlags(this, propAssertion, true);
  829. flag(propAssertion, 'lockSsfi', true);
  830. if (!negate || props.length === 1) {
  831. propAssertion.property(prop, val[prop]);
  832. return;
  833. }
  834. try {
  835. propAssertion.property(prop, val[prop]);
  836. } catch (err) {
  837. if (!_.checkError.compatibleConstructor(err, AssertionError)) {
  838. throw err;
  839. }
  840. if (firstErr === null) firstErr = err;
  841. numErrs++;
  842. }
  843. }, this);
  844. // When validating .not.include with multiple properties, we only want
  845. // to throw an assertion error if all of the properties are included,
  846. // in which case we throw the first property assertion error that we
  847. // encountered.
  848. if (negate && props.length > 1 && numErrs === props.length) {
  849. throw firstErr;
  850. }
  851. return;
  852. }
  853. // Assert inclusion in collection or substring in a string.
  854. this.assert(
  855. included
  856. , 'expected #{this} to ' + descriptor + 'include ' + _.inspect(val)
  857. , 'expected #{this} to not ' + descriptor + 'include ' + _.inspect(val));
  858. }
  859. Assertion.addChainableMethod('include', include, includeChainingBehavior);
  860. Assertion.addChainableMethod('contain', include, includeChainingBehavior);
  861. Assertion.addChainableMethod('contains', include, includeChainingBehavior);
  862. Assertion.addChainableMethod('includes', include, includeChainingBehavior);
  863. /**
  864. * ### .ok
  865. *
  866. * Asserts that the target is a truthy value (considered `true` in boolean context).
  867. * However, it's often best to assert that the target is strictly (`===`) or
  868. * deeply equal to its expected value.
  869. *
  870. * expect(1).to.equal(1); // Recommended
  871. * expect(1).to.be.ok; // Not recommended
  872. *
  873. * expect(true).to.be.true; // Recommended
  874. * expect(true).to.be.ok; // Not recommended
  875. *
  876. * Add `.not` earlier in the chain to negate `.ok`.
  877. *
  878. * expect(0).to.equal(0); // Recommended
  879. * expect(0).to.not.be.ok; // Not recommended
  880. *
  881. * expect(false).to.be.false; // Recommended
  882. * expect(false).to.not.be.ok; // Not recommended
  883. *
  884. * expect(null).to.be.null; // Recommended
  885. * expect(null).to.not.be.ok; // Not recommended
  886. *
  887. * expect(undefined).to.be.undefined; // Recommended
  888. * expect(undefined).to.not.be.ok; // Not recommended
  889. *
  890. * A custom error message can be given as the second argument to `expect`.
  891. *
  892. * expect(false, 'nooo why fail??').to.be.ok;
  893. *
  894. * @name ok
  895. * @namespace BDD
  896. * @api public
  897. */
  898. Assertion.addProperty('ok', function () {
  899. this.assert(
  900. flag(this, 'object')
  901. , 'expected #{this} to be truthy'
  902. , 'expected #{this} to be falsy');
  903. });
  904. /**
  905. * ### .true
  906. *
  907. * Asserts that the target is strictly (`===`) equal to `true`.
  908. *
  909. * expect(true).to.be.true;
  910. *
  911. * Add `.not` earlier in the chain to negate `.true`. However, it's often best
  912. * to assert that the target is equal to its expected value, rather than not
  913. * equal to `true`.
  914. *
  915. * expect(false).to.be.false; // Recommended
  916. * expect(false).to.not.be.true; // Not recommended
  917. *
  918. * expect(1).to.equal(1); // Recommended
  919. * expect(1).to.not.be.true; // Not recommended
  920. *
  921. * A custom error message can be given as the second argument to `expect`.
  922. *
  923. * expect(false, 'nooo why fail??').to.be.true;
  924. *
  925. * @name true
  926. * @namespace BDD
  927. * @api public
  928. */
  929. Assertion.addProperty('true', function () {
  930. this.assert(
  931. true === flag(this, 'object')
  932. , 'expected #{this} to be true'
  933. , 'expected #{this} to be false'
  934. , flag(this, 'negate') ? false : true
  935. );
  936. });
  937. /**
  938. * ### .false
  939. *
  940. * Asserts that the target is strictly (`===`) equal to `false`.
  941. *
  942. * expect(false).to.be.false;
  943. *
  944. * Add `.not` earlier in the chain to negate `.false`. However, it's often
  945. * best to assert that the target is equal to its expected value, rather than
  946. * not equal to `false`.
  947. *
  948. * expect(true).to.be.true; // Recommended
  949. * expect(true).to.not.be.false; // Not recommended
  950. *
  951. * expect(1).to.equal(1); // Recommended
  952. * expect(1).to.not.be.false; // Not recommended
  953. *
  954. * A custom error message can be given as the second argument to `expect`.
  955. *
  956. * expect(true, 'nooo why fail??').to.be.false;
  957. *
  958. * @name false
  959. * @namespace BDD
  960. * @api public
  961. */
  962. Assertion.addProperty('false', function () {
  963. this.assert(
  964. false === flag(this, 'object')
  965. , 'expected #{this} to be false'
  966. , 'expected #{this} to be true'
  967. , flag(this, 'negate') ? true : false
  968. );
  969. });
  970. /**
  971. * ### .null
  972. *
  973. * Asserts that the target is strictly (`===`) equal to `null`.
  974. *
  975. * expect(null).to.be.null;
  976. *
  977. * Add `.not` earlier in the chain to negate `.null`. However, it's often best
  978. * to assert that the target is equal to its expected value, rather than not
  979. * equal to `null`.
  980. *
  981. * expect(1).to.equal(1); // Recommended
  982. * expect(1).to.not.be.null; // Not recommended
  983. *
  984. * A custom error message can be given as the second argument to `expect`.
  985. *
  986. * expect(42, 'nooo why fail??').to.be.null;
  987. *
  988. * @name null
  989. * @namespace BDD
  990. * @api public
  991. */
  992. Assertion.addProperty('null', function () {
  993. this.assert(
  994. null === flag(this, 'object')
  995. , 'expected #{this} to be null'
  996. , 'expected #{this} not to be null'
  997. );
  998. });
  999. /**
  1000. * ### .undefined
  1001. *
  1002. * Asserts that the target is strictly (`===`) equal to `undefined`.
  1003. *
  1004. * expect(undefined).to.be.undefined;
  1005. *
  1006. * Add `.not` earlier in the chain to negate `.undefined`. However, it's often
  1007. * best to assert that the target is equal to its expected value, rather than
  1008. * not equal to `undefined`.
  1009. *
  1010. * expect(1).to.equal(1); // Recommended
  1011. * expect(1).to.not.be.undefined; // Not recommended
  1012. *
  1013. * A custom error message can be given as the second argument to `expect`.
  1014. *
  1015. * expect(42, 'nooo why fail??').to.be.undefined;
  1016. *
  1017. * @name undefined
  1018. * @namespace BDD
  1019. * @api public
  1020. */
  1021. Assertion.addProperty('undefined', function () {
  1022. this.assert(
  1023. undefined === flag(this, 'object')
  1024. , 'expected #{this} to be undefined'
  1025. , 'expected #{this} not to be undefined'
  1026. );
  1027. });
  1028. /**
  1029. * ### .NaN
  1030. *
  1031. * Asserts that the target is exactly `NaN`.
  1032. *
  1033. * expect(NaN).to.be.NaN;
  1034. *
  1035. * Add `.not` earlier in the chain to negate `.NaN`. However, it's often best
  1036. * to assert that the target is equal to its expected value, rather than not
  1037. * equal to `NaN`.
  1038. *
  1039. * expect('foo').to.equal('foo'); // Recommended
  1040. * expect('foo').to.not.be.NaN; // Not recommended
  1041. *
  1042. * A custom error message can be given as the second argument to `expect`.
  1043. *
  1044. * expect(42, 'nooo why fail??').to.be.NaN;
  1045. *
  1046. * @name NaN
  1047. * @namespace BDD
  1048. * @api public
  1049. */
  1050. Assertion.addProperty('NaN', function () {
  1051. this.assert(
  1052. _.isNaN(flag(this, 'object'))
  1053. , 'expected #{this} to be NaN'
  1054. , 'expected #{this} not to be NaN'
  1055. );
  1056. });
  1057. /**
  1058. * ### .exist
  1059. *
  1060. * Asserts that the target is not strictly (`===`) equal to either `null` or
  1061. * `undefined`. However, it's often best to assert that the target is equal to
  1062. * its expected value.
  1063. *
  1064. * expect(1).to.equal(1); // Recommended
  1065. * expect(1).to.exist; // Not recommended
  1066. *
  1067. * expect(0).to.equal(0); // Recommended
  1068. * expect(0).to.exist; // Not recommended
  1069. *
  1070. * Add `.not` earlier in the chain to negate `.exist`.
  1071. *
  1072. * expect(null).to.be.null; // Recommended
  1073. * expect(null).to.not.exist; // Not recommended
  1074. *
  1075. * expect(undefined).to.be.undefined; // Recommended
  1076. * expect(undefined).to.not.exist; // Not recommended
  1077. *
  1078. * A custom error message can be given as the second argument to `expect`.
  1079. *
  1080. * expect(null, 'nooo why fail??').to.exist;
  1081. *
  1082. * The alias `.exists` can be used interchangeably with `.exist`.
  1083. *
  1084. * @name exist
  1085. * @alias exists
  1086. * @namespace BDD
  1087. * @api public
  1088. */
  1089. function assertExist () {
  1090. var val = flag(this, 'object');
  1091. this.assert(
  1092. val !== null && val !== undefined
  1093. , 'expected #{this} to exist'
  1094. , 'expected #{this} to not exist'
  1095. );
  1096. }
  1097. Assertion.addProperty('exist', assertExist);
  1098. Assertion.addProperty('exists', assertExist);
  1099. /**
  1100. * ### .empty
  1101. *
  1102. * When the target is a string or array, `.empty` asserts that the target's
  1103. * `length` property is strictly (`===`) equal to `0`.
  1104. *
  1105. * expect([]).to.be.empty;
  1106. * expect('').to.be.empty;
  1107. *
  1108. * When the target is a map or set, `.empty` asserts that the target's `size`
  1109. * property is strictly equal to `0`.
  1110. *
  1111. * expect(new Set()).to.be.empty;
  1112. * expect(new Map()).to.be.empty;
  1113. *
  1114. * When the target is a non-function object, `.empty` asserts that the target
  1115. * doesn't have any own enumerable properties. Properties with Symbol-based
  1116. * keys are excluded from the count.
  1117. *
  1118. * expect({}).to.be.empty;
  1119. *
  1120. * Because `.empty` does different things based on the target's type, it's
  1121. * important to check the target's type before using `.empty`. See the `.a`
  1122. * doc for info on testing a target's type.
  1123. *
  1124. * expect([]).to.be.an('array').that.is.empty;
  1125. *
  1126. * Add `.not` earlier in the chain to negate `.empty`. However, it's often
  1127. * best to assert that the target contains its expected number of values,
  1128. * rather than asserting that it's not empty.
  1129. *
  1130. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1131. * expect([1, 2, 3]).to.not.be.empty; // Not recommended
  1132. *
  1133. * expect(new Set([1, 2, 3])).to.have.property('size', 3); // Recommended
  1134. * expect(new Set([1, 2, 3])).to.not.be.empty; // Not recommended
  1135. *
  1136. * expect(Object.keys({a: 1})).to.have.lengthOf(1); // Recommended
  1137. * expect({a: 1}).to.not.be.empty; // Not recommended
  1138. *
  1139. * A custom error message can be given as the second argument to `expect`.
  1140. *
  1141. * expect([1, 2, 3], 'nooo why fail??').to.be.empty;
  1142. *
  1143. * @name empty
  1144. * @namespace BDD
  1145. * @api public
  1146. */
  1147. Assertion.addProperty('empty', function () {
  1148. var val = flag(this, 'object')
  1149. , ssfi = flag(this, 'ssfi')
  1150. , flagMsg = flag(this, 'message')
  1151. , itemsCount;
  1152. flagMsg = flagMsg ? flagMsg + ': ' : '';
  1153. switch (_.type(val).toLowerCase()) {
  1154. case 'array':
  1155. case 'string':
  1156. itemsCount = val.length;
  1157. break;
  1158. case 'map':
  1159. case 'set':
  1160. itemsCount = val.size;
  1161. break;
  1162. case 'weakmap':
  1163. case 'weakset':
  1164. throw new AssertionError(
  1165. flagMsg + '.empty was passed a weak collection',
  1166. undefined,
  1167. ssfi
  1168. );
  1169. case 'function':
  1170. var msg = flagMsg + '.empty was passed a function ' + _.getName(val);
  1171. throw new AssertionError(msg.trim(), undefined, ssfi);
  1172. default:
  1173. if (val !== Object(val)) {
  1174. throw new AssertionError(
  1175. flagMsg + '.empty was passed non-string primitive ' + _.inspect(val),
  1176. undefined,
  1177. ssfi
  1178. );
  1179. }
  1180. itemsCount = Object.keys(val).length;
  1181. }
  1182. this.assert(
  1183. 0 === itemsCount
  1184. , 'expected #{this} to be empty'
  1185. , 'expected #{this} not to be empty'
  1186. );
  1187. });
  1188. /**
  1189. * ### .arguments
  1190. *
  1191. * Asserts that the target is an `arguments` object.
  1192. *
  1193. * function test () {
  1194. * expect(arguments).to.be.arguments;
  1195. * }
  1196. *
  1197. * test();
  1198. *
  1199. * Add `.not` earlier in the chain to negate `.arguments`. However, it's often
  1200. * best to assert which type the target is expected to be, rather than
  1201. * asserting that it’s not an `arguments` object.
  1202. *
  1203. * expect('foo').to.be.a('string'); // Recommended
  1204. * expect('foo').to.not.be.arguments; // Not recommended
  1205. *
  1206. * A custom error message can be given as the second argument to `expect`.
  1207. *
  1208. * expect({}, 'nooo why fail??').to.be.arguments;
  1209. *
  1210. * The alias `.Arguments` can be used interchangeably with `.arguments`.
  1211. *
  1212. * @name arguments
  1213. * @alias Arguments
  1214. * @namespace BDD
  1215. * @api public
  1216. */
  1217. function checkArguments () {
  1218. var obj = flag(this, 'object')
  1219. , type = _.type(obj);
  1220. this.assert(
  1221. 'Arguments' === type
  1222. , 'expected #{this} to be arguments but got ' + type
  1223. , 'expected #{this} to not be arguments'
  1224. );
  1225. }
  1226. Assertion.addProperty('arguments', checkArguments);
  1227. Assertion.addProperty('Arguments', checkArguments);
  1228. /**
  1229. * ### .equal(val[, msg])
  1230. *
  1231. * Asserts that the target is strictly (`===`) equal to the given `val`.
  1232. *
  1233. * expect(1).to.equal(1);
  1234. * expect('foo').to.equal('foo');
  1235. *
  1236. * Add `.deep` earlier in the chain to use deep equality instead. See the
  1237. * `deep-eql` project page for info on the deep equality algorithm:
  1238. * https://github.com/chaijs/deep-eql.
  1239. *
  1240. * // Target object deeply (but not strictly) equals `{a: 1}`
  1241. * expect({a: 1}).to.deep.equal({a: 1});
  1242. * expect({a: 1}).to.not.equal({a: 1});
  1243. *
  1244. * // Target array deeply (but not strictly) equals `[1, 2]`
  1245. * expect([1, 2]).to.deep.equal([1, 2]);
  1246. * expect([1, 2]).to.not.equal([1, 2]);
  1247. *
  1248. * Add `.not` earlier in the chain to negate `.equal`. However, it's often
  1249. * best to assert that the target is equal to its expected value, rather than
  1250. * not equal to one of countless unexpected values.
  1251. *
  1252. * expect(1).to.equal(1); // Recommended
  1253. * expect(1).to.not.equal(2); // Not recommended
  1254. *
  1255. * `.equal` accepts an optional `msg` argument which is a custom error message
  1256. * to show when the assertion fails. The message can also be given as the
  1257. * second argument to `expect`.
  1258. *
  1259. * expect(1).to.equal(2, 'nooo why fail??');
  1260. * expect(1, 'nooo why fail??').to.equal(2);
  1261. *
  1262. * The aliases `.equals` and `eq` can be used interchangeably with `.equal`.
  1263. *
  1264. * @name equal
  1265. * @alias equals
  1266. * @alias eq
  1267. * @param {Mixed} val
  1268. * @param {String} msg _optional_
  1269. * @namespace BDD
  1270. * @api public
  1271. */
  1272. function assertEqual (val, msg) {
  1273. if (msg) flag(this, 'message', msg);
  1274. var obj = flag(this, 'object');
  1275. if (flag(this, 'deep')) {
  1276. var prevLockSsfi = flag(this, 'lockSsfi');
  1277. flag(this, 'lockSsfi', true);
  1278. this.eql(val);
  1279. flag(this, 'lockSsfi', prevLockSsfi);
  1280. } else {
  1281. this.assert(
  1282. val === obj
  1283. , 'expected #{this} to equal #{exp}'
  1284. , 'expected #{this} to not equal #{exp}'
  1285. , val
  1286. , this._obj
  1287. , true
  1288. );
  1289. }
  1290. }
  1291. Assertion.addMethod('equal', assertEqual);
  1292. Assertion.addMethod('equals', assertEqual);
  1293. Assertion.addMethod('eq', assertEqual);
  1294. /**
  1295. * ### .eql(obj[, msg])
  1296. *
  1297. * Asserts that the target is deeply equal to the given `obj`. See the
  1298. * `deep-eql` project page for info on the deep equality algorithm:
  1299. * https://github.com/chaijs/deep-eql.
  1300. *
  1301. * // Target object is deeply (but not strictly) equal to {a: 1}
  1302. * expect({a: 1}).to.eql({a: 1}).but.not.equal({a: 1});
  1303. *
  1304. * // Target array is deeply (but not strictly) equal to [1, 2]
  1305. * expect([1, 2]).to.eql([1, 2]).but.not.equal([1, 2]);
  1306. *
  1307. * Add `.not` earlier in the chain to negate `.eql`. However, it's often best
  1308. * to assert that the target is deeply equal to its expected value, rather
  1309. * than not deeply equal to one of countless unexpected values.
  1310. *
  1311. * expect({a: 1}).to.eql({a: 1}); // Recommended
  1312. * expect({a: 1}).to.not.eql({b: 2}); // Not recommended
  1313. *
  1314. * `.eql` accepts an optional `msg` argument which is a custom error message
  1315. * to show when the assertion fails. The message can also be given as the
  1316. * second argument to `expect`.
  1317. *
  1318. * expect({a: 1}).to.eql({b: 2}, 'nooo why fail??');
  1319. * expect({a: 1}, 'nooo why fail??').to.eql({b: 2});
  1320. *
  1321. * The alias `.eqls` can be used interchangeably with `.eql`.
  1322. *
  1323. * The `.deep.equal` assertion is almost identical to `.eql` but with one
  1324. * difference: `.deep.equal` causes deep equality comparisons to also be used
  1325. * for any other assertions that follow in the chain.
  1326. *
  1327. * @name eql
  1328. * @alias eqls
  1329. * @param {Mixed} obj
  1330. * @param {String} msg _optional_
  1331. * @namespace BDD
  1332. * @api public
  1333. */
  1334. function assertEql(obj, msg) {
  1335. if (msg) flag(this, 'message', msg);
  1336. this.assert(
  1337. _.eql(obj, flag(this, 'object'))
  1338. , 'expected #{this} to deeply equal #{exp}'
  1339. , 'expected #{this} to not deeply equal #{exp}'
  1340. , obj
  1341. , this._obj
  1342. , true
  1343. );
  1344. }
  1345. Assertion.addMethod('eql', assertEql);
  1346. Assertion.addMethod('eqls', assertEql);
  1347. /**
  1348. * ### .above(n[, msg])
  1349. *
  1350. * Asserts that the target is a number or a date greater than the given number or date `n` respectively.
  1351. * However, it's often best to assert that the target is equal to its expected
  1352. * value.
  1353. *
  1354. * expect(2).to.equal(2); // Recommended
  1355. * expect(2).to.be.above(1); // Not recommended
  1356. *
  1357. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1358. * or `size` is greater than the given number `n`.
  1359. *
  1360. * expect('foo').to.have.lengthOf(3); // Recommended
  1361. * expect('foo').to.have.lengthOf.above(2); // Not recommended
  1362. *
  1363. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1364. * expect([1, 2, 3]).to.have.lengthOf.above(2); // Not recommended
  1365. *
  1366. * Add `.not` earlier in the chain to negate `.above`.
  1367. *
  1368. * expect(2).to.equal(2); // Recommended
  1369. * expect(1).to.not.be.above(2); // Not recommended
  1370. *
  1371. * `.above` accepts an optional `msg` argument which is a custom error message
  1372. * to show when the assertion fails. The message can also be given as the
  1373. * second argument to `expect`.
  1374. *
  1375. * expect(1).to.be.above(2, 'nooo why fail??');
  1376. * expect(1, 'nooo why fail??').to.be.above(2);
  1377. *
  1378. * The aliases `.gt` and `.greaterThan` can be used interchangeably with
  1379. * `.above`.
  1380. *
  1381. * @name above
  1382. * @alias gt
  1383. * @alias greaterThan
  1384. * @param {Number} n
  1385. * @param {String} msg _optional_
  1386. * @namespace BDD
  1387. * @api public
  1388. */
  1389. function assertAbove (n, msg) {
  1390. if (msg) flag(this, 'message', msg);
  1391. var obj = flag(this, 'object')
  1392. , doLength = flag(this, 'doLength')
  1393. , flagMsg = flag(this, 'message')
  1394. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1395. , ssfi = flag(this, 'ssfi')
  1396. , objType = _.type(obj).toLowerCase()
  1397. , nType = _.type(n).toLowerCase()
  1398. , errorMessage
  1399. , shouldThrow = true;
  1400. if (doLength && objType !== 'map' && objType !== 'set') {
  1401. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1402. }
  1403. if (!doLength && (objType === 'date' && nType !== 'date')) {
  1404. errorMessage = msgPrefix + 'the argument to above must be a date';
  1405. } else if (nType !== 'number' && (doLength || objType === 'number')) {
  1406. errorMessage = msgPrefix + 'the argument to above must be a number';
  1407. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1408. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1409. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1410. } else {
  1411. shouldThrow = false;
  1412. }
  1413. if (shouldThrow) {
  1414. throw new AssertionError(errorMessage, undefined, ssfi);
  1415. }
  1416. if (doLength) {
  1417. var descriptor = 'length'
  1418. , itemsCount;
  1419. if (objType === 'map' || objType === 'set') {
  1420. descriptor = 'size';
  1421. itemsCount = obj.size;
  1422. } else {
  1423. itemsCount = obj.length;
  1424. }
  1425. this.assert(
  1426. itemsCount > n
  1427. , 'expected #{this} to have a ' + descriptor + ' above #{exp} but got #{act}'
  1428. , 'expected #{this} to not have a ' + descriptor + ' above #{exp}'
  1429. , n
  1430. , itemsCount
  1431. );
  1432. } else {
  1433. this.assert(
  1434. obj > n
  1435. , 'expected #{this} to be above #{exp}'
  1436. , 'expected #{this} to be at most #{exp}'
  1437. , n
  1438. );
  1439. }
  1440. }
  1441. Assertion.addMethod('above', assertAbove);
  1442. Assertion.addMethod('gt', assertAbove);
  1443. Assertion.addMethod('greaterThan', assertAbove);
  1444. /**
  1445. * ### .least(n[, msg])
  1446. *
  1447. * Asserts that the target is a number or a date greater than or equal to the given
  1448. * number or date `n` respectively. However, it's often best to assert that the target is equal to
  1449. * its expected value.
  1450. *
  1451. * expect(2).to.equal(2); // Recommended
  1452. * expect(2).to.be.at.least(1); // Not recommended
  1453. * expect(2).to.be.at.least(2); // Not recommended
  1454. *
  1455. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1456. * or `size` is greater than or equal to the given number `n`.
  1457. *
  1458. * expect('foo').to.have.lengthOf(3); // Recommended
  1459. * expect('foo').to.have.lengthOf.at.least(2); // Not recommended
  1460. *
  1461. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1462. * expect([1, 2, 3]).to.have.lengthOf.at.least(2); // Not recommended
  1463. *
  1464. * Add `.not` earlier in the chain to negate `.least`.
  1465. *
  1466. * expect(1).to.equal(1); // Recommended
  1467. * expect(1).to.not.be.at.least(2); // Not recommended
  1468. *
  1469. * `.least` accepts an optional `msg` argument which is a custom error message
  1470. * to show when the assertion fails. The message can also be given as the
  1471. * second argument to `expect`.
  1472. *
  1473. * expect(1).to.be.at.least(2, 'nooo why fail??');
  1474. * expect(1, 'nooo why fail??').to.be.at.least(2);
  1475. *
  1476. * The aliases `.gte` and `.greaterThanOrEqual` can be used interchangeably with
  1477. * `.least`.
  1478. *
  1479. * @name least
  1480. * @alias gte
  1481. * @alias greaterThanOrEqual
  1482. * @param {Number} n
  1483. * @param {String} msg _optional_
  1484. * @namespace BDD
  1485. * @api public
  1486. */
  1487. function assertLeast (n, msg) {
  1488. if (msg) flag(this, 'message', msg);
  1489. var obj = flag(this, 'object')
  1490. , doLength = flag(this, 'doLength')
  1491. , flagMsg = flag(this, 'message')
  1492. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1493. , ssfi = flag(this, 'ssfi')
  1494. , objType = _.type(obj).toLowerCase()
  1495. , nType = _.type(n).toLowerCase()
  1496. , errorMessage
  1497. , shouldThrow = true;
  1498. if (doLength && objType !== 'map' && objType !== 'set') {
  1499. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1500. }
  1501. if (!doLength && (objType === 'date' && nType !== 'date')) {
  1502. errorMessage = msgPrefix + 'the argument to least must be a date';
  1503. } else if (nType !== 'number' && (doLength || objType === 'number')) {
  1504. errorMessage = msgPrefix + 'the argument to least must be a number';
  1505. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1506. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1507. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1508. } else {
  1509. shouldThrow = false;
  1510. }
  1511. if (shouldThrow) {
  1512. throw new AssertionError(errorMessage, undefined, ssfi);
  1513. }
  1514. if (doLength) {
  1515. var descriptor = 'length'
  1516. , itemsCount;
  1517. if (objType === 'map' || objType === 'set') {
  1518. descriptor = 'size';
  1519. itemsCount = obj.size;
  1520. } else {
  1521. itemsCount = obj.length;
  1522. }
  1523. this.assert(
  1524. itemsCount >= n
  1525. , 'expected #{this} to have a ' + descriptor + ' at least #{exp} but got #{act}'
  1526. , 'expected #{this} to have a ' + descriptor + ' below #{exp}'
  1527. , n
  1528. , itemsCount
  1529. );
  1530. } else {
  1531. this.assert(
  1532. obj >= n
  1533. , 'expected #{this} to be at least #{exp}'
  1534. , 'expected #{this} to be below #{exp}'
  1535. , n
  1536. );
  1537. }
  1538. }
  1539. Assertion.addMethod('least', assertLeast);
  1540. Assertion.addMethod('gte', assertLeast);
  1541. Assertion.addMethod('greaterThanOrEqual', assertLeast);
  1542. /**
  1543. * ### .below(n[, msg])
  1544. *
  1545. * Asserts that the target is a number or a date less than the given number or date `n` respectively.
  1546. * However, it's often best to assert that the target is equal to its expected
  1547. * value.
  1548. *
  1549. * expect(1).to.equal(1); // Recommended
  1550. * expect(1).to.be.below(2); // Not recommended
  1551. *
  1552. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1553. * or `size` is less than the given number `n`.
  1554. *
  1555. * expect('foo').to.have.lengthOf(3); // Recommended
  1556. * expect('foo').to.have.lengthOf.below(4); // Not recommended
  1557. *
  1558. * expect([1, 2, 3]).to.have.length(3); // Recommended
  1559. * expect([1, 2, 3]).to.have.lengthOf.below(4); // Not recommended
  1560. *
  1561. * Add `.not` earlier in the chain to negate `.below`.
  1562. *
  1563. * expect(2).to.equal(2); // Recommended
  1564. * expect(2).to.not.be.below(1); // Not recommended
  1565. *
  1566. * `.below` accepts an optional `msg` argument which is a custom error message
  1567. * to show when the assertion fails. The message can also be given as the
  1568. * second argument to `expect`.
  1569. *
  1570. * expect(2).to.be.below(1, 'nooo why fail??');
  1571. * expect(2, 'nooo why fail??').to.be.below(1);
  1572. *
  1573. * The aliases `.lt` and `.lessThan` can be used interchangeably with
  1574. * `.below`.
  1575. *
  1576. * @name below
  1577. * @alias lt
  1578. * @alias lessThan
  1579. * @param {Number} n
  1580. * @param {String} msg _optional_
  1581. * @namespace BDD
  1582. * @api public
  1583. */
  1584. function assertBelow (n, msg) {
  1585. if (msg) flag(this, 'message', msg);
  1586. var obj = flag(this, 'object')
  1587. , doLength = flag(this, 'doLength')
  1588. , flagMsg = flag(this, 'message')
  1589. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1590. , ssfi = flag(this, 'ssfi')
  1591. , objType = _.type(obj).toLowerCase()
  1592. , nType = _.type(n).toLowerCase()
  1593. , errorMessage
  1594. , shouldThrow = true;
  1595. if (doLength && objType !== 'map' && objType !== 'set') {
  1596. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1597. }
  1598. if (!doLength && (objType === 'date' && nType !== 'date')) {
  1599. errorMessage = msgPrefix + 'the argument to below must be a date';
  1600. } else if (nType !== 'number' && (doLength || objType === 'number')) {
  1601. errorMessage = msgPrefix + 'the argument to below must be a number';
  1602. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1603. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1604. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1605. } else {
  1606. shouldThrow = false;
  1607. }
  1608. if (shouldThrow) {
  1609. throw new AssertionError(errorMessage, undefined, ssfi);
  1610. }
  1611. if (doLength) {
  1612. var descriptor = 'length'
  1613. , itemsCount;
  1614. if (objType === 'map' || objType === 'set') {
  1615. descriptor = 'size';
  1616. itemsCount = obj.size;
  1617. } else {
  1618. itemsCount = obj.length;
  1619. }
  1620. this.assert(
  1621. itemsCount < n
  1622. , 'expected #{this} to have a ' + descriptor + ' below #{exp} but got #{act}'
  1623. , 'expected #{this} to not have a ' + descriptor + ' below #{exp}'
  1624. , n
  1625. , itemsCount
  1626. );
  1627. } else {
  1628. this.assert(
  1629. obj < n
  1630. , 'expected #{this} to be below #{exp}'
  1631. , 'expected #{this} to be at least #{exp}'
  1632. , n
  1633. );
  1634. }
  1635. }
  1636. Assertion.addMethod('below', assertBelow);
  1637. Assertion.addMethod('lt', assertBelow);
  1638. Assertion.addMethod('lessThan', assertBelow);
  1639. /**
  1640. * ### .most(n[, msg])
  1641. *
  1642. * Asserts that the target is a number or a date less than or equal to the given number
  1643. * or date `n` respectively. However, it's often best to assert that the target is equal to its
  1644. * expected value.
  1645. *
  1646. * expect(1).to.equal(1); // Recommended
  1647. * expect(1).to.be.at.most(2); // Not recommended
  1648. * expect(1).to.be.at.most(1); // Not recommended
  1649. *
  1650. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1651. * or `size` is less than or equal to the given number `n`.
  1652. *
  1653. * expect('foo').to.have.lengthOf(3); // Recommended
  1654. * expect('foo').to.have.lengthOf.at.most(4); // Not recommended
  1655. *
  1656. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1657. * expect([1, 2, 3]).to.have.lengthOf.at.most(4); // Not recommended
  1658. *
  1659. * Add `.not` earlier in the chain to negate `.most`.
  1660. *
  1661. * expect(2).to.equal(2); // Recommended
  1662. * expect(2).to.not.be.at.most(1); // Not recommended
  1663. *
  1664. * `.most` accepts an optional `msg` argument which is a custom error message
  1665. * to show when the assertion fails. The message can also be given as the
  1666. * second argument to `expect`.
  1667. *
  1668. * expect(2).to.be.at.most(1, 'nooo why fail??');
  1669. * expect(2, 'nooo why fail??').to.be.at.most(1);
  1670. *
  1671. * The aliases `.lte` and `.lessThanOrEqual` can be used interchangeably with
  1672. * `.most`.
  1673. *
  1674. * @name most
  1675. * @alias lte
  1676. * @alias lessThanOrEqual
  1677. * @param {Number} n
  1678. * @param {String} msg _optional_
  1679. * @namespace BDD
  1680. * @api public
  1681. */
  1682. function assertMost (n, msg) {
  1683. if (msg) flag(this, 'message', msg);
  1684. var obj = flag(this, 'object')
  1685. , doLength = flag(this, 'doLength')
  1686. , flagMsg = flag(this, 'message')
  1687. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1688. , ssfi = flag(this, 'ssfi')
  1689. , objType = _.type(obj).toLowerCase()
  1690. , nType = _.type(n).toLowerCase()
  1691. , errorMessage
  1692. , shouldThrow = true;
  1693. if (doLength && objType !== 'map' && objType !== 'set') {
  1694. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1695. }
  1696. if (!doLength && (objType === 'date' && nType !== 'date')) {
  1697. errorMessage = msgPrefix + 'the argument to most must be a date';
  1698. } else if (nType !== 'number' && (doLength || objType === 'number')) {
  1699. errorMessage = msgPrefix + 'the argument to most must be a number';
  1700. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1701. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1702. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1703. } else {
  1704. shouldThrow = false;
  1705. }
  1706. if (shouldThrow) {
  1707. throw new AssertionError(errorMessage, undefined, ssfi);
  1708. }
  1709. if (doLength) {
  1710. var descriptor = 'length'
  1711. , itemsCount;
  1712. if (objType === 'map' || objType === 'set') {
  1713. descriptor = 'size';
  1714. itemsCount = obj.size;
  1715. } else {
  1716. itemsCount = obj.length;
  1717. }
  1718. this.assert(
  1719. itemsCount <= n
  1720. , 'expected #{this} to have a ' + descriptor + ' at most #{exp} but got #{act}'
  1721. , 'expected #{this} to have a ' + descriptor + ' above #{exp}'
  1722. , n
  1723. , itemsCount
  1724. );
  1725. } else {
  1726. this.assert(
  1727. obj <= n
  1728. , 'expected #{this} to be at most #{exp}'
  1729. , 'expected #{this} to be above #{exp}'
  1730. , n
  1731. );
  1732. }
  1733. }
  1734. Assertion.addMethod('most', assertMost);
  1735. Assertion.addMethod('lte', assertMost);
  1736. Assertion.addMethod('lessThanOrEqual', assertMost);
  1737. /**
  1738. * ### .within(start, finish[, msg])
  1739. *
  1740. * Asserts that the target is a number or a date greater than or equal to the given
  1741. * number or date `start`, and less than or equal to the given number or date `finish` respectively.
  1742. * However, it's often best to assert that the target is equal to its expected
  1743. * value.
  1744. *
  1745. * expect(2).to.equal(2); // Recommended
  1746. * expect(2).to.be.within(1, 3); // Not recommended
  1747. * expect(2).to.be.within(2, 3); // Not recommended
  1748. * expect(2).to.be.within(1, 2); // Not recommended
  1749. *
  1750. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1751. * or `size` is greater than or equal to the given number `start`, and less
  1752. * than or equal to the given number `finish`.
  1753. *
  1754. * expect('foo').to.have.lengthOf(3); // Recommended
  1755. * expect('foo').to.have.lengthOf.within(2, 4); // Not recommended
  1756. *
  1757. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1758. * expect([1, 2, 3]).to.have.lengthOf.within(2, 4); // Not recommended
  1759. *
  1760. * Add `.not` earlier in the chain to negate `.within`.
  1761. *
  1762. * expect(1).to.equal(1); // Recommended
  1763. * expect(1).to.not.be.within(2, 4); // Not recommended
  1764. *
  1765. * `.within` accepts an optional `msg` argument which is a custom error
  1766. * message to show when the assertion fails. The message can also be given as
  1767. * the second argument to `expect`.
  1768. *
  1769. * expect(4).to.be.within(1, 3, 'nooo why fail??');
  1770. * expect(4, 'nooo why fail??').to.be.within(1, 3);
  1771. *
  1772. * @name within
  1773. * @param {Number} start lower bound inclusive
  1774. * @param {Number} finish upper bound inclusive
  1775. * @param {String} msg _optional_
  1776. * @namespace BDD
  1777. * @api public
  1778. */
  1779. Assertion.addMethod('within', function (start, finish, msg) {
  1780. if (msg) flag(this, 'message', msg);
  1781. var obj = flag(this, 'object')
  1782. , doLength = flag(this, 'doLength')
  1783. , flagMsg = flag(this, 'message')
  1784. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1785. , ssfi = flag(this, 'ssfi')
  1786. , objType = _.type(obj).toLowerCase()
  1787. , startType = _.type(start).toLowerCase()
  1788. , finishType = _.type(finish).toLowerCase()
  1789. , errorMessage
  1790. , shouldThrow = true
  1791. , range = (startType === 'date' && finishType === 'date')
  1792. ? start.toUTCString() + '..' + finish.toUTCString()
  1793. : start + '..' + finish;
  1794. if (doLength && objType !== 'map' && objType !== 'set') {
  1795. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1796. }
  1797. if (!doLength && (objType === 'date' && (startType !== 'date' || finishType !== 'date'))) {
  1798. errorMessage = msgPrefix + 'the arguments to within must be dates';
  1799. } else if ((startType !== 'number' || finishType !== 'number') && (doLength || objType === 'number')) {
  1800. errorMessage = msgPrefix + 'the arguments to within must be numbers';
  1801. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1802. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1803. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1804. } else {
  1805. shouldThrow = false;
  1806. }
  1807. if (shouldThrow) {
  1808. throw new AssertionError(errorMessage, undefined, ssfi);
  1809. }
  1810. if (doLength) {
  1811. var descriptor = 'length'
  1812. , itemsCount;
  1813. if (objType === 'map' || objType === 'set') {
  1814. descriptor = 'size';
  1815. itemsCount = obj.size;
  1816. } else {
  1817. itemsCount = obj.length;
  1818. }
  1819. this.assert(
  1820. itemsCount >= start && itemsCount <= finish
  1821. , 'expected #{this} to have a ' + descriptor + ' within ' + range
  1822. , 'expected #{this} to not have a ' + descriptor + ' within ' + range
  1823. );
  1824. } else {
  1825. this.assert(
  1826. obj >= start && obj <= finish
  1827. , 'expected #{this} to be within ' + range
  1828. , 'expected #{this} to not be within ' + range
  1829. );
  1830. }
  1831. });
  1832. /**
  1833. * ### .instanceof(constructor[, msg])
  1834. *
  1835. * Asserts that the target is an instance of the given `constructor`.
  1836. *
  1837. * function Cat () { }
  1838. *
  1839. * expect(new Cat()).to.be.an.instanceof(Cat);
  1840. * expect([1, 2]).to.be.an.instanceof(Array);
  1841. *
  1842. * Add `.not` earlier in the chain to negate `.instanceof`.
  1843. *
  1844. * expect({a: 1}).to.not.be.an.instanceof(Array);
  1845. *
  1846. * `.instanceof` accepts an optional `msg` argument which is a custom error
  1847. * message to show when the assertion fails. The message can also be given as
  1848. * the second argument to `expect`.
  1849. *
  1850. * expect(1).to.be.an.instanceof(Array, 'nooo why fail??');
  1851. * expect(1, 'nooo why fail??').to.be.an.instanceof(Array);
  1852. *
  1853. * Due to limitations in ES5, `.instanceof` may not always work as expected
  1854. * when using a transpiler such as Babel or TypeScript. In particular, it may
  1855. * produce unexpected results when subclassing built-in object such as
  1856. * `Array`, `Error`, and `Map`. See your transpiler's docs for details:
  1857. *
  1858. * - ([Babel](https://babeljs.io/docs/usage/caveats/#classes))
  1859. * - ([TypeScript](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work))
  1860. *
  1861. * The alias `.instanceOf` can be used interchangeably with `.instanceof`.
  1862. *
  1863. * @name instanceof
  1864. * @param {Constructor} constructor
  1865. * @param {String} msg _optional_
  1866. * @alias instanceOf
  1867. * @namespace BDD
  1868. * @api public
  1869. */
  1870. function assertInstanceOf (constructor, msg) {
  1871. if (msg) flag(this, 'message', msg);
  1872. var target = flag(this, 'object')
  1873. var ssfi = flag(this, 'ssfi');
  1874. var flagMsg = flag(this, 'message');
  1875. try {
  1876. var isInstanceOf = target instanceof constructor;
  1877. } catch (err) {
  1878. if (err instanceof TypeError) {
  1879. flagMsg = flagMsg ? flagMsg + ': ' : '';
  1880. throw new AssertionError(
  1881. flagMsg + 'The instanceof assertion needs a constructor but '
  1882. + _.type(constructor) + ' was given.',
  1883. undefined,
  1884. ssfi
  1885. );
  1886. }
  1887. throw err;
  1888. }
  1889. var name = _.getName(constructor);
  1890. if (name === null) {
  1891. name = 'an unnamed constructor';
  1892. }
  1893. this.assert(
  1894. isInstanceOf
  1895. , 'expected #{this} to be an instance of ' + name
  1896. , 'expected #{this} to not be an instance of ' + name
  1897. );
  1898. };
  1899. Assertion.addMethod('instanceof', assertInstanceOf);
  1900. Assertion.addMethod('instanceOf', assertInstanceOf);
  1901. /**
  1902. * ### .property(name[, val[, msg]])
  1903. *
  1904. * Asserts that the target has a property with the given key `name`.
  1905. *
  1906. * expect({a: 1}).to.have.property('a');
  1907. *
  1908. * When `val` is provided, `.property` also asserts that the property's value
  1909. * is equal to the given `val`.
  1910. *
  1911. * expect({a: 1}).to.have.property('a', 1);
  1912. *
  1913. * By default, strict (`===`) equality is used. Add `.deep` earlier in the
  1914. * chain to use deep equality instead. See the `deep-eql` project page for
  1915. * info on the deep equality algorithm: https://github.com/chaijs/deep-eql.
  1916. *
  1917. * // Target object deeply (but not strictly) has property `x: {a: 1}`
  1918. * expect({x: {a: 1}}).to.have.deep.property('x', {a: 1});
  1919. * expect({x: {a: 1}}).to.not.have.property('x', {a: 1});
  1920. *
  1921. * The target's enumerable and non-enumerable properties are always included
  1922. * in the search. By default, both own and inherited properties are included.
  1923. * Add `.own` earlier in the chain to exclude inherited properties from the
  1924. * search.
  1925. *
  1926. * Object.prototype.b = 2;
  1927. *
  1928. * expect({a: 1}).to.have.own.property('a');
  1929. * expect({a: 1}).to.have.own.property('a', 1);
  1930. * expect({a: 1}).to.have.property('b');
  1931. * expect({a: 1}).to.not.have.own.property('b');
  1932. *
  1933. * `.deep` and `.own` can be combined.
  1934. *
  1935. * expect({x: {a: 1}}).to.have.deep.own.property('x', {a: 1});
  1936. *
  1937. * Add `.nested` earlier in the chain to enable dot- and bracket-notation when
  1938. * referencing nested properties.
  1939. *
  1940. * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]');
  1941. * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]', 'y');
  1942. *
  1943. * If `.` or `[]` are part of an actual property name, they can be escaped by
  1944. * adding two backslashes before them.
  1945. *
  1946. * expect({'.a': {'[b]': 'x'}}).to.have.nested.property('\\.a.\\[b\\]');
  1947. *
  1948. * `.deep` and `.nested` can be combined.
  1949. *
  1950. * expect({a: {b: [{c: 3}]}})
  1951. * .to.have.deep.nested.property('a.b[0]', {c: 3});
  1952. *
  1953. * `.own` and `.nested` cannot be combined.
  1954. *
  1955. * Add `.not` earlier in the chain to negate `.property`.
  1956. *
  1957. * expect({a: 1}).to.not.have.property('b');
  1958. *
  1959. * However, it's dangerous to negate `.property` when providing `val`. The
  1960. * problem is that it creates uncertain expectations by asserting that the
  1961. * target either doesn't have a property with the given key `name`, or that it
  1962. * does have a property with the given key `name` but its value isn't equal to
  1963. * the given `val`. It's often best to identify the exact output that's
  1964. * expected, and then write an assertion that only accepts that exact output.
  1965. *
  1966. * When the target isn't expected to have a property with the given key
  1967. * `name`, it's often best to assert exactly that.
  1968. *
  1969. * expect({b: 2}).to.not.have.property('a'); // Recommended
  1970. * expect({b: 2}).to.not.have.property('a', 1); // Not recommended
  1971. *
  1972. * When the target is expected to have a property with the given key `name`,
  1973. * it's often best to assert that the property has its expected value, rather
  1974. * than asserting that it doesn't have one of many unexpected values.
  1975. *
  1976. * expect({a: 3}).to.have.property('a', 3); // Recommended
  1977. * expect({a: 3}).to.not.have.property('a', 1); // Not recommended
  1978. *
  1979. * `.property` changes the target of any assertions that follow in the chain
  1980. * to be the value of the property from the original target object.
  1981. *
  1982. * expect({a: 1}).to.have.property('a').that.is.a('number');
  1983. *
  1984. * `.property` accepts an optional `msg` argument which is a custom error
  1985. * message to show when the assertion fails. The message can also be given as
  1986. * the second argument to `expect`. When not providing `val`, only use the
  1987. * second form.
  1988. *
  1989. * // Recommended
  1990. * expect({a: 1}).to.have.property('a', 2, 'nooo why fail??');
  1991. * expect({a: 1}, 'nooo why fail??').to.have.property('a', 2);
  1992. * expect({a: 1}, 'nooo why fail??').to.have.property('b');
  1993. *
  1994. * // Not recommended
  1995. * expect({a: 1}).to.have.property('b', undefined, 'nooo why fail??');
  1996. *
  1997. * The above assertion isn't the same thing as not providing `val`. Instead,
  1998. * it's asserting that the target object has a `b` property that's equal to
  1999. * `undefined`.
  2000. *
  2001. * The assertions `.ownProperty` and `.haveOwnProperty` can be used
  2002. * interchangeably with `.own.property`.
  2003. *
  2004. * @name property
  2005. * @param {String} name
  2006. * @param {Mixed} val (optional)
  2007. * @param {String} msg _optional_
  2008. * @returns value of property for chaining
  2009. * @namespace BDD
  2010. * @api public
  2011. */
  2012. function assertProperty (name, val, msg) {
  2013. if (msg) flag(this, 'message', msg);
  2014. var isNested = flag(this, 'nested')
  2015. , isOwn = flag(this, 'own')
  2016. , flagMsg = flag(this, 'message')
  2017. , obj = flag(this, 'object')
  2018. , ssfi = flag(this, 'ssfi')
  2019. , nameType = typeof name;
  2020. flagMsg = flagMsg ? flagMsg + ': ' : '';
  2021. if (isNested) {
  2022. if (nameType !== 'string') {
  2023. throw new AssertionError(
  2024. flagMsg + 'the argument to property must be a string when using nested syntax',
  2025. undefined,
  2026. ssfi
  2027. );
  2028. }
  2029. } else {
  2030. if (nameType !== 'string' && nameType !== 'number' && nameType !== 'symbol') {
  2031. throw new AssertionError(
  2032. flagMsg + 'the argument to property must be a string, number, or symbol',
  2033. undefined,
  2034. ssfi
  2035. );
  2036. }
  2037. }
  2038. if (isNested && isOwn) {
  2039. throw new AssertionError(
  2040. flagMsg + 'The "nested" and "own" flags cannot be combined.',
  2041. undefined,
  2042. ssfi
  2043. );
  2044. }
  2045. if (obj === null || obj === undefined) {
  2046. throw new AssertionError(
  2047. flagMsg + 'Target cannot be null or undefined.',
  2048. undefined,
  2049. ssfi
  2050. );
  2051. }
  2052. var isDeep = flag(this, 'deep')
  2053. , negate = flag(this, 'negate')
  2054. , pathInfo = isNested ? _.getPathInfo(obj, name) : null
  2055. , value = isNested ? pathInfo.value : obj[name];
  2056. var descriptor = '';
  2057. if (isDeep) descriptor += 'deep ';
  2058. if (isOwn) descriptor += 'own ';
  2059. if (isNested) descriptor += 'nested ';
  2060. descriptor += 'property ';
  2061. var hasProperty;
  2062. if (isOwn) hasProperty = Object.prototype.hasOwnProperty.call(obj, name);
  2063. else if (isNested) hasProperty = pathInfo.exists;
  2064. else hasProperty = _.hasProperty(obj, name);
  2065. // When performing a negated assertion for both name and val, merely having
  2066. // a property with the given name isn't enough to cause the assertion to
  2067. // fail. It must both have a property with the given name, and the value of
  2068. // that property must equal the given val. Therefore, skip this assertion in
  2069. // favor of the next.
  2070. if (!negate || arguments.length === 1) {
  2071. this.assert(
  2072. hasProperty
  2073. , 'expected #{this} to have ' + descriptor + _.inspect(name)
  2074. , 'expected #{this} to not have ' + descriptor + _.inspect(name));
  2075. }
  2076. if (arguments.length > 1) {
  2077. this.assert(
  2078. hasProperty && (isDeep ? _.eql(val, value) : val === value)
  2079. , 'expected #{this} to have ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
  2080. , 'expected #{this} to not have ' + descriptor + _.inspect(name) + ' of #{act}'
  2081. , val
  2082. , value
  2083. );
  2084. }
  2085. flag(this, 'object', value);
  2086. }
  2087. Assertion.addMethod('property', assertProperty);
  2088. function assertOwnProperty (name, value, msg) {
  2089. flag(this, 'own', true);
  2090. assertProperty.apply(this, arguments);
  2091. }
  2092. Assertion.addMethod('ownProperty', assertOwnProperty);
  2093. Assertion.addMethod('haveOwnProperty', assertOwnProperty);
  2094. /**
  2095. * ### .ownPropertyDescriptor(name[, descriptor[, msg]])
  2096. *
  2097. * Asserts that the target has its own property descriptor with the given key
  2098. * `name`. Enumerable and non-enumerable properties are included in the
  2099. * search.
  2100. *
  2101. * expect({a: 1}).to.have.ownPropertyDescriptor('a');
  2102. *
  2103. * When `descriptor` is provided, `.ownPropertyDescriptor` also asserts that
  2104. * the property's descriptor is deeply equal to the given `descriptor`. See
  2105. * the `deep-eql` project page for info on the deep equality algorithm:
  2106. * https://github.com/chaijs/deep-eql.
  2107. *
  2108. * expect({a: 1}).to.have.ownPropertyDescriptor('a', {
  2109. * configurable: true,
  2110. * enumerable: true,
  2111. * writable: true,
  2112. * value: 1,
  2113. * });
  2114. *
  2115. * Add `.not` earlier in the chain to negate `.ownPropertyDescriptor`.
  2116. *
  2117. * expect({a: 1}).to.not.have.ownPropertyDescriptor('b');
  2118. *
  2119. * However, it's dangerous to negate `.ownPropertyDescriptor` when providing
  2120. * a `descriptor`. The problem is that it creates uncertain expectations by
  2121. * asserting that the target either doesn't have a property descriptor with
  2122. * the given key `name`, or that it does have a property descriptor with the
  2123. * given key `name` but it’s not deeply equal to the given `descriptor`. It's
  2124. * often best to identify the exact output that's expected, and then write an
  2125. * assertion that only accepts that exact output.
  2126. *
  2127. * When the target isn't expected to have a property descriptor with the given
  2128. * key `name`, it's often best to assert exactly that.
  2129. *
  2130. * // Recommended
  2131. * expect({b: 2}).to.not.have.ownPropertyDescriptor('a');
  2132. *
  2133. * // Not recommended
  2134. * expect({b: 2}).to.not.have.ownPropertyDescriptor('a', {
  2135. * configurable: true,
  2136. * enumerable: true,
  2137. * writable: true,
  2138. * value: 1,
  2139. * });
  2140. *
  2141. * When the target is expected to have a property descriptor with the given
  2142. * key `name`, it's often best to assert that the property has its expected
  2143. * descriptor, rather than asserting that it doesn't have one of many
  2144. * unexpected descriptors.
  2145. *
  2146. * // Recommended
  2147. * expect({a: 3}).to.have.ownPropertyDescriptor('a', {
  2148. * configurable: true,
  2149. * enumerable: true,
  2150. * writable: true,
  2151. * value: 3,
  2152. * });
  2153. *
  2154. * // Not recommended
  2155. * expect({a: 3}).to.not.have.ownPropertyDescriptor('a', {
  2156. * configurable: true,
  2157. * enumerable: true,
  2158. * writable: true,
  2159. * value: 1,
  2160. * });
  2161. *
  2162. * `.ownPropertyDescriptor` changes the target of any assertions that follow
  2163. * in the chain to be the value of the property descriptor from the original
  2164. * target object.
  2165. *
  2166. * expect({a: 1}).to.have.ownPropertyDescriptor('a')
  2167. * .that.has.property('enumerable', true);
  2168. *
  2169. * `.ownPropertyDescriptor` accepts an optional `msg` argument which is a
  2170. * custom error message to show when the assertion fails. The message can also
  2171. * be given as the second argument to `expect`. When not providing
  2172. * `descriptor`, only use the second form.
  2173. *
  2174. * // Recommended
  2175. * expect({a: 1}).to.have.ownPropertyDescriptor('a', {
  2176. * configurable: true,
  2177. * enumerable: true,
  2178. * writable: true,
  2179. * value: 2,
  2180. * }, 'nooo why fail??');
  2181. *
  2182. * // Recommended
  2183. * expect({a: 1}, 'nooo why fail??').to.have.ownPropertyDescriptor('a', {
  2184. * configurable: true,
  2185. * enumerable: true,
  2186. * writable: true,
  2187. * value: 2,
  2188. * });
  2189. *
  2190. * // Recommended
  2191. * expect({a: 1}, 'nooo why fail??').to.have.ownPropertyDescriptor('b');
  2192. *
  2193. * // Not recommended
  2194. * expect({a: 1})
  2195. * .to.have.ownPropertyDescriptor('b', undefined, 'nooo why fail??');
  2196. *
  2197. * The above assertion isn't the same thing as not providing `descriptor`.
  2198. * Instead, it's asserting that the target object has a `b` property
  2199. * descriptor that's deeply equal to `undefined`.
  2200. *
  2201. * The alias `.haveOwnPropertyDescriptor` can be used interchangeably with
  2202. * `.ownPropertyDescriptor`.
  2203. *
  2204. * @name ownPropertyDescriptor
  2205. * @alias haveOwnPropertyDescriptor
  2206. * @param {String} name
  2207. * @param {Object} descriptor _optional_
  2208. * @param {String} msg _optional_
  2209. * @namespace BDD
  2210. * @api public
  2211. */
  2212. function assertOwnPropertyDescriptor (name, descriptor, msg) {
  2213. if (typeof descriptor === 'string') {
  2214. msg = descriptor;
  2215. descriptor = null;
  2216. }
  2217. if (msg) flag(this, 'message', msg);
  2218. var obj = flag(this, 'object');
  2219. var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
  2220. if (actualDescriptor && descriptor) {
  2221. this.assert(
  2222. _.eql(descriptor, actualDescriptor)
  2223. , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)
  2224. , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)
  2225. , descriptor
  2226. , actualDescriptor
  2227. , true
  2228. );
  2229. } else {
  2230. this.assert(
  2231. actualDescriptor
  2232. , 'expected #{this} to have an own property descriptor for ' + _.inspect(name)
  2233. , 'expected #{this} to not have an own property descriptor for ' + _.inspect(name)
  2234. );
  2235. }
  2236. flag(this, 'object', actualDescriptor);
  2237. }
  2238. Assertion.addMethod('ownPropertyDescriptor', assertOwnPropertyDescriptor);
  2239. Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
  2240. /**
  2241. * ### .lengthOf(n[, msg])
  2242. *
  2243. * Asserts that the target's `length` or `size` is equal to the given number
  2244. * `n`.
  2245. *
  2246. * expect([1, 2, 3]).to.have.lengthOf(3);
  2247. * expect('foo').to.have.lengthOf(3);
  2248. * expect(new Set([1, 2, 3])).to.have.lengthOf(3);
  2249. * expect(new Map([['a', 1], ['b', 2], ['c', 3]])).to.have.lengthOf(3);
  2250. *
  2251. * Add `.not` earlier in the chain to negate `.lengthOf`. However, it's often
  2252. * best to assert that the target's `length` property is equal to its expected
  2253. * value, rather than not equal to one of many unexpected values.
  2254. *
  2255. * expect('foo').to.have.lengthOf(3); // Recommended
  2256. * expect('foo').to.not.have.lengthOf(4); // Not recommended
  2257. *
  2258. * `.lengthOf` accepts an optional `msg` argument which is a custom error
  2259. * message to show when the assertion fails. The message can also be given as
  2260. * the second argument to `expect`.
  2261. *
  2262. * expect([1, 2, 3]).to.have.lengthOf(2, 'nooo why fail??');
  2263. * expect([1, 2, 3], 'nooo why fail??').to.have.lengthOf(2);
  2264. *
  2265. * `.lengthOf` can also be used as a language chain, causing all `.above`,
  2266. * `.below`, `.least`, `.most`, and `.within` assertions that follow in the
  2267. * chain to use the target's `length` property as the target. However, it's
  2268. * often best to assert that the target's `length` property is equal to its
  2269. * expected length, rather than asserting that its `length` property falls
  2270. * within some range of values.
  2271. *
  2272. * // Recommended
  2273. * expect([1, 2, 3]).to.have.lengthOf(3);
  2274. *
  2275. * // Not recommended
  2276. * expect([1, 2, 3]).to.have.lengthOf.above(2);
  2277. * expect([1, 2, 3]).to.have.lengthOf.below(4);
  2278. * expect([1, 2, 3]).to.have.lengthOf.at.least(3);
  2279. * expect([1, 2, 3]).to.have.lengthOf.at.most(3);
  2280. * expect([1, 2, 3]).to.have.lengthOf.within(2,4);
  2281. *
  2282. * Due to a compatibility issue, the alias `.length` can't be chained directly
  2283. * off of an uninvoked method such as `.a`. Therefore, `.length` can't be used
  2284. * interchangeably with `.lengthOf` in every situation. It's recommended to
  2285. * always use `.lengthOf` instead of `.length`.
  2286. *
  2287. * expect([1, 2, 3]).to.have.a.length(3); // incompatible; throws error
  2288. * expect([1, 2, 3]).to.have.a.lengthOf(3); // passes as expected
  2289. *
  2290. * @name lengthOf
  2291. * @alias length
  2292. * @param {Number} n
  2293. * @param {String} msg _optional_
  2294. * @namespace BDD
  2295. * @api public
  2296. */
  2297. function assertLengthChain () {
  2298. flag(this, 'doLength', true);
  2299. }
  2300. function assertLength (n, msg) {
  2301. if (msg) flag(this, 'message', msg);
  2302. var obj = flag(this, 'object')
  2303. , objType = _.type(obj).toLowerCase()
  2304. , flagMsg = flag(this, 'message')
  2305. , ssfi = flag(this, 'ssfi')
  2306. , descriptor = 'length'
  2307. , itemsCount;
  2308. switch (objType) {
  2309. case 'map':
  2310. case 'set':
  2311. descriptor = 'size';
  2312. itemsCount = obj.size;
  2313. break;
  2314. default:
  2315. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  2316. itemsCount = obj.length;
  2317. }
  2318. this.assert(
  2319. itemsCount == n
  2320. , 'expected #{this} to have a ' + descriptor + ' of #{exp} but got #{act}'
  2321. , 'expected #{this} to not have a ' + descriptor + ' of #{act}'
  2322. , n
  2323. , itemsCount
  2324. );
  2325. }
  2326. Assertion.addChainableMethod('length', assertLength, assertLengthChain);
  2327. Assertion.addChainableMethod('lengthOf', assertLength, assertLengthChain);
  2328. /**
  2329. * ### .match(re[, msg])
  2330. *
  2331. * Asserts that the target matches the given regular expression `re`.
  2332. *
  2333. * expect('foobar').to.match(/^foo/);
  2334. *
  2335. * Add `.not` earlier in the chain to negate `.match`.
  2336. *
  2337. * expect('foobar').to.not.match(/taco/);
  2338. *
  2339. * `.match` accepts an optional `msg` argument which is a custom error message
  2340. * to show when the assertion fails. The message can also be given as the
  2341. * second argument to `expect`.
  2342. *
  2343. * expect('foobar').to.match(/taco/, 'nooo why fail??');
  2344. * expect('foobar', 'nooo why fail??').to.match(/taco/);
  2345. *
  2346. * The alias `.matches` can be used interchangeably with `.match`.
  2347. *
  2348. * @name match
  2349. * @alias matches
  2350. * @param {RegExp} re
  2351. * @param {String} msg _optional_
  2352. * @namespace BDD
  2353. * @api public
  2354. */
  2355. function assertMatch(re, msg) {
  2356. if (msg) flag(this, 'message', msg);
  2357. var obj = flag(this, 'object');
  2358. this.assert(
  2359. re.exec(obj)
  2360. , 'expected #{this} to match ' + re
  2361. , 'expected #{this} not to match ' + re
  2362. );
  2363. }
  2364. Assertion.addMethod('match', assertMatch);
  2365. Assertion.addMethod('matches', assertMatch);
  2366. /**
  2367. * ### .string(str[, msg])
  2368. *
  2369. * Asserts that the target string contains the given substring `str`.
  2370. *
  2371. * expect('foobar').to.have.string('bar');
  2372. *
  2373. * Add `.not` earlier in the chain to negate `.string`.
  2374. *
  2375. * expect('foobar').to.not.have.string('taco');
  2376. *
  2377. * `.string` accepts an optional `msg` argument which is a custom error
  2378. * message to show when the assertion fails. The message can also be given as
  2379. * the second argument to `expect`.
  2380. *
  2381. * expect('foobar').to.have.string('taco', 'nooo why fail??');
  2382. * expect('foobar', 'nooo why fail??').to.have.string('taco');
  2383. *
  2384. * @name string
  2385. * @param {String} str
  2386. * @param {String} msg _optional_
  2387. * @namespace BDD
  2388. * @api public
  2389. */
  2390. Assertion.addMethod('string', function (str, msg) {
  2391. if (msg) flag(this, 'message', msg);
  2392. var obj = flag(this, 'object')
  2393. , flagMsg = flag(this, 'message')
  2394. , ssfi = flag(this, 'ssfi');
  2395. new Assertion(obj, flagMsg, ssfi, true).is.a('string');
  2396. this.assert(
  2397. ~obj.indexOf(str)
  2398. , 'expected #{this} to contain ' + _.inspect(str)
  2399. , 'expected #{this} to not contain ' + _.inspect(str)
  2400. );
  2401. });
  2402. /**
  2403. * ### .keys(key1[, key2[, ...]])
  2404. *
  2405. * Asserts that the target object, array, map, or set has the given keys. Only
  2406. * the target's own inherited properties are included in the search.
  2407. *
  2408. * When the target is an object or array, keys can be provided as one or more
  2409. * string arguments, a single array argument, or a single object argument. In
  2410. * the latter case, only the keys in the given object matter; the values are
  2411. * ignored.
  2412. *
  2413. * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
  2414. * expect(['x', 'y']).to.have.all.keys(0, 1);
  2415. *
  2416. * expect({a: 1, b: 2}).to.have.all.keys(['a', 'b']);
  2417. * expect(['x', 'y']).to.have.all.keys([0, 1]);
  2418. *
  2419. * expect({a: 1, b: 2}).to.have.all.keys({a: 4, b: 5}); // ignore 4 and 5
  2420. * expect(['x', 'y']).to.have.all.keys({0: 4, 1: 5}); // ignore 4 and 5
  2421. *
  2422. * When the target is a map or set, each key must be provided as a separate
  2423. * argument.
  2424. *
  2425. * expect(new Map([['a', 1], ['b', 2]])).to.have.all.keys('a', 'b');
  2426. * expect(new Set(['a', 'b'])).to.have.all.keys('a', 'b');
  2427. *
  2428. * Because `.keys` does different things based on the target's type, it's
  2429. * important to check the target's type before using `.keys`. See the `.a` doc
  2430. * for info on testing a target's type.
  2431. *
  2432. * expect({a: 1, b: 2}).to.be.an('object').that.has.all.keys('a', 'b');
  2433. *
  2434. * By default, strict (`===`) equality is used to compare keys of maps and
  2435. * sets. Add `.deep` earlier in the chain to use deep equality instead. See
  2436. * the `deep-eql` project page for info on the deep equality algorithm:
  2437. * https://github.com/chaijs/deep-eql.
  2438. *
  2439. * // Target set deeply (but not strictly) has key `{a: 1}`
  2440. * expect(new Set([{a: 1}])).to.have.all.deep.keys([{a: 1}]);
  2441. * expect(new Set([{a: 1}])).to.not.have.all.keys([{a: 1}]);
  2442. *
  2443. * By default, the target must have all of the given keys and no more. Add
  2444. * `.any` earlier in the chain to only require that the target have at least
  2445. * one of the given keys. Also, add `.not` earlier in the chain to negate
  2446. * `.keys`. It's often best to add `.any` when negating `.keys`, and to use
  2447. * `.all` when asserting `.keys` without negation.
  2448. *
  2449. * When negating `.keys`, `.any` is preferred because `.not.any.keys` asserts
  2450. * exactly what's expected of the output, whereas `.not.all.keys` creates
  2451. * uncertain expectations.
  2452. *
  2453. * // Recommended; asserts that target doesn't have any of the given keys
  2454. * expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');
  2455. *
  2456. * // Not recommended; asserts that target doesn't have all of the given
  2457. * // keys but may or may not have some of them
  2458. * expect({a: 1, b: 2}).to.not.have.all.keys('c', 'd');
  2459. *
  2460. * When asserting `.keys` without negation, `.all` is preferred because
  2461. * `.all.keys` asserts exactly what's expected of the output, whereas
  2462. * `.any.keys` creates uncertain expectations.
  2463. *
  2464. * // Recommended; asserts that target has all the given keys
  2465. * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
  2466. *
  2467. * // Not recommended; asserts that target has at least one of the given
  2468. * // keys but may or may not have more of them
  2469. * expect({a: 1, b: 2}).to.have.any.keys('a', 'b');
  2470. *
  2471. * Note that `.all` is used by default when neither `.all` nor `.any` appear
  2472. * earlier in the chain. However, it's often best to add `.all` anyway because
  2473. * it improves readability.
  2474. *
  2475. * // Both assertions are identical
  2476. * expect({a: 1, b: 2}).to.have.all.keys('a', 'b'); // Recommended
  2477. * expect({a: 1, b: 2}).to.have.keys('a', 'b'); // Not recommended
  2478. *
  2479. * Add `.include` earlier in the chain to require that the target's keys be a
  2480. * superset of the expected keys, rather than identical sets.
  2481. *
  2482. * // Target object's keys are a superset of ['a', 'b'] but not identical
  2483. * expect({a: 1, b: 2, c: 3}).to.include.all.keys('a', 'b');
  2484. * expect({a: 1, b: 2, c: 3}).to.not.have.all.keys('a', 'b');
  2485. *
  2486. * However, if `.any` and `.include` are combined, only the `.any` takes
  2487. * effect. The `.include` is ignored in this case.
  2488. *
  2489. * // Both assertions are identical
  2490. * expect({a: 1}).to.have.any.keys('a', 'b');
  2491. * expect({a: 1}).to.include.any.keys('a', 'b');
  2492. *
  2493. * A custom error message can be given as the second argument to `expect`.
  2494. *
  2495. * expect({a: 1}, 'nooo why fail??').to.have.key('b');
  2496. *
  2497. * The alias `.key` can be used interchangeably with `.keys`.
  2498. *
  2499. * @name keys
  2500. * @alias key
  2501. * @param {...String|Array|Object} keys
  2502. * @namespace BDD
  2503. * @api public
  2504. */
  2505. function assertKeys (keys) {
  2506. var obj = flag(this, 'object')
  2507. , objType = _.type(obj)
  2508. , keysType = _.type(keys)
  2509. , ssfi = flag(this, 'ssfi')
  2510. , isDeep = flag(this, 'deep')
  2511. , str
  2512. , deepStr = ''
  2513. , actual
  2514. , ok = true
  2515. , flagMsg = flag(this, 'message');
  2516. flagMsg = flagMsg ? flagMsg + ': ' : '';
  2517. var mixedArgsMsg = flagMsg + 'when testing keys against an object or an array you must give a single Array|Object|String argument or multiple String arguments';
  2518. if (objType === 'Map' || objType === 'Set') {
  2519. deepStr = isDeep ? 'deeply ' : '';
  2520. actual = [];
  2521. // Map and Set '.keys' aren't supported in IE 11. Therefore, use .forEach.
  2522. obj.forEach(function (val, key) { actual.push(key) });
  2523. if (keysType !== 'Array') {
  2524. keys = Array.prototype.slice.call(arguments);
  2525. }
  2526. } else {
  2527. actual = _.getOwnEnumerableProperties(obj);
  2528. switch (keysType) {
  2529. case 'Array':
  2530. if (arguments.length > 1) {
  2531. throw new AssertionError(mixedArgsMsg, undefined, ssfi);
  2532. }
  2533. break;
  2534. case 'Object':
  2535. if (arguments.length > 1) {
  2536. throw new AssertionError(mixedArgsMsg, undefined, ssfi);
  2537. }
  2538. keys = Object.keys(keys);
  2539. break;
  2540. default:
  2541. keys = Array.prototype.slice.call(arguments);
  2542. }
  2543. // Only stringify non-Symbols because Symbols would become "Symbol()"
  2544. keys = keys.map(function (val) {
  2545. return typeof val === 'symbol' ? val : String(val);
  2546. });
  2547. }
  2548. if (!keys.length) {
  2549. throw new AssertionError(flagMsg + 'keys required', undefined, ssfi);
  2550. }
  2551. var len = keys.length
  2552. , any = flag(this, 'any')
  2553. , all = flag(this, 'all')
  2554. , expected = keys;
  2555. if (!any && !all) {
  2556. all = true;
  2557. }
  2558. // Has any
  2559. if (any) {
  2560. ok = expected.some(function(expectedKey) {
  2561. return actual.some(function(actualKey) {
  2562. if (isDeep) {
  2563. return _.eql(expectedKey, actualKey);
  2564. } else {
  2565. return expectedKey === actualKey;
  2566. }
  2567. });
  2568. });
  2569. }
  2570. // Has all
  2571. if (all) {
  2572. ok = expected.every(function(expectedKey) {
  2573. return actual.some(function(actualKey) {
  2574. if (isDeep) {
  2575. return _.eql(expectedKey, actualKey);
  2576. } else {
  2577. return expectedKey === actualKey;
  2578. }
  2579. });
  2580. });
  2581. if (!flag(this, 'contains')) {
  2582. ok = ok && keys.length == actual.length;
  2583. }
  2584. }
  2585. // Key string
  2586. if (len > 1) {
  2587. keys = keys.map(function(key) {
  2588. return _.inspect(key);
  2589. });
  2590. var last = keys.pop();
  2591. if (all) {
  2592. str = keys.join(', ') + ', and ' + last;
  2593. }
  2594. if (any) {
  2595. str = keys.join(', ') + ', or ' + last;
  2596. }
  2597. } else {
  2598. str = _.inspect(keys[0]);
  2599. }
  2600. // Form
  2601. str = (len > 1 ? 'keys ' : 'key ') + str;
  2602. // Have / include
  2603. str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
  2604. // Assertion
  2605. this.assert(
  2606. ok
  2607. , 'expected #{this} to ' + deepStr + str
  2608. , 'expected #{this} to not ' + deepStr + str
  2609. , expected.slice(0).sort(_.compareByInspect)
  2610. , actual.sort(_.compareByInspect)
  2611. , true
  2612. );
  2613. }
  2614. Assertion.addMethod('keys', assertKeys);
  2615. Assertion.addMethod('key', assertKeys);
  2616. /**
  2617. * ### .throw([errorLike], [errMsgMatcher], [msg])
  2618. *
  2619. * When no arguments are provided, `.throw` invokes the target function and
  2620. * asserts that an error is thrown.
  2621. *
  2622. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2623. *
  2624. * expect(badFn).to.throw();
  2625. *
  2626. * When one argument is provided, and it's an error constructor, `.throw`
  2627. * invokes the target function and asserts that an error is thrown that's an
  2628. * instance of that error constructor.
  2629. *
  2630. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2631. *
  2632. * expect(badFn).to.throw(TypeError);
  2633. *
  2634. * When one argument is provided, and it's an error instance, `.throw` invokes
  2635. * the target function and asserts that an error is thrown that's strictly
  2636. * (`===`) equal to that error instance.
  2637. *
  2638. * var err = new TypeError('Illegal salmon!');
  2639. * var badFn = function () { throw err; };
  2640. *
  2641. * expect(badFn).to.throw(err);
  2642. *
  2643. * When one argument is provided, and it's a string, `.throw` invokes the
  2644. * target function and asserts that an error is thrown with a message that
  2645. * contains that string.
  2646. *
  2647. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2648. *
  2649. * expect(badFn).to.throw('salmon');
  2650. *
  2651. * When one argument is provided, and it's a regular expression, `.throw`
  2652. * invokes the target function and asserts that an error is thrown with a
  2653. * message that matches that regular expression.
  2654. *
  2655. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2656. *
  2657. * expect(badFn).to.throw(/salmon/);
  2658. *
  2659. * When two arguments are provided, and the first is an error instance or
  2660. * constructor, and the second is a string or regular expression, `.throw`
  2661. * invokes the function and asserts that an error is thrown that fulfills both
  2662. * conditions as described above.
  2663. *
  2664. * var err = new TypeError('Illegal salmon!');
  2665. * var badFn = function () { throw err; };
  2666. *
  2667. * expect(badFn).to.throw(TypeError, 'salmon');
  2668. * expect(badFn).to.throw(TypeError, /salmon/);
  2669. * expect(badFn).to.throw(err, 'salmon');
  2670. * expect(badFn).to.throw(err, /salmon/);
  2671. *
  2672. * Add `.not` earlier in the chain to negate `.throw`.
  2673. *
  2674. * var goodFn = function () {};
  2675. *
  2676. * expect(goodFn).to.not.throw();
  2677. *
  2678. * However, it's dangerous to negate `.throw` when providing any arguments.
  2679. * The problem is that it creates uncertain expectations by asserting that the
  2680. * target either doesn't throw an error, or that it throws an error but of a
  2681. * different type than the given type, or that it throws an error of the given
  2682. * type but with a message that doesn't include the given string. It's often
  2683. * best to identify the exact output that's expected, and then write an
  2684. * assertion that only accepts that exact output.
  2685. *
  2686. * When the target isn't expected to throw an error, it's often best to assert
  2687. * exactly that.
  2688. *
  2689. * var goodFn = function () {};
  2690. *
  2691. * expect(goodFn).to.not.throw(); // Recommended
  2692. * expect(goodFn).to.not.throw(ReferenceError, 'x'); // Not recommended
  2693. *
  2694. * When the target is expected to throw an error, it's often best to assert
  2695. * that the error is of its expected type, and has a message that includes an
  2696. * expected string, rather than asserting that it doesn't have one of many
  2697. * unexpected types, and doesn't have a message that includes some string.
  2698. *
  2699. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2700. *
  2701. * expect(badFn).to.throw(TypeError, 'salmon'); // Recommended
  2702. * expect(badFn).to.not.throw(ReferenceError, 'x'); // Not recommended
  2703. *
  2704. * `.throw` changes the target of any assertions that follow in the chain to
  2705. * be the error object that's thrown.
  2706. *
  2707. * var err = new TypeError('Illegal salmon!');
  2708. * err.code = 42;
  2709. * var badFn = function () { throw err; };
  2710. *
  2711. * expect(badFn).to.throw(TypeError).with.property('code', 42);
  2712. *
  2713. * `.throw` accepts an optional `msg` argument which is a custom error message
  2714. * to show when the assertion fails. The message can also be given as the
  2715. * second argument to `expect`. When not providing two arguments, always use
  2716. * the second form.
  2717. *
  2718. * var goodFn = function () {};
  2719. *
  2720. * expect(goodFn).to.throw(TypeError, 'x', 'nooo why fail??');
  2721. * expect(goodFn, 'nooo why fail??').to.throw();
  2722. *
  2723. * Due to limitations in ES5, `.throw` may not always work as expected when
  2724. * using a transpiler such as Babel or TypeScript. In particular, it may
  2725. * produce unexpected results when subclassing the built-in `Error` object and
  2726. * then passing the subclassed constructor to `.throw`. See your transpiler's
  2727. * docs for details:
  2728. *
  2729. * - ([Babel](https://babeljs.io/docs/usage/caveats/#classes))
  2730. * - ([TypeScript](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work))
  2731. *
  2732. * Beware of some common mistakes when using the `throw` assertion. One common
  2733. * mistake is to accidentally invoke the function yourself instead of letting
  2734. * the `throw` assertion invoke the function for you. For example, when
  2735. * testing if a function named `fn` throws, provide `fn` instead of `fn()` as
  2736. * the target for the assertion.
  2737. *
  2738. * expect(fn).to.throw(); // Good! Tests `fn` as desired
  2739. * expect(fn()).to.throw(); // Bad! Tests result of `fn()`, not `fn`
  2740. *
  2741. * If you need to assert that your function `fn` throws when passed certain
  2742. * arguments, then wrap a call to `fn` inside of another function.
  2743. *
  2744. * expect(function () { fn(42); }).to.throw(); // Function expression
  2745. * expect(() => fn(42)).to.throw(); // ES6 arrow function
  2746. *
  2747. * Another common mistake is to provide an object method (or any stand-alone
  2748. * function that relies on `this`) as the target of the assertion. Doing so is
  2749. * problematic because the `this` context will be lost when the function is
  2750. * invoked by `.throw`; there's no way for it to know what `this` is supposed
  2751. * to be. There are two ways around this problem. One solution is to wrap the
  2752. * method or function call inside of another function. Another solution is to
  2753. * use `bind`.
  2754. *
  2755. * expect(function () { cat.meow(); }).to.throw(); // Function expression
  2756. * expect(() => cat.meow()).to.throw(); // ES6 arrow function
  2757. * expect(cat.meow.bind(cat)).to.throw(); // Bind
  2758. *
  2759. * Finally, it's worth mentioning that it's a best practice in JavaScript to
  2760. * only throw `Error` and derivatives of `Error` such as `ReferenceError`,
  2761. * `TypeError`, and user-defined objects that extend `Error`. No other type of
  2762. * value will generate a stack trace when initialized. With that said, the
  2763. * `throw` assertion does technically support any type of value being thrown,
  2764. * not just `Error` and its derivatives.
  2765. *
  2766. * The aliases `.throws` and `.Throw` can be used interchangeably with
  2767. * `.throw`.
  2768. *
  2769. * @name throw
  2770. * @alias throws
  2771. * @alias Throw
  2772. * @param {Error|ErrorConstructor} errorLike
  2773. * @param {String|RegExp} errMsgMatcher error message
  2774. * @param {String} msg _optional_
  2775. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  2776. * @returns error for chaining (null if no error)
  2777. * @namespace BDD
  2778. * @api public
  2779. */
  2780. function assertThrows (errorLike, errMsgMatcher, msg) {
  2781. if (msg) flag(this, 'message', msg);
  2782. var obj = flag(this, 'object')
  2783. , ssfi = flag(this, 'ssfi')
  2784. , flagMsg = flag(this, 'message')
  2785. , negate = flag(this, 'negate') || false;
  2786. new Assertion(obj, flagMsg, ssfi, true).is.a('function');
  2787. if (errorLike instanceof RegExp || typeof errorLike === 'string') {
  2788. errMsgMatcher = errorLike;
  2789. errorLike = null;
  2790. }
  2791. var caughtErr;
  2792. try {
  2793. obj();
  2794. } catch (err) {
  2795. caughtErr = err;
  2796. }
  2797. // If we have the negate flag enabled and at least one valid argument it means we do expect an error
  2798. // but we want it to match a given set of criteria
  2799. var everyArgIsUndefined = errorLike === undefined && errMsgMatcher === undefined;
  2800. // If we've got the negate flag enabled and both args, we should only fail if both aren't compatible
  2801. // See Issue #551 and PR #683@GitHub
  2802. var everyArgIsDefined = Boolean(errorLike && errMsgMatcher);
  2803. var errorLikeFail = false;
  2804. var errMsgMatcherFail = false;
  2805. // Checking if error was thrown
  2806. if (everyArgIsUndefined || !everyArgIsUndefined && !negate) {
  2807. // We need this to display results correctly according to their types
  2808. var errorLikeString = 'an error';
  2809. if (errorLike instanceof Error) {
  2810. errorLikeString = '#{exp}';
  2811. } else if (errorLike) {
  2812. errorLikeString = _.checkError.getConstructorName(errorLike);
  2813. }
  2814. this.assert(
  2815. caughtErr
  2816. , 'expected #{this} to throw ' + errorLikeString
  2817. , 'expected #{this} to not throw an error but #{act} was thrown'
  2818. , errorLike && errorLike.toString()
  2819. , (caughtErr instanceof Error ?
  2820. caughtErr.toString() : (typeof caughtErr === 'string' ? caughtErr : caughtErr &&
  2821. _.checkError.getConstructorName(caughtErr)))
  2822. );
  2823. }
  2824. if (errorLike && caughtErr) {
  2825. // We should compare instances only if `errorLike` is an instance of `Error`
  2826. if (errorLike instanceof Error) {
  2827. var isCompatibleInstance = _.checkError.compatibleInstance(caughtErr, errorLike);
  2828. if (isCompatibleInstance === negate) {
  2829. // These checks were created to ensure we won't fail too soon when we've got both args and a negate
  2830. // See Issue #551 and PR #683@GitHub
  2831. if (everyArgIsDefined && negate) {
  2832. errorLikeFail = true;
  2833. } else {
  2834. this.assert(
  2835. negate
  2836. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  2837. , 'expected #{this} to not throw #{exp}' + (caughtErr && !negate ? ' but #{act} was thrown' : '')
  2838. , errorLike.toString()
  2839. , caughtErr.toString()
  2840. );
  2841. }
  2842. }
  2843. }
  2844. var isCompatibleConstructor = _.checkError.compatibleConstructor(caughtErr, errorLike);
  2845. if (isCompatibleConstructor === negate) {
  2846. if (everyArgIsDefined && negate) {
  2847. errorLikeFail = true;
  2848. } else {
  2849. this.assert(
  2850. negate
  2851. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  2852. , 'expected #{this} to not throw #{exp}' + (caughtErr ? ' but #{act} was thrown' : '')
  2853. , (errorLike instanceof Error ? errorLike.toString() : errorLike && _.checkError.getConstructorName(errorLike))
  2854. , (caughtErr instanceof Error ? caughtErr.toString() : caughtErr && _.checkError.getConstructorName(caughtErr))
  2855. );
  2856. }
  2857. }
  2858. }
  2859. if (caughtErr && errMsgMatcher !== undefined && errMsgMatcher !== null) {
  2860. // Here we check compatible messages
  2861. var placeholder = 'including';
  2862. if (errMsgMatcher instanceof RegExp) {
  2863. placeholder = 'matching'
  2864. }
  2865. var isCompatibleMessage = _.checkError.compatibleMessage(caughtErr, errMsgMatcher);
  2866. if (isCompatibleMessage === negate) {
  2867. if (everyArgIsDefined && negate) {
  2868. errMsgMatcherFail = true;
  2869. } else {
  2870. this.assert(
  2871. negate
  2872. , 'expected #{this} to throw error ' + placeholder + ' #{exp} but got #{act}'
  2873. , 'expected #{this} to throw error not ' + placeholder + ' #{exp}'
  2874. , errMsgMatcher
  2875. , _.checkError.getMessage(caughtErr)
  2876. );
  2877. }
  2878. }
  2879. }
  2880. // If both assertions failed and both should've matched we throw an error
  2881. if (errorLikeFail && errMsgMatcherFail) {
  2882. this.assert(
  2883. negate
  2884. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  2885. , 'expected #{this} to not throw #{exp}' + (caughtErr ? ' but #{act} was thrown' : '')
  2886. , (errorLike instanceof Error ? errorLike.toString() : errorLike && _.checkError.getConstructorName(errorLike))
  2887. , (caughtErr instanceof Error ? caughtErr.toString() : caughtErr && _.checkError.getConstructorName(caughtErr))
  2888. );
  2889. }
  2890. flag(this, 'object', caughtErr);
  2891. };
  2892. Assertion.addMethod('throw', assertThrows);
  2893. Assertion.addMethod('throws', assertThrows);
  2894. Assertion.addMethod('Throw', assertThrows);
  2895. /**
  2896. * ### .respondTo(method[, msg])
  2897. *
  2898. * When the target is a non-function object, `.respondTo` asserts that the
  2899. * target has a method with the given name `method`. The method can be own or
  2900. * inherited, and it can be enumerable or non-enumerable.
  2901. *
  2902. * function Cat () {}
  2903. * Cat.prototype.meow = function () {};
  2904. *
  2905. * expect(new Cat()).to.respondTo('meow');
  2906. *
  2907. * When the target is a function, `.respondTo` asserts that the target's
  2908. * `prototype` property has a method with the given name `method`. Again, the
  2909. * method can be own or inherited, and it can be enumerable or non-enumerable.
  2910. *
  2911. * function Cat () {}
  2912. * Cat.prototype.meow = function () {};
  2913. *
  2914. * expect(Cat).to.respondTo('meow');
  2915. *
  2916. * Add `.itself` earlier in the chain to force `.respondTo` to treat the
  2917. * target as a non-function object, even if it's a function. Thus, it asserts
  2918. * that the target has a method with the given name `method`, rather than
  2919. * asserting that the target's `prototype` property has a method with the
  2920. * given name `method`.
  2921. *
  2922. * function Cat () {}
  2923. * Cat.prototype.meow = function () {};
  2924. * Cat.hiss = function () {};
  2925. *
  2926. * expect(Cat).itself.to.respondTo('hiss').but.not.respondTo('meow');
  2927. *
  2928. * When not adding `.itself`, it's important to check the target's type before
  2929. * using `.respondTo`. See the `.a` doc for info on checking a target's type.
  2930. *
  2931. * function Cat () {}
  2932. * Cat.prototype.meow = function () {};
  2933. *
  2934. * expect(new Cat()).to.be.an('object').that.respondsTo('meow');
  2935. *
  2936. * Add `.not` earlier in the chain to negate `.respondTo`.
  2937. *
  2938. * function Dog () {}
  2939. * Dog.prototype.bark = function () {};
  2940. *
  2941. * expect(new Dog()).to.not.respondTo('meow');
  2942. *
  2943. * `.respondTo` accepts an optional `msg` argument which is a custom error
  2944. * message to show when the assertion fails. The message can also be given as
  2945. * the second argument to `expect`.
  2946. *
  2947. * expect({}).to.respondTo('meow', 'nooo why fail??');
  2948. * expect({}, 'nooo why fail??').to.respondTo('meow');
  2949. *
  2950. * The alias `.respondsTo` can be used interchangeably with `.respondTo`.
  2951. *
  2952. * @name respondTo
  2953. * @alias respondsTo
  2954. * @param {String} method
  2955. * @param {String} msg _optional_
  2956. * @namespace BDD
  2957. * @api public
  2958. */
  2959. function respondTo (method, msg) {
  2960. if (msg) flag(this, 'message', msg);
  2961. var obj = flag(this, 'object')
  2962. , itself = flag(this, 'itself')
  2963. , context = ('function' === typeof obj && !itself)
  2964. ? obj.prototype[method]
  2965. : obj[method];
  2966. this.assert(
  2967. 'function' === typeof context
  2968. , 'expected #{this} to respond to ' + _.inspect(method)
  2969. , 'expected #{this} to not respond to ' + _.inspect(method)
  2970. );
  2971. }
  2972. Assertion.addMethod('respondTo', respondTo);
  2973. Assertion.addMethod('respondsTo', respondTo);
  2974. /**
  2975. * ### .itself
  2976. *
  2977. * Forces all `.respondTo` assertions that follow in the chain to behave as if
  2978. * the target is a non-function object, even if it's a function. Thus, it
  2979. * causes `.respondTo` to assert that the target has a method with the given
  2980. * name, rather than asserting that the target's `prototype` property has a
  2981. * method with the given name.
  2982. *
  2983. * function Cat () {}
  2984. * Cat.prototype.meow = function () {};
  2985. * Cat.hiss = function () {};
  2986. *
  2987. * expect(Cat).itself.to.respondTo('hiss').but.not.respondTo('meow');
  2988. *
  2989. * @name itself
  2990. * @namespace BDD
  2991. * @api public
  2992. */
  2993. Assertion.addProperty('itself', function () {
  2994. flag(this, 'itself', true);
  2995. });
  2996. /**
  2997. * ### .satisfy(matcher[, msg])
  2998. *
  2999. * Invokes the given `matcher` function with the target being passed as the
  3000. * first argument, and asserts that the value returned is truthy.
  3001. *
  3002. * expect(1).to.satisfy(function(num) {
  3003. * return num > 0;
  3004. * });
  3005. *
  3006. * Add `.not` earlier in the chain to negate `.satisfy`.
  3007. *
  3008. * expect(1).to.not.satisfy(function(num) {
  3009. * return num > 2;
  3010. * });
  3011. *
  3012. * `.satisfy` accepts an optional `msg` argument which is a custom error
  3013. * message to show when the assertion fails. The message can also be given as
  3014. * the second argument to `expect`.
  3015. *
  3016. * expect(1).to.satisfy(function(num) {
  3017. * return num > 2;
  3018. * }, 'nooo why fail??');
  3019. *
  3020. * expect(1, 'nooo why fail??').to.satisfy(function(num) {
  3021. * return num > 2;
  3022. * });
  3023. *
  3024. * The alias `.satisfies` can be used interchangeably with `.satisfy`.
  3025. *
  3026. * @name satisfy
  3027. * @alias satisfies
  3028. * @param {Function} matcher
  3029. * @param {String} msg _optional_
  3030. * @namespace BDD
  3031. * @api public
  3032. */
  3033. function satisfy (matcher, msg) {
  3034. if (msg) flag(this, 'message', msg);
  3035. var obj = flag(this, 'object');
  3036. var result = matcher(obj);
  3037. this.assert(
  3038. result
  3039. , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
  3040. , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
  3041. , flag(this, 'negate') ? false : true
  3042. , result
  3043. );
  3044. }
  3045. Assertion.addMethod('satisfy', satisfy);
  3046. Assertion.addMethod('satisfies', satisfy);
  3047. /**
  3048. * ### .closeTo(expected, delta[, msg])
  3049. *
  3050. * Asserts that the target is a number that's within a given +/- `delta` range
  3051. * of the given number `expected`. However, it's often best to assert that the
  3052. * target is equal to its expected value.
  3053. *
  3054. * // Recommended
  3055. * expect(1.5).to.equal(1.5);
  3056. *
  3057. * // Not recommended
  3058. * expect(1.5).to.be.closeTo(1, 0.5);
  3059. * expect(1.5).to.be.closeTo(2, 0.5);
  3060. * expect(1.5).to.be.closeTo(1, 1);
  3061. *
  3062. * Add `.not` earlier in the chain to negate `.closeTo`.
  3063. *
  3064. * expect(1.5).to.equal(1.5); // Recommended
  3065. * expect(1.5).to.not.be.closeTo(3, 1); // Not recommended
  3066. *
  3067. * `.closeTo` accepts an optional `msg` argument which is a custom error
  3068. * message to show when the assertion fails. The message can also be given as
  3069. * the second argument to `expect`.
  3070. *
  3071. * expect(1.5).to.be.closeTo(3, 1, 'nooo why fail??');
  3072. * expect(1.5, 'nooo why fail??').to.be.closeTo(3, 1);
  3073. *
  3074. * The alias `.approximately` can be used interchangeably with `.closeTo`.
  3075. *
  3076. * @name closeTo
  3077. * @alias approximately
  3078. * @param {Number} expected
  3079. * @param {Number} delta
  3080. * @param {String} msg _optional_
  3081. * @namespace BDD
  3082. * @api public
  3083. */
  3084. function closeTo(expected, delta, msg) {
  3085. if (msg) flag(this, 'message', msg);
  3086. var obj = flag(this, 'object')
  3087. , flagMsg = flag(this, 'message')
  3088. , ssfi = flag(this, 'ssfi');
  3089. new Assertion(obj, flagMsg, ssfi, true).is.a('number');
  3090. if (typeof expected !== 'number' || typeof delta !== 'number') {
  3091. flagMsg = flagMsg ? flagMsg + ': ' : '';
  3092. var deltaMessage = delta === undefined ? ", and a delta is required" : "";
  3093. throw new AssertionError(
  3094. flagMsg + 'the arguments to closeTo or approximately must be numbers' + deltaMessage,
  3095. undefined,
  3096. ssfi
  3097. );
  3098. }
  3099. this.assert(
  3100. Math.abs(obj - expected) <= delta
  3101. , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
  3102. , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
  3103. );
  3104. }
  3105. Assertion.addMethod('closeTo', closeTo);
  3106. Assertion.addMethod('approximately', closeTo);
  3107. // Note: Duplicates are ignored if testing for inclusion instead of sameness.
  3108. function isSubsetOf(subset, superset, cmp, contains, ordered) {
  3109. if (!contains) {
  3110. if (subset.length !== superset.length) return false;
  3111. superset = superset.slice();
  3112. }
  3113. return subset.every(function(elem, idx) {
  3114. if (ordered) return cmp ? cmp(elem, superset[idx]) : elem === superset[idx];
  3115. if (!cmp) {
  3116. var matchIdx = superset.indexOf(elem);
  3117. if (matchIdx === -1) return false;
  3118. // Remove match from superset so not counted twice if duplicate in subset.
  3119. if (!contains) superset.splice(matchIdx, 1);
  3120. return true;
  3121. }
  3122. return superset.some(function(elem2, matchIdx) {
  3123. if (!cmp(elem, elem2)) return false;
  3124. // Remove match from superset so not counted twice if duplicate in subset.
  3125. if (!contains) superset.splice(matchIdx, 1);
  3126. return true;
  3127. });
  3128. });
  3129. }
  3130. /**
  3131. * ### .members(set[, msg])
  3132. *
  3133. * Asserts that the target array has the same members as the given array
  3134. * `set`.
  3135. *
  3136. * expect([1, 2, 3]).to.have.members([2, 1, 3]);
  3137. * expect([1, 2, 2]).to.have.members([2, 1, 2]);
  3138. *
  3139. * By default, members are compared using strict (`===`) equality. Add `.deep`
  3140. * earlier in the chain to use deep equality instead. See the `deep-eql`
  3141. * project page for info on the deep equality algorithm:
  3142. * https://github.com/chaijs/deep-eql.
  3143. *
  3144. * // Target array deeply (but not strictly) has member `{a: 1}`
  3145. * expect([{a: 1}]).to.have.deep.members([{a: 1}]);
  3146. * expect([{a: 1}]).to.not.have.members([{a: 1}]);
  3147. *
  3148. * By default, order doesn't matter. Add `.ordered` earlier in the chain to
  3149. * require that members appear in the same order.
  3150. *
  3151. * expect([1, 2, 3]).to.have.ordered.members([1, 2, 3]);
  3152. * expect([1, 2, 3]).to.have.members([2, 1, 3])
  3153. * .but.not.ordered.members([2, 1, 3]);
  3154. *
  3155. * By default, both arrays must be the same size. Add `.include` earlier in
  3156. * the chain to require that the target's members be a superset of the
  3157. * expected members. Note that duplicates are ignored in the subset when
  3158. * `.include` is added.
  3159. *
  3160. * // Target array is a superset of [1, 2] but not identical
  3161. * expect([1, 2, 3]).to.include.members([1, 2]);
  3162. * expect([1, 2, 3]).to.not.have.members([1, 2]);
  3163. *
  3164. * // Duplicates in the subset are ignored
  3165. * expect([1, 2, 3]).to.include.members([1, 2, 2, 2]);
  3166. *
  3167. * `.deep`, `.ordered`, and `.include` can all be combined. However, if
  3168. * `.include` and `.ordered` are combined, the ordering begins at the start of
  3169. * both arrays.
  3170. *
  3171. * expect([{a: 1}, {b: 2}, {c: 3}])
  3172. * .to.include.deep.ordered.members([{a: 1}, {b: 2}])
  3173. * .but.not.include.deep.ordered.members([{b: 2}, {c: 3}]);
  3174. *
  3175. * Add `.not` earlier in the chain to negate `.members`. However, it's
  3176. * dangerous to do so. The problem is that it creates uncertain expectations
  3177. * by asserting that the target array doesn't have all of the same members as
  3178. * the given array `set` but may or may not have some of them. It's often best
  3179. * to identify the exact output that's expected, and then write an assertion
  3180. * that only accepts that exact output.
  3181. *
  3182. * expect([1, 2]).to.not.include(3).and.not.include(4); // Recommended
  3183. * expect([1, 2]).to.not.have.members([3, 4]); // Not recommended
  3184. *
  3185. * `.members` accepts an optional `msg` argument which is a custom error
  3186. * message to show when the assertion fails. The message can also be given as
  3187. * the second argument to `expect`.
  3188. *
  3189. * expect([1, 2]).to.have.members([1, 2, 3], 'nooo why fail??');
  3190. * expect([1, 2], 'nooo why fail??').to.have.members([1, 2, 3]);
  3191. *
  3192. * @name members
  3193. * @param {Array} set
  3194. * @param {String} msg _optional_
  3195. * @namespace BDD
  3196. * @api public
  3197. */
  3198. Assertion.addMethod('members', function (subset, msg) {
  3199. if (msg) flag(this, 'message', msg);
  3200. var obj = flag(this, 'object')
  3201. , flagMsg = flag(this, 'message')
  3202. , ssfi = flag(this, 'ssfi');
  3203. new Assertion(obj, flagMsg, ssfi, true).to.be.an('array');
  3204. new Assertion(subset, flagMsg, ssfi, true).to.be.an('array');
  3205. var contains = flag(this, 'contains');
  3206. var ordered = flag(this, 'ordered');
  3207. var subject, failMsg, failNegateMsg;
  3208. if (contains) {
  3209. subject = ordered ? 'an ordered superset' : 'a superset';
  3210. failMsg = 'expected #{this} to be ' + subject + ' of #{exp}';
  3211. failNegateMsg = 'expected #{this} to not be ' + subject + ' of #{exp}';
  3212. } else {
  3213. subject = ordered ? 'ordered members' : 'members';
  3214. failMsg = 'expected #{this} to have the same ' + subject + ' as #{exp}';
  3215. failNegateMsg = 'expected #{this} to not have the same ' + subject + ' as #{exp}';
  3216. }
  3217. var cmp = flag(this, 'deep') ? _.eql : undefined;
  3218. this.assert(
  3219. isSubsetOf(subset, obj, cmp, contains, ordered)
  3220. , failMsg
  3221. , failNegateMsg
  3222. , subset
  3223. , obj
  3224. , true
  3225. );
  3226. });
  3227. /**
  3228. * ### .oneOf(list[, msg])
  3229. *
  3230. * Asserts that the target is a member of the given array `list`. However,
  3231. * it's often best to assert that the target is equal to its expected value.
  3232. *
  3233. * expect(1).to.equal(1); // Recommended
  3234. * expect(1).to.be.oneOf([1, 2, 3]); // Not recommended
  3235. *
  3236. * Comparisons are performed using strict (`===`) equality.
  3237. *
  3238. * Add `.not` earlier in the chain to negate `.oneOf`.
  3239. *
  3240. * expect(1).to.equal(1); // Recommended
  3241. * expect(1).to.not.be.oneOf([2, 3, 4]); // Not recommended
  3242. *
  3243. * It can also be chained with `.contain` or `.include`, which will work with
  3244. * both arrays and strings:
  3245. *
  3246. * expect('Today is sunny').to.contain.oneOf(['sunny', 'cloudy'])
  3247. * expect('Today is rainy').to.not.contain.oneOf(['sunny', 'cloudy'])
  3248. * expect([1,2,3]).to.contain.oneOf([3,4,5])
  3249. * expect([1,2,3]).to.not.contain.oneOf([4,5,6])
  3250. *
  3251. * `.oneOf` accepts an optional `msg` argument which is a custom error message
  3252. * to show when the assertion fails. The message can also be given as the
  3253. * second argument to `expect`.
  3254. *
  3255. * expect(1).to.be.oneOf([2, 3, 4], 'nooo why fail??');
  3256. * expect(1, 'nooo why fail??').to.be.oneOf([2, 3, 4]);
  3257. *
  3258. * @name oneOf
  3259. * @param {Array<*>} list
  3260. * @param {String} msg _optional_
  3261. * @namespace BDD
  3262. * @api public
  3263. */
  3264. function oneOf (list, msg) {
  3265. if (msg) flag(this, 'message', msg);
  3266. var expected = flag(this, 'object')
  3267. , flagMsg = flag(this, 'message')
  3268. , ssfi = flag(this, 'ssfi')
  3269. , contains = flag(this, 'contains')
  3270. , isDeep = flag(this, 'deep');
  3271. new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
  3272. if (contains) {
  3273. this.assert(
  3274. list.some(function(possibility) { return expected.indexOf(possibility) > -1 })
  3275. , 'expected #{this} to contain one of #{exp}'
  3276. , 'expected #{this} to not contain one of #{exp}'
  3277. , list
  3278. , expected
  3279. );
  3280. } else {
  3281. if (isDeep) {
  3282. this.assert(
  3283. list.some(function(possibility) { return _.eql(expected, possibility) })
  3284. , 'expected #{this} to deeply equal one of #{exp}'
  3285. , 'expected #{this} to deeply equal one of #{exp}'
  3286. , list
  3287. , expected
  3288. );
  3289. } else {
  3290. this.assert(
  3291. list.indexOf(expected) > -1
  3292. , 'expected #{this} to be one of #{exp}'
  3293. , 'expected #{this} to not be one of #{exp}'
  3294. , list
  3295. , expected
  3296. );
  3297. }
  3298. }
  3299. }
  3300. Assertion.addMethod('oneOf', oneOf);
  3301. /**
  3302. * ### .change(subject[, prop[, msg]])
  3303. *
  3304. * When one argument is provided, `.change` asserts that the given function
  3305. * `subject` returns a different value when it's invoked before the target
  3306. * function compared to when it's invoked afterward. However, it's often best
  3307. * to assert that `subject` is equal to its expected value.
  3308. *
  3309. * var dots = ''
  3310. * , addDot = function () { dots += '.'; }
  3311. * , getDots = function () { return dots; };
  3312. *
  3313. * // Recommended
  3314. * expect(getDots()).to.equal('');
  3315. * addDot();
  3316. * expect(getDots()).to.equal('.');
  3317. *
  3318. * // Not recommended
  3319. * expect(addDot).to.change(getDots);
  3320. *
  3321. * When two arguments are provided, `.change` asserts that the value of the
  3322. * given object `subject`'s `prop` property is different before invoking the
  3323. * target function compared to afterward.
  3324. *
  3325. * var myObj = {dots: ''}
  3326. * , addDot = function () { myObj.dots += '.'; };
  3327. *
  3328. * // Recommended
  3329. * expect(myObj).to.have.property('dots', '');
  3330. * addDot();
  3331. * expect(myObj).to.have.property('dots', '.');
  3332. *
  3333. * // Not recommended
  3334. * expect(addDot).to.change(myObj, 'dots');
  3335. *
  3336. * Strict (`===`) equality is used to compare before and after values.
  3337. *
  3338. * Add `.not` earlier in the chain to negate `.change`.
  3339. *
  3340. * var dots = ''
  3341. * , noop = function () {}
  3342. * , getDots = function () { return dots; };
  3343. *
  3344. * expect(noop).to.not.change(getDots);
  3345. *
  3346. * var myObj = {dots: ''}
  3347. * , noop = function () {};
  3348. *
  3349. * expect(noop).to.not.change(myObj, 'dots');
  3350. *
  3351. * `.change` accepts an optional `msg` argument which is a custom error
  3352. * message to show when the assertion fails. The message can also be given as
  3353. * the second argument to `expect`. When not providing two arguments, always
  3354. * use the second form.
  3355. *
  3356. * var myObj = {dots: ''}
  3357. * , addDot = function () { myObj.dots += '.'; };
  3358. *
  3359. * expect(addDot).to.not.change(myObj, 'dots', 'nooo why fail??');
  3360. *
  3361. * var dots = ''
  3362. * , addDot = function () { dots += '.'; }
  3363. * , getDots = function () { return dots; };
  3364. *
  3365. * expect(addDot, 'nooo why fail??').to.not.change(getDots);
  3366. *
  3367. * `.change` also causes all `.by` assertions that follow in the chain to
  3368. * assert how much a numeric subject was increased or decreased by. However,
  3369. * it's dangerous to use `.change.by`. The problem is that it creates
  3370. * uncertain expectations by asserting that the subject either increases by
  3371. * the given delta, or that it decreases by the given delta. It's often best
  3372. * to identify the exact output that's expected, and then write an assertion
  3373. * that only accepts that exact output.
  3374. *
  3375. * var myObj = {val: 1}
  3376. * , addTwo = function () { myObj.val += 2; }
  3377. * , subtractTwo = function () { myObj.val -= 2; };
  3378. *
  3379. * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
  3380. * expect(addTwo).to.change(myObj, 'val').by(2); // Not recommended
  3381. *
  3382. * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
  3383. * expect(subtractTwo).to.change(myObj, 'val').by(2); // Not recommended
  3384. *
  3385. * The alias `.changes` can be used interchangeably with `.change`.
  3386. *
  3387. * @name change
  3388. * @alias changes
  3389. * @param {String} subject
  3390. * @param {String} prop name _optional_
  3391. * @param {String} msg _optional_
  3392. * @namespace BDD
  3393. * @api public
  3394. */
  3395. function assertChanges (subject, prop, msg) {
  3396. if (msg) flag(this, 'message', msg);
  3397. var fn = flag(this, 'object')
  3398. , flagMsg = flag(this, 'message')
  3399. , ssfi = flag(this, 'ssfi');
  3400. new Assertion(fn, flagMsg, ssfi, true).is.a('function');
  3401. var initial;
  3402. if (!prop) {
  3403. new Assertion(subject, flagMsg, ssfi, true).is.a('function');
  3404. initial = subject();
  3405. } else {
  3406. new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
  3407. initial = subject[prop];
  3408. }
  3409. fn();
  3410. var final = prop === undefined || prop === null ? subject() : subject[prop];
  3411. var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
  3412. // This gets flagged because of the .by(delta) assertion
  3413. flag(this, 'deltaMsgObj', msgObj);
  3414. flag(this, 'initialDeltaValue', initial);
  3415. flag(this, 'finalDeltaValue', final);
  3416. flag(this, 'deltaBehavior', 'change');
  3417. flag(this, 'realDelta', final !== initial);
  3418. this.assert(
  3419. initial !== final
  3420. , 'expected ' + msgObj + ' to change'
  3421. , 'expected ' + msgObj + ' to not change'
  3422. );
  3423. }
  3424. Assertion.addMethod('change', assertChanges);
  3425. Assertion.addMethod('changes', assertChanges);
  3426. /**
  3427. * ### .increase(subject[, prop[, msg]])
  3428. *
  3429. * When one argument is provided, `.increase` asserts that the given function
  3430. * `subject` returns a greater number when it's invoked after invoking the
  3431. * target function compared to when it's invoked beforehand. `.increase` also
  3432. * causes all `.by` assertions that follow in the chain to assert how much
  3433. * greater of a number is returned. It's often best to assert that the return
  3434. * value increased by the expected amount, rather than asserting it increased
  3435. * by any amount.
  3436. *
  3437. * var val = 1
  3438. * , addTwo = function () { val += 2; }
  3439. * , getVal = function () { return val; };
  3440. *
  3441. * expect(addTwo).to.increase(getVal).by(2); // Recommended
  3442. * expect(addTwo).to.increase(getVal); // Not recommended
  3443. *
  3444. * When two arguments are provided, `.increase` asserts that the value of the
  3445. * given object `subject`'s `prop` property is greater after invoking the
  3446. * target function compared to beforehand.
  3447. *
  3448. * var myObj = {val: 1}
  3449. * , addTwo = function () { myObj.val += 2; };
  3450. *
  3451. * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
  3452. * expect(addTwo).to.increase(myObj, 'val'); // Not recommended
  3453. *
  3454. * Add `.not` earlier in the chain to negate `.increase`. However, it's
  3455. * dangerous to do so. The problem is that it creates uncertain expectations
  3456. * by asserting that the subject either decreases, or that it stays the same.
  3457. * It's often best to identify the exact output that's expected, and then
  3458. * write an assertion that only accepts that exact output.
  3459. *
  3460. * When the subject is expected to decrease, it's often best to assert that it
  3461. * decreased by the expected amount.
  3462. *
  3463. * var myObj = {val: 1}
  3464. * , subtractTwo = function () { myObj.val -= 2; };
  3465. *
  3466. * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
  3467. * expect(subtractTwo).to.not.increase(myObj, 'val'); // Not recommended
  3468. *
  3469. * When the subject is expected to stay the same, it's often best to assert
  3470. * exactly that.
  3471. *
  3472. * var myObj = {val: 1}
  3473. * , noop = function () {};
  3474. *
  3475. * expect(noop).to.not.change(myObj, 'val'); // Recommended
  3476. * expect(noop).to.not.increase(myObj, 'val'); // Not recommended
  3477. *
  3478. * `.increase` accepts an optional `msg` argument which is a custom error
  3479. * message to show when the assertion fails. The message can also be given as
  3480. * the second argument to `expect`. When not providing two arguments, always
  3481. * use the second form.
  3482. *
  3483. * var myObj = {val: 1}
  3484. * , noop = function () {};
  3485. *
  3486. * expect(noop).to.increase(myObj, 'val', 'nooo why fail??');
  3487. *
  3488. * var val = 1
  3489. * , noop = function () {}
  3490. * , getVal = function () { return val; };
  3491. *
  3492. * expect(noop, 'nooo why fail??').to.increase(getVal);
  3493. *
  3494. * The alias `.increases` can be used interchangeably with `.increase`.
  3495. *
  3496. * @name increase
  3497. * @alias increases
  3498. * @param {String|Function} subject
  3499. * @param {String} prop name _optional_
  3500. * @param {String} msg _optional_
  3501. * @namespace BDD
  3502. * @api public
  3503. */
  3504. function assertIncreases (subject, prop, msg) {
  3505. if (msg) flag(this, 'message', msg);
  3506. var fn = flag(this, 'object')
  3507. , flagMsg = flag(this, 'message')
  3508. , ssfi = flag(this, 'ssfi');
  3509. new Assertion(fn, flagMsg, ssfi, true).is.a('function');
  3510. var initial;
  3511. if (!prop) {
  3512. new Assertion(subject, flagMsg, ssfi, true).is.a('function');
  3513. initial = subject();
  3514. } else {
  3515. new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
  3516. initial = subject[prop];
  3517. }
  3518. // Make sure that the target is a number
  3519. new Assertion(initial, flagMsg, ssfi, true).is.a('number');
  3520. fn();
  3521. var final = prop === undefined || prop === null ? subject() : subject[prop];
  3522. var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
  3523. flag(this, 'deltaMsgObj', msgObj);
  3524. flag(this, 'initialDeltaValue', initial);
  3525. flag(this, 'finalDeltaValue', final);
  3526. flag(this, 'deltaBehavior', 'increase');
  3527. flag(this, 'realDelta', final - initial);
  3528. this.assert(
  3529. final - initial > 0
  3530. , 'expected ' + msgObj + ' to increase'
  3531. , 'expected ' + msgObj + ' to not increase'
  3532. );
  3533. }
  3534. Assertion.addMethod('increase', assertIncreases);
  3535. Assertion.addMethod('increases', assertIncreases);
  3536. /**
  3537. * ### .decrease(subject[, prop[, msg]])
  3538. *
  3539. * When one argument is provided, `.decrease` asserts that the given function
  3540. * `subject` returns a lesser number when it's invoked after invoking the
  3541. * target function compared to when it's invoked beforehand. `.decrease` also
  3542. * causes all `.by` assertions that follow in the chain to assert how much
  3543. * lesser of a number is returned. It's often best to assert that the return
  3544. * value decreased by the expected amount, rather than asserting it decreased
  3545. * by any amount.
  3546. *
  3547. * var val = 1
  3548. * , subtractTwo = function () { val -= 2; }
  3549. * , getVal = function () { return val; };
  3550. *
  3551. * expect(subtractTwo).to.decrease(getVal).by(2); // Recommended
  3552. * expect(subtractTwo).to.decrease(getVal); // Not recommended
  3553. *
  3554. * When two arguments are provided, `.decrease` asserts that the value of the
  3555. * given object `subject`'s `prop` property is lesser after invoking the
  3556. * target function compared to beforehand.
  3557. *
  3558. * var myObj = {val: 1}
  3559. * , subtractTwo = function () { myObj.val -= 2; };
  3560. *
  3561. * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
  3562. * expect(subtractTwo).to.decrease(myObj, 'val'); // Not recommended
  3563. *
  3564. * Add `.not` earlier in the chain to negate `.decrease`. However, it's
  3565. * dangerous to do so. The problem is that it creates uncertain expectations
  3566. * by asserting that the subject either increases, or that it stays the same.
  3567. * It's often best to identify the exact output that's expected, and then
  3568. * write an assertion that only accepts that exact output.
  3569. *
  3570. * When the subject is expected to increase, it's often best to assert that it
  3571. * increased by the expected amount.
  3572. *
  3573. * var myObj = {val: 1}
  3574. * , addTwo = function () { myObj.val += 2; };
  3575. *
  3576. * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
  3577. * expect(addTwo).to.not.decrease(myObj, 'val'); // Not recommended
  3578. *
  3579. * When the subject is expected to stay the same, it's often best to assert
  3580. * exactly that.
  3581. *
  3582. * var myObj = {val: 1}
  3583. * , noop = function () {};
  3584. *
  3585. * expect(noop).to.not.change(myObj, 'val'); // Recommended
  3586. * expect(noop).to.not.decrease(myObj, 'val'); // Not recommended
  3587. *
  3588. * `.decrease` accepts an optional `msg` argument which is a custom error
  3589. * message to show when the assertion fails. The message can also be given as
  3590. * the second argument to `expect`. When not providing two arguments, always
  3591. * use the second form.
  3592. *
  3593. * var myObj = {val: 1}
  3594. * , noop = function () {};
  3595. *
  3596. * expect(noop).to.decrease(myObj, 'val', 'nooo why fail??');
  3597. *
  3598. * var val = 1
  3599. * , noop = function () {}
  3600. * , getVal = function () { return val; };
  3601. *
  3602. * expect(noop, 'nooo why fail??').to.decrease(getVal);
  3603. *
  3604. * The alias `.decreases` can be used interchangeably with `.decrease`.
  3605. *
  3606. * @name decrease
  3607. * @alias decreases
  3608. * @param {String|Function} subject
  3609. * @param {String} prop name _optional_
  3610. * @param {String} msg _optional_
  3611. * @namespace BDD
  3612. * @api public
  3613. */
  3614. function assertDecreases (subject, prop, msg) {
  3615. if (msg) flag(this, 'message', msg);
  3616. var fn = flag(this, 'object')
  3617. , flagMsg = flag(this, 'message')
  3618. , ssfi = flag(this, 'ssfi');
  3619. new Assertion(fn, flagMsg, ssfi, true).is.a('function');
  3620. var initial;
  3621. if (!prop) {
  3622. new Assertion(subject, flagMsg, ssfi, true).is.a('function');
  3623. initial = subject();
  3624. } else {
  3625. new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
  3626. initial = subject[prop];
  3627. }
  3628. // Make sure that the target is a number
  3629. new Assertion(initial, flagMsg, ssfi, true).is.a('number');
  3630. fn();
  3631. var final = prop === undefined || prop === null ? subject() : subject[prop];
  3632. var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
  3633. flag(this, 'deltaMsgObj', msgObj);
  3634. flag(this, 'initialDeltaValue', initial);
  3635. flag(this, 'finalDeltaValue', final);
  3636. flag(this, 'deltaBehavior', 'decrease');
  3637. flag(this, 'realDelta', initial - final);
  3638. this.assert(
  3639. final - initial < 0
  3640. , 'expected ' + msgObj + ' to decrease'
  3641. , 'expected ' + msgObj + ' to not decrease'
  3642. );
  3643. }
  3644. Assertion.addMethod('decrease', assertDecreases);
  3645. Assertion.addMethod('decreases', assertDecreases);
  3646. /**
  3647. * ### .by(delta[, msg])
  3648. *
  3649. * When following an `.increase` assertion in the chain, `.by` asserts that
  3650. * the subject of the `.increase` assertion increased by the given `delta`.
  3651. *
  3652. * var myObj = {val: 1}
  3653. * , addTwo = function () { myObj.val += 2; };
  3654. *
  3655. * expect(addTwo).to.increase(myObj, 'val').by(2);
  3656. *
  3657. * When following a `.decrease` assertion in the chain, `.by` asserts that the
  3658. * subject of the `.decrease` assertion decreased by the given `delta`.
  3659. *
  3660. * var myObj = {val: 1}
  3661. * , subtractTwo = function () { myObj.val -= 2; };
  3662. *
  3663. * expect(subtractTwo).to.decrease(myObj, 'val').by(2);
  3664. *
  3665. * When following a `.change` assertion in the chain, `.by` asserts that the
  3666. * subject of the `.change` assertion either increased or decreased by the
  3667. * given `delta`. However, it's dangerous to use `.change.by`. The problem is
  3668. * that it creates uncertain expectations. It's often best to identify the
  3669. * exact output that's expected, and then write an assertion that only accepts
  3670. * that exact output.
  3671. *
  3672. * var myObj = {val: 1}
  3673. * , addTwo = function () { myObj.val += 2; }
  3674. * , subtractTwo = function () { myObj.val -= 2; };
  3675. *
  3676. * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
  3677. * expect(addTwo).to.change(myObj, 'val').by(2); // Not recommended
  3678. *
  3679. * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
  3680. * expect(subtractTwo).to.change(myObj, 'val').by(2); // Not recommended
  3681. *
  3682. * Add `.not` earlier in the chain to negate `.by`. However, it's often best
  3683. * to assert that the subject changed by its expected delta, rather than
  3684. * asserting that it didn't change by one of countless unexpected deltas.
  3685. *
  3686. * var myObj = {val: 1}
  3687. * , addTwo = function () { myObj.val += 2; };
  3688. *
  3689. * // Recommended
  3690. * expect(addTwo).to.increase(myObj, 'val').by(2);
  3691. *
  3692. * // Not recommended
  3693. * expect(addTwo).to.increase(myObj, 'val').but.not.by(3);
  3694. *
  3695. * `.by` accepts an optional `msg` argument which is a custom error message to
  3696. * show when the assertion fails. The message can also be given as the second
  3697. * argument to `expect`.
  3698. *
  3699. * var myObj = {val: 1}
  3700. * , addTwo = function () { myObj.val += 2; };
  3701. *
  3702. * expect(addTwo).to.increase(myObj, 'val').by(3, 'nooo why fail??');
  3703. * expect(addTwo, 'nooo why fail??').to.increase(myObj, 'val').by(3);
  3704. *
  3705. * @name by
  3706. * @param {Number} delta
  3707. * @param {String} msg _optional_
  3708. * @namespace BDD
  3709. * @api public
  3710. */
  3711. function assertDelta(delta, msg) {
  3712. if (msg) flag(this, 'message', msg);
  3713. var msgObj = flag(this, 'deltaMsgObj');
  3714. var initial = flag(this, 'initialDeltaValue');
  3715. var final = flag(this, 'finalDeltaValue');
  3716. var behavior = flag(this, 'deltaBehavior');
  3717. var realDelta = flag(this, 'realDelta');
  3718. var expression;
  3719. if (behavior === 'change') {
  3720. expression = Math.abs(final - initial) === Math.abs(delta);
  3721. } else {
  3722. expression = realDelta === Math.abs(delta);
  3723. }
  3724. this.assert(
  3725. expression
  3726. , 'expected ' + msgObj + ' to ' + behavior + ' by ' + delta
  3727. , 'expected ' + msgObj + ' to not ' + behavior + ' by ' + delta
  3728. );
  3729. }
  3730. Assertion.addMethod('by', assertDelta);
  3731. /**
  3732. * ### .extensible
  3733. *
  3734. * Asserts that the target is extensible, which means that new properties can
  3735. * be added to it. Primitives are never extensible.
  3736. *
  3737. * expect({a: 1}).to.be.extensible;
  3738. *
  3739. * Add `.not` earlier in the chain to negate `.extensible`.
  3740. *
  3741. * var nonExtensibleObject = Object.preventExtensions({})
  3742. * , sealedObject = Object.seal({})
  3743. * , frozenObject = Object.freeze({});
  3744. *
  3745. * expect(nonExtensibleObject).to.not.be.extensible;
  3746. * expect(sealedObject).to.not.be.extensible;
  3747. * expect(frozenObject).to.not.be.extensible;
  3748. * expect(1).to.not.be.extensible;
  3749. *
  3750. * A custom error message can be given as the second argument to `expect`.
  3751. *
  3752. * expect(1, 'nooo why fail??').to.be.extensible;
  3753. *
  3754. * @name extensible
  3755. * @namespace BDD
  3756. * @api public
  3757. */
  3758. Assertion.addProperty('extensible', function() {
  3759. var obj = flag(this, 'object');
  3760. // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
  3761. // In ES6, a non-object argument will be treated as if it was a non-extensible ordinary object, simply return false.
  3762. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
  3763. // The following provides ES6 behavior for ES5 environments.
  3764. var isExtensible = obj === Object(obj) && Object.isExtensible(obj);
  3765. this.assert(
  3766. isExtensible
  3767. , 'expected #{this} to be extensible'
  3768. , 'expected #{this} to not be extensible'
  3769. );
  3770. });
  3771. /**
  3772. * ### .sealed
  3773. *
  3774. * Asserts that the target is sealed, which means that new properties can't be
  3775. * added to it, and its existing properties can't be reconfigured or deleted.
  3776. * However, it's possible that its existing properties can still be reassigned
  3777. * to different values. Primitives are always sealed.
  3778. *
  3779. * var sealedObject = Object.seal({});
  3780. * var frozenObject = Object.freeze({});
  3781. *
  3782. * expect(sealedObject).to.be.sealed;
  3783. * expect(frozenObject).to.be.sealed;
  3784. * expect(1).to.be.sealed;
  3785. *
  3786. * Add `.not` earlier in the chain to negate `.sealed`.
  3787. *
  3788. * expect({a: 1}).to.not.be.sealed;
  3789. *
  3790. * A custom error message can be given as the second argument to `expect`.
  3791. *
  3792. * expect({a: 1}, 'nooo why fail??').to.be.sealed;
  3793. *
  3794. * @name sealed
  3795. * @namespace BDD
  3796. * @api public
  3797. */
  3798. Assertion.addProperty('sealed', function() {
  3799. var obj = flag(this, 'object');
  3800. // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
  3801. // In ES6, a non-object argument will be treated as if it was a sealed ordinary object, simply return true.
  3802. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
  3803. // The following provides ES6 behavior for ES5 environments.
  3804. var isSealed = obj === Object(obj) ? Object.isSealed(obj) : true;
  3805. this.assert(
  3806. isSealed
  3807. , 'expected #{this} to be sealed'
  3808. , 'expected #{this} to not be sealed'
  3809. );
  3810. });
  3811. /**
  3812. * ### .frozen
  3813. *
  3814. * Asserts that the target is frozen, which means that new properties can't be
  3815. * added to it, and its existing properties can't be reassigned to different
  3816. * values, reconfigured, or deleted. Primitives are always frozen.
  3817. *
  3818. * var frozenObject = Object.freeze({});
  3819. *
  3820. * expect(frozenObject).to.be.frozen;
  3821. * expect(1).to.be.frozen;
  3822. *
  3823. * Add `.not` earlier in the chain to negate `.frozen`.
  3824. *
  3825. * expect({a: 1}).to.not.be.frozen;
  3826. *
  3827. * A custom error message can be given as the second argument to `expect`.
  3828. *
  3829. * expect({a: 1}, 'nooo why fail??').to.be.frozen;
  3830. *
  3831. * @name frozen
  3832. * @namespace BDD
  3833. * @api public
  3834. */
  3835. Assertion.addProperty('frozen', function() {
  3836. var obj = flag(this, 'object');
  3837. // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
  3838. // In ES6, a non-object argument will be treated as if it was a frozen ordinary object, simply return true.
  3839. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
  3840. // The following provides ES6 behavior for ES5 environments.
  3841. var isFrozen = obj === Object(obj) ? Object.isFrozen(obj) : true;
  3842. this.assert(
  3843. isFrozen
  3844. , 'expected #{this} to be frozen'
  3845. , 'expected #{this} to not be frozen'
  3846. );
  3847. });
  3848. /**
  3849. * ### .finite
  3850. *
  3851. * Asserts that the target is a number, and isn't `NaN` or positive/negative
  3852. * `Infinity`.
  3853. *
  3854. * expect(1).to.be.finite;
  3855. *
  3856. * Add `.not` earlier in the chain to negate `.finite`. However, it's
  3857. * dangerous to do so. The problem is that it creates uncertain expectations
  3858. * by asserting that the subject either isn't a number, or that it's `NaN`, or
  3859. * that it's positive `Infinity`, or that it's negative `Infinity`. It's often
  3860. * best to identify the exact output that's expected, and then write an
  3861. * assertion that only accepts that exact output.
  3862. *
  3863. * When the target isn't expected to be a number, it's often best to assert
  3864. * that it's the expected type, rather than asserting that it isn't one of
  3865. * many unexpected types.
  3866. *
  3867. * expect('foo').to.be.a('string'); // Recommended
  3868. * expect('foo').to.not.be.finite; // Not recommended
  3869. *
  3870. * When the target is expected to be `NaN`, it's often best to assert exactly
  3871. * that.
  3872. *
  3873. * expect(NaN).to.be.NaN; // Recommended
  3874. * expect(NaN).to.not.be.finite; // Not recommended
  3875. *
  3876. * When the target is expected to be positive infinity, it's often best to
  3877. * assert exactly that.
  3878. *
  3879. * expect(Infinity).to.equal(Infinity); // Recommended
  3880. * expect(Infinity).to.not.be.finite; // Not recommended
  3881. *
  3882. * When the target is expected to be negative infinity, it's often best to
  3883. * assert exactly that.
  3884. *
  3885. * expect(-Infinity).to.equal(-Infinity); // Recommended
  3886. * expect(-Infinity).to.not.be.finite; // Not recommended
  3887. *
  3888. * A custom error message can be given as the second argument to `expect`.
  3889. *
  3890. * expect('foo', 'nooo why fail??').to.be.finite;
  3891. *
  3892. * @name finite
  3893. * @namespace BDD
  3894. * @api public
  3895. */
  3896. Assertion.addProperty('finite', function(msg) {
  3897. var obj = flag(this, 'object');
  3898. this.assert(
  3899. typeof obj === 'number' && isFinite(obj)
  3900. , 'expected #{this} to be a finite number'
  3901. , 'expected #{this} to not be a finite number'
  3902. );
  3903. });
  3904. };
  3905. },{}],6:[function(require,module,exports){
  3906. /*!
  3907. * chai
  3908. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  3909. * MIT Licensed
  3910. */
  3911. module.exports = function (chai, util) {
  3912. /*!
  3913. * Chai dependencies.
  3914. */
  3915. var Assertion = chai.Assertion
  3916. , flag = util.flag;
  3917. /*!
  3918. * Module export.
  3919. */
  3920. /**
  3921. * ### assert(expression, message)
  3922. *
  3923. * Write your own test expressions.
  3924. *
  3925. * assert('foo' !== 'bar', 'foo is not bar');
  3926. * assert(Array.isArray([]), 'empty arrays are arrays');
  3927. *
  3928. * @param {Mixed} expression to test for truthiness
  3929. * @param {String} message to display on error
  3930. * @name assert
  3931. * @namespace Assert
  3932. * @api public
  3933. */
  3934. var assert = chai.assert = function (express, errmsg) {
  3935. var test = new Assertion(null, null, chai.assert, true);
  3936. test.assert(
  3937. express
  3938. , errmsg
  3939. , '[ negation message unavailable ]'
  3940. );
  3941. };
  3942. /**
  3943. * ### .fail([message])
  3944. * ### .fail(actual, expected, [message], [operator])
  3945. *
  3946. * Throw a failure. Node.js `assert` module-compatible.
  3947. *
  3948. * assert.fail();
  3949. * assert.fail("custom error message");
  3950. * assert.fail(1, 2);
  3951. * assert.fail(1, 2, "custom error message");
  3952. * assert.fail(1, 2, "custom error message", ">");
  3953. * assert.fail(1, 2, undefined, ">");
  3954. *
  3955. * @name fail
  3956. * @param {Mixed} actual
  3957. * @param {Mixed} expected
  3958. * @param {String} message
  3959. * @param {String} operator
  3960. * @namespace Assert
  3961. * @api public
  3962. */
  3963. assert.fail = function (actual, expected, message, operator) {
  3964. if (arguments.length < 2) {
  3965. // Comply with Node's fail([message]) interface
  3966. message = actual;
  3967. actual = undefined;
  3968. }
  3969. message = message || 'assert.fail()';
  3970. throw new chai.AssertionError(message, {
  3971. actual: actual
  3972. , expected: expected
  3973. , operator: operator
  3974. }, assert.fail);
  3975. };
  3976. /**
  3977. * ### .isOk(object, [message])
  3978. *
  3979. * Asserts that `object` is truthy.
  3980. *
  3981. * assert.isOk('everything', 'everything is ok');
  3982. * assert.isOk(false, 'this will fail');
  3983. *
  3984. * @name isOk
  3985. * @alias ok
  3986. * @param {Mixed} object to test
  3987. * @param {String} message
  3988. * @namespace Assert
  3989. * @api public
  3990. */
  3991. assert.isOk = function (val, msg) {
  3992. new Assertion(val, msg, assert.isOk, true).is.ok;
  3993. };
  3994. /**
  3995. * ### .isNotOk(object, [message])
  3996. *
  3997. * Asserts that `object` is falsy.
  3998. *
  3999. * assert.isNotOk('everything', 'this will fail');
  4000. * assert.isNotOk(false, 'this will pass');
  4001. *
  4002. * @name isNotOk
  4003. * @alias notOk
  4004. * @param {Mixed} object to test
  4005. * @param {String} message
  4006. * @namespace Assert
  4007. * @api public
  4008. */
  4009. assert.isNotOk = function (val, msg) {
  4010. new Assertion(val, msg, assert.isNotOk, true).is.not.ok;
  4011. };
  4012. /**
  4013. * ### .equal(actual, expected, [message])
  4014. *
  4015. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  4016. *
  4017. * assert.equal(3, '3', '== coerces values to strings');
  4018. *
  4019. * @name equal
  4020. * @param {Mixed} actual
  4021. * @param {Mixed} expected
  4022. * @param {String} message
  4023. * @namespace Assert
  4024. * @api public
  4025. */
  4026. assert.equal = function (act, exp, msg) {
  4027. var test = new Assertion(act, msg, assert.equal, true);
  4028. test.assert(
  4029. exp == flag(test, 'object')
  4030. , 'expected #{this} to equal #{exp}'
  4031. , 'expected #{this} to not equal #{act}'
  4032. , exp
  4033. , act
  4034. , true
  4035. );
  4036. };
  4037. /**
  4038. * ### .notEqual(actual, expected, [message])
  4039. *
  4040. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  4041. *
  4042. * assert.notEqual(3, 4, 'these numbers are not equal');
  4043. *
  4044. * @name notEqual
  4045. * @param {Mixed} actual
  4046. * @param {Mixed} expected
  4047. * @param {String} message
  4048. * @namespace Assert
  4049. * @api public
  4050. */
  4051. assert.notEqual = function (act, exp, msg) {
  4052. var test = new Assertion(act, msg, assert.notEqual, true);
  4053. test.assert(
  4054. exp != flag(test, 'object')
  4055. , 'expected #{this} to not equal #{exp}'
  4056. , 'expected #{this} to equal #{act}'
  4057. , exp
  4058. , act
  4059. , true
  4060. );
  4061. };
  4062. /**
  4063. * ### .strictEqual(actual, expected, [message])
  4064. *
  4065. * Asserts strict equality (`===`) of `actual` and `expected`.
  4066. *
  4067. * assert.strictEqual(true, true, 'these booleans are strictly equal');
  4068. *
  4069. * @name strictEqual
  4070. * @param {Mixed} actual
  4071. * @param {Mixed} expected
  4072. * @param {String} message
  4073. * @namespace Assert
  4074. * @api public
  4075. */
  4076. assert.strictEqual = function (act, exp, msg) {
  4077. new Assertion(act, msg, assert.strictEqual, true).to.equal(exp);
  4078. };
  4079. /**
  4080. * ### .notStrictEqual(actual, expected, [message])
  4081. *
  4082. * Asserts strict inequality (`!==`) of `actual` and `expected`.
  4083. *
  4084. * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
  4085. *
  4086. * @name notStrictEqual
  4087. * @param {Mixed} actual
  4088. * @param {Mixed} expected
  4089. * @param {String} message
  4090. * @namespace Assert
  4091. * @api public
  4092. */
  4093. assert.notStrictEqual = function (act, exp, msg) {
  4094. new Assertion(act, msg, assert.notStrictEqual, true).to.not.equal(exp);
  4095. };
  4096. /**
  4097. * ### .deepEqual(actual, expected, [message])
  4098. *
  4099. * Asserts that `actual` is deeply equal to `expected`.
  4100. *
  4101. * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
  4102. *
  4103. * @name deepEqual
  4104. * @param {Mixed} actual
  4105. * @param {Mixed} expected
  4106. * @param {String} message
  4107. * @alias deepStrictEqual
  4108. * @namespace Assert
  4109. * @api public
  4110. */
  4111. assert.deepEqual = assert.deepStrictEqual = function (act, exp, msg) {
  4112. new Assertion(act, msg, assert.deepEqual, true).to.eql(exp);
  4113. };
  4114. /**
  4115. * ### .notDeepEqual(actual, expected, [message])
  4116. *
  4117. * Assert that `actual` is not deeply equal to `expected`.
  4118. *
  4119. * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
  4120. *
  4121. * @name notDeepEqual
  4122. * @param {Mixed} actual
  4123. * @param {Mixed} expected
  4124. * @param {String} message
  4125. * @namespace Assert
  4126. * @api public
  4127. */
  4128. assert.notDeepEqual = function (act, exp, msg) {
  4129. new Assertion(act, msg, assert.notDeepEqual, true).to.not.eql(exp);
  4130. };
  4131. /**
  4132. * ### .isAbove(valueToCheck, valueToBeAbove, [message])
  4133. *
  4134. * Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`.
  4135. *
  4136. * assert.isAbove(5, 2, '5 is strictly greater than 2');
  4137. *
  4138. * @name isAbove
  4139. * @param {Mixed} valueToCheck
  4140. * @param {Mixed} valueToBeAbove
  4141. * @param {String} message
  4142. * @namespace Assert
  4143. * @api public
  4144. */
  4145. assert.isAbove = function (val, abv, msg) {
  4146. new Assertion(val, msg, assert.isAbove, true).to.be.above(abv);
  4147. };
  4148. /**
  4149. * ### .isAtLeast(valueToCheck, valueToBeAtLeast, [message])
  4150. *
  4151. * Asserts `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`.
  4152. *
  4153. * assert.isAtLeast(5, 2, '5 is greater or equal to 2');
  4154. * assert.isAtLeast(3, 3, '3 is greater or equal to 3');
  4155. *
  4156. * @name isAtLeast
  4157. * @param {Mixed} valueToCheck
  4158. * @param {Mixed} valueToBeAtLeast
  4159. * @param {String} message
  4160. * @namespace Assert
  4161. * @api public
  4162. */
  4163. assert.isAtLeast = function (val, atlst, msg) {
  4164. new Assertion(val, msg, assert.isAtLeast, true).to.be.least(atlst);
  4165. };
  4166. /**
  4167. * ### .isBelow(valueToCheck, valueToBeBelow, [message])
  4168. *
  4169. * Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`.
  4170. *
  4171. * assert.isBelow(3, 6, '3 is strictly less than 6');
  4172. *
  4173. * @name isBelow
  4174. * @param {Mixed} valueToCheck
  4175. * @param {Mixed} valueToBeBelow
  4176. * @param {String} message
  4177. * @namespace Assert
  4178. * @api public
  4179. */
  4180. assert.isBelow = function (val, blw, msg) {
  4181. new Assertion(val, msg, assert.isBelow, true).to.be.below(blw);
  4182. };
  4183. /**
  4184. * ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
  4185. *
  4186. * Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`.
  4187. *
  4188. * assert.isAtMost(3, 6, '3 is less than or equal to 6');
  4189. * assert.isAtMost(4, 4, '4 is less than or equal to 4');
  4190. *
  4191. * @name isAtMost
  4192. * @param {Mixed} valueToCheck
  4193. * @param {Mixed} valueToBeAtMost
  4194. * @param {String} message
  4195. * @namespace Assert
  4196. * @api public
  4197. */
  4198. assert.isAtMost = function (val, atmst, msg) {
  4199. new Assertion(val, msg, assert.isAtMost, true).to.be.most(atmst);
  4200. };
  4201. /**
  4202. * ### .isTrue(value, [message])
  4203. *
  4204. * Asserts that `value` is true.
  4205. *
  4206. * var teaServed = true;
  4207. * assert.isTrue(teaServed, 'the tea has been served');
  4208. *
  4209. * @name isTrue
  4210. * @param {Mixed} value
  4211. * @param {String} message
  4212. * @namespace Assert
  4213. * @api public
  4214. */
  4215. assert.isTrue = function (val, msg) {
  4216. new Assertion(val, msg, assert.isTrue, true).is['true'];
  4217. };
  4218. /**
  4219. * ### .isNotTrue(value, [message])
  4220. *
  4221. * Asserts that `value` is not true.
  4222. *
  4223. * var tea = 'tasty chai';
  4224. * assert.isNotTrue(tea, 'great, time for tea!');
  4225. *
  4226. * @name isNotTrue
  4227. * @param {Mixed} value
  4228. * @param {String} message
  4229. * @namespace Assert
  4230. * @api public
  4231. */
  4232. assert.isNotTrue = function (val, msg) {
  4233. new Assertion(val, msg, assert.isNotTrue, true).to.not.equal(true);
  4234. };
  4235. /**
  4236. * ### .isFalse(value, [message])
  4237. *
  4238. * Asserts that `value` is false.
  4239. *
  4240. * var teaServed = false;
  4241. * assert.isFalse(teaServed, 'no tea yet? hmm...');
  4242. *
  4243. * @name isFalse
  4244. * @param {Mixed} value
  4245. * @param {String} message
  4246. * @namespace Assert
  4247. * @api public
  4248. */
  4249. assert.isFalse = function (val, msg) {
  4250. new Assertion(val, msg, assert.isFalse, true).is['false'];
  4251. };
  4252. /**
  4253. * ### .isNotFalse(value, [message])
  4254. *
  4255. * Asserts that `value` is not false.
  4256. *
  4257. * var tea = 'tasty chai';
  4258. * assert.isNotFalse(tea, 'great, time for tea!');
  4259. *
  4260. * @name isNotFalse
  4261. * @param {Mixed} value
  4262. * @param {String} message
  4263. * @namespace Assert
  4264. * @api public
  4265. */
  4266. assert.isNotFalse = function (val, msg) {
  4267. new Assertion(val, msg, assert.isNotFalse, true).to.not.equal(false);
  4268. };
  4269. /**
  4270. * ### .isNull(value, [message])
  4271. *
  4272. * Asserts that `value` is null.
  4273. *
  4274. * assert.isNull(err, 'there was no error');
  4275. *
  4276. * @name isNull
  4277. * @param {Mixed} value
  4278. * @param {String} message
  4279. * @namespace Assert
  4280. * @api public
  4281. */
  4282. assert.isNull = function (val, msg) {
  4283. new Assertion(val, msg, assert.isNull, true).to.equal(null);
  4284. };
  4285. /**
  4286. * ### .isNotNull(value, [message])
  4287. *
  4288. * Asserts that `value` is not null.
  4289. *
  4290. * var tea = 'tasty chai';
  4291. * assert.isNotNull(tea, 'great, time for tea!');
  4292. *
  4293. * @name isNotNull
  4294. * @param {Mixed} value
  4295. * @param {String} message
  4296. * @namespace Assert
  4297. * @api public
  4298. */
  4299. assert.isNotNull = function (val, msg) {
  4300. new Assertion(val, msg, assert.isNotNull, true).to.not.equal(null);
  4301. };
  4302. /**
  4303. * ### .isNaN
  4304. *
  4305. * Asserts that value is NaN.
  4306. *
  4307. * assert.isNaN(NaN, 'NaN is NaN');
  4308. *
  4309. * @name isNaN
  4310. * @param {Mixed} value
  4311. * @param {String} message
  4312. * @namespace Assert
  4313. * @api public
  4314. */
  4315. assert.isNaN = function (val, msg) {
  4316. new Assertion(val, msg, assert.isNaN, true).to.be.NaN;
  4317. };
  4318. /**
  4319. * ### .isNotNaN
  4320. *
  4321. * Asserts that value is not NaN.
  4322. *
  4323. * assert.isNotNaN(4, '4 is not NaN');
  4324. *
  4325. * @name isNotNaN
  4326. * @param {Mixed} value
  4327. * @param {String} message
  4328. * @namespace Assert
  4329. * @api public
  4330. */
  4331. assert.isNotNaN = function (val, msg) {
  4332. new Assertion(val, msg, assert.isNotNaN, true).not.to.be.NaN;
  4333. };
  4334. /**
  4335. * ### .exists
  4336. *
  4337. * Asserts that the target is neither `null` nor `undefined`.
  4338. *
  4339. * var foo = 'hi';
  4340. *
  4341. * assert.exists(foo, 'foo is neither `null` nor `undefined`');
  4342. *
  4343. * @name exists
  4344. * @param {Mixed} value
  4345. * @param {String} message
  4346. * @namespace Assert
  4347. * @api public
  4348. */
  4349. assert.exists = function (val, msg) {
  4350. new Assertion(val, msg, assert.exists, true).to.exist;
  4351. };
  4352. /**
  4353. * ### .notExists
  4354. *
  4355. * Asserts that the target is either `null` or `undefined`.
  4356. *
  4357. * var bar = null
  4358. * , baz;
  4359. *
  4360. * assert.notExists(bar);
  4361. * assert.notExists(baz, 'baz is either null or undefined');
  4362. *
  4363. * @name notExists
  4364. * @param {Mixed} value
  4365. * @param {String} message
  4366. * @namespace Assert
  4367. * @api public
  4368. */
  4369. assert.notExists = function (val, msg) {
  4370. new Assertion(val, msg, assert.notExists, true).to.not.exist;
  4371. };
  4372. /**
  4373. * ### .isUndefined(value, [message])
  4374. *
  4375. * Asserts that `value` is `undefined`.
  4376. *
  4377. * var tea;
  4378. * assert.isUndefined(tea, 'no tea defined');
  4379. *
  4380. * @name isUndefined
  4381. * @param {Mixed} value
  4382. * @param {String} message
  4383. * @namespace Assert
  4384. * @api public
  4385. */
  4386. assert.isUndefined = function (val, msg) {
  4387. new Assertion(val, msg, assert.isUndefined, true).to.equal(undefined);
  4388. };
  4389. /**
  4390. * ### .isDefined(value, [message])
  4391. *
  4392. * Asserts that `value` is not `undefined`.
  4393. *
  4394. * var tea = 'cup of chai';
  4395. * assert.isDefined(tea, 'tea has been defined');
  4396. *
  4397. * @name isDefined
  4398. * @param {Mixed} value
  4399. * @param {String} message
  4400. * @namespace Assert
  4401. * @api public
  4402. */
  4403. assert.isDefined = function (val, msg) {
  4404. new Assertion(val, msg, assert.isDefined, true).to.not.equal(undefined);
  4405. };
  4406. /**
  4407. * ### .isFunction(value, [message])
  4408. *
  4409. * Asserts that `value` is a function.
  4410. *
  4411. * function serveTea() { return 'cup of tea'; };
  4412. * assert.isFunction(serveTea, 'great, we can have tea now');
  4413. *
  4414. * @name isFunction
  4415. * @param {Mixed} value
  4416. * @param {String} message
  4417. * @namespace Assert
  4418. * @api public
  4419. */
  4420. assert.isFunction = function (val, msg) {
  4421. new Assertion(val, msg, assert.isFunction, true).to.be.a('function');
  4422. };
  4423. /**
  4424. * ### .isNotFunction(value, [message])
  4425. *
  4426. * Asserts that `value` is _not_ a function.
  4427. *
  4428. * var serveTea = [ 'heat', 'pour', 'sip' ];
  4429. * assert.isNotFunction(serveTea, 'great, we have listed the steps');
  4430. *
  4431. * @name isNotFunction
  4432. * @param {Mixed} value
  4433. * @param {String} message
  4434. * @namespace Assert
  4435. * @api public
  4436. */
  4437. assert.isNotFunction = function (val, msg) {
  4438. new Assertion(val, msg, assert.isNotFunction, true).to.not.be.a('function');
  4439. };
  4440. /**
  4441. * ### .isObject(value, [message])
  4442. *
  4443. * Asserts that `value` is an object of type 'Object' (as revealed by `Object.prototype.toString`).
  4444. * _The assertion does not match subclassed objects._
  4445. *
  4446. * var selection = { name: 'Chai', serve: 'with spices' };
  4447. * assert.isObject(selection, 'tea selection is an object');
  4448. *
  4449. * @name isObject
  4450. * @param {Mixed} value
  4451. * @param {String} message
  4452. * @namespace Assert
  4453. * @api public
  4454. */
  4455. assert.isObject = function (val, msg) {
  4456. new Assertion(val, msg, assert.isObject, true).to.be.a('object');
  4457. };
  4458. /**
  4459. * ### .isNotObject(value, [message])
  4460. *
  4461. * Asserts that `value` is _not_ an object of type 'Object' (as revealed by `Object.prototype.toString`).
  4462. *
  4463. * var selection = 'chai'
  4464. * assert.isNotObject(selection, 'tea selection is not an object');
  4465. * assert.isNotObject(null, 'null is not an object');
  4466. *
  4467. * @name isNotObject
  4468. * @param {Mixed} value
  4469. * @param {String} message
  4470. * @namespace Assert
  4471. * @api public
  4472. */
  4473. assert.isNotObject = function (val, msg) {
  4474. new Assertion(val, msg, assert.isNotObject, true).to.not.be.a('object');
  4475. };
  4476. /**
  4477. * ### .isArray(value, [message])
  4478. *
  4479. * Asserts that `value` is an array.
  4480. *
  4481. * var menu = [ 'green', 'chai', 'oolong' ];
  4482. * assert.isArray(menu, 'what kind of tea do we want?');
  4483. *
  4484. * @name isArray
  4485. * @param {Mixed} value
  4486. * @param {String} message
  4487. * @namespace Assert
  4488. * @api public
  4489. */
  4490. assert.isArray = function (val, msg) {
  4491. new Assertion(val, msg, assert.isArray, true).to.be.an('array');
  4492. };
  4493. /**
  4494. * ### .isNotArray(value, [message])
  4495. *
  4496. * Asserts that `value` is _not_ an array.
  4497. *
  4498. * var menu = 'green|chai|oolong';
  4499. * assert.isNotArray(menu, 'what kind of tea do we want?');
  4500. *
  4501. * @name isNotArray
  4502. * @param {Mixed} value
  4503. * @param {String} message
  4504. * @namespace Assert
  4505. * @api public
  4506. */
  4507. assert.isNotArray = function (val, msg) {
  4508. new Assertion(val, msg, assert.isNotArray, true).to.not.be.an('array');
  4509. };
  4510. /**
  4511. * ### .isString(value, [message])
  4512. *
  4513. * Asserts that `value` is a string.
  4514. *
  4515. * var teaOrder = 'chai';
  4516. * assert.isString(teaOrder, 'order placed');
  4517. *
  4518. * @name isString
  4519. * @param {Mixed} value
  4520. * @param {String} message
  4521. * @namespace Assert
  4522. * @api public
  4523. */
  4524. assert.isString = function (val, msg) {
  4525. new Assertion(val, msg, assert.isString, true).to.be.a('string');
  4526. };
  4527. /**
  4528. * ### .isNotString(value, [message])
  4529. *
  4530. * Asserts that `value` is _not_ a string.
  4531. *
  4532. * var teaOrder = 4;
  4533. * assert.isNotString(teaOrder, 'order placed');
  4534. *
  4535. * @name isNotString
  4536. * @param {Mixed} value
  4537. * @param {String} message
  4538. * @namespace Assert
  4539. * @api public
  4540. */
  4541. assert.isNotString = function (val, msg) {
  4542. new Assertion(val, msg, assert.isNotString, true).to.not.be.a('string');
  4543. };
  4544. /**
  4545. * ### .isNumber(value, [message])
  4546. *
  4547. * Asserts that `value` is a number.
  4548. *
  4549. * var cups = 2;
  4550. * assert.isNumber(cups, 'how many cups');
  4551. *
  4552. * @name isNumber
  4553. * @param {Number} value
  4554. * @param {String} message
  4555. * @namespace Assert
  4556. * @api public
  4557. */
  4558. assert.isNumber = function (val, msg) {
  4559. new Assertion(val, msg, assert.isNumber, true).to.be.a('number');
  4560. };
  4561. /**
  4562. * ### .isNotNumber(value, [message])
  4563. *
  4564. * Asserts that `value` is _not_ a number.
  4565. *
  4566. * var cups = '2 cups please';
  4567. * assert.isNotNumber(cups, 'how many cups');
  4568. *
  4569. * @name isNotNumber
  4570. * @param {Mixed} value
  4571. * @param {String} message
  4572. * @namespace Assert
  4573. * @api public
  4574. */
  4575. assert.isNotNumber = function (val, msg) {
  4576. new Assertion(val, msg, assert.isNotNumber, true).to.not.be.a('number');
  4577. };
  4578. /**
  4579. * ### .isFinite(value, [message])
  4580. *
  4581. * Asserts that `value` is a finite number. Unlike `.isNumber`, this will fail for `NaN` and `Infinity`.
  4582. *
  4583. * var cups = 2;
  4584. * assert.isFinite(cups, 'how many cups');
  4585. *
  4586. * assert.isFinite(NaN); // throws
  4587. *
  4588. * @name isFinite
  4589. * @param {Number} value
  4590. * @param {String} message
  4591. * @namespace Assert
  4592. * @api public
  4593. */
  4594. assert.isFinite = function (val, msg) {
  4595. new Assertion(val, msg, assert.isFinite, true).to.be.finite;
  4596. };
  4597. /**
  4598. * ### .isBoolean(value, [message])
  4599. *
  4600. * Asserts that `value` is a boolean.
  4601. *
  4602. * var teaReady = true
  4603. * , teaServed = false;
  4604. *
  4605. * assert.isBoolean(teaReady, 'is the tea ready');
  4606. * assert.isBoolean(teaServed, 'has tea been served');
  4607. *
  4608. * @name isBoolean
  4609. * @param {Mixed} value
  4610. * @param {String} message
  4611. * @namespace Assert
  4612. * @api public
  4613. */
  4614. assert.isBoolean = function (val, msg) {
  4615. new Assertion(val, msg, assert.isBoolean, true).to.be.a('boolean');
  4616. };
  4617. /**
  4618. * ### .isNotBoolean(value, [message])
  4619. *
  4620. * Asserts that `value` is _not_ a boolean.
  4621. *
  4622. * var teaReady = 'yep'
  4623. * , teaServed = 'nope';
  4624. *
  4625. * assert.isNotBoolean(teaReady, 'is the tea ready');
  4626. * assert.isNotBoolean(teaServed, 'has tea been served');
  4627. *
  4628. * @name isNotBoolean
  4629. * @param {Mixed} value
  4630. * @param {String} message
  4631. * @namespace Assert
  4632. * @api public
  4633. */
  4634. assert.isNotBoolean = function (val, msg) {
  4635. new Assertion(val, msg, assert.isNotBoolean, true).to.not.be.a('boolean');
  4636. };
  4637. /**
  4638. * ### .typeOf(value, name, [message])
  4639. *
  4640. * Asserts that `value`'s type is `name`, as determined by
  4641. * `Object.prototype.toString`.
  4642. *
  4643. * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
  4644. * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
  4645. * assert.typeOf('tea', 'string', 'we have a string');
  4646. * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
  4647. * assert.typeOf(null, 'null', 'we have a null');
  4648. * assert.typeOf(undefined, 'undefined', 'we have an undefined');
  4649. *
  4650. * @name typeOf
  4651. * @param {Mixed} value
  4652. * @param {String} name
  4653. * @param {String} message
  4654. * @namespace Assert
  4655. * @api public
  4656. */
  4657. assert.typeOf = function (val, type, msg) {
  4658. new Assertion(val, msg, assert.typeOf, true).to.be.a(type);
  4659. };
  4660. /**
  4661. * ### .notTypeOf(value, name, [message])
  4662. *
  4663. * Asserts that `value`'s type is _not_ `name`, as determined by
  4664. * `Object.prototype.toString`.
  4665. *
  4666. * assert.notTypeOf('tea', 'number', 'strings are not numbers');
  4667. *
  4668. * @name notTypeOf
  4669. * @param {Mixed} value
  4670. * @param {String} typeof name
  4671. * @param {String} message
  4672. * @namespace Assert
  4673. * @api public
  4674. */
  4675. assert.notTypeOf = function (val, type, msg) {
  4676. new Assertion(val, msg, assert.notTypeOf, true).to.not.be.a(type);
  4677. };
  4678. /**
  4679. * ### .instanceOf(object, constructor, [message])
  4680. *
  4681. * Asserts that `value` is an instance of `constructor`.
  4682. *
  4683. * var Tea = function (name) { this.name = name; }
  4684. * , chai = new Tea('chai');
  4685. *
  4686. * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
  4687. *
  4688. * @name instanceOf
  4689. * @param {Object} object
  4690. * @param {Constructor} constructor
  4691. * @param {String} message
  4692. * @namespace Assert
  4693. * @api public
  4694. */
  4695. assert.instanceOf = function (val, type, msg) {
  4696. new Assertion(val, msg, assert.instanceOf, true).to.be.instanceOf(type);
  4697. };
  4698. /**
  4699. * ### .notInstanceOf(object, constructor, [message])
  4700. *
  4701. * Asserts `value` is not an instance of `constructor`.
  4702. *
  4703. * var Tea = function (name) { this.name = name; }
  4704. * , chai = new String('chai');
  4705. *
  4706. * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
  4707. *
  4708. * @name notInstanceOf
  4709. * @param {Object} object
  4710. * @param {Constructor} constructor
  4711. * @param {String} message
  4712. * @namespace Assert
  4713. * @api public
  4714. */
  4715. assert.notInstanceOf = function (val, type, msg) {
  4716. new Assertion(val, msg, assert.notInstanceOf, true)
  4717. .to.not.be.instanceOf(type);
  4718. };
  4719. /**
  4720. * ### .include(haystack, needle, [message])
  4721. *
  4722. * Asserts that `haystack` includes `needle`. Can be used to assert the
  4723. * inclusion of a value in an array, a substring in a string, or a subset of
  4724. * properties in an object.
  4725. *
  4726. * assert.include([1,2,3], 2, 'array contains value');
  4727. * assert.include('foobar', 'foo', 'string contains substring');
  4728. * assert.include({ foo: 'bar', hello: 'universe' }, { foo: 'bar' }, 'object contains property');
  4729. *
  4730. * Strict equality (===) is used. When asserting the inclusion of a value in
  4731. * an array, the array is searched for an element that's strictly equal to the
  4732. * given value. When asserting a subset of properties in an object, the object
  4733. * is searched for the given property keys, checking that each one is present
  4734. * and strictly equal to the given property value. For instance:
  4735. *
  4736. * var obj1 = {a: 1}
  4737. * , obj2 = {b: 2};
  4738. * assert.include([obj1, obj2], obj1);
  4739. * assert.include({foo: obj1, bar: obj2}, {foo: obj1});
  4740. * assert.include({foo: obj1, bar: obj2}, {foo: obj1, bar: obj2});
  4741. *
  4742. * @name include
  4743. * @param {Array|String} haystack
  4744. * @param {Mixed} needle
  4745. * @param {String} message
  4746. * @namespace Assert
  4747. * @api public
  4748. */
  4749. assert.include = function (exp, inc, msg) {
  4750. new Assertion(exp, msg, assert.include, true).include(inc);
  4751. };
  4752. /**
  4753. * ### .notInclude(haystack, needle, [message])
  4754. *
  4755. * Asserts that `haystack` does not include `needle`. Can be used to assert
  4756. * the absence of a value in an array, a substring in a string, or a subset of
  4757. * properties in an object.
  4758. *
  4759. * assert.notInclude([1,2,3], 4, "array doesn't contain value");
  4760. * assert.notInclude('foobar', 'baz', "string doesn't contain substring");
  4761. * assert.notInclude({ foo: 'bar', hello: 'universe' }, { foo: 'baz' }, 'object doesn't contain property');
  4762. *
  4763. * Strict equality (===) is used. When asserting the absence of a value in an
  4764. * array, the array is searched to confirm the absence of an element that's
  4765. * strictly equal to the given value. When asserting a subset of properties in
  4766. * an object, the object is searched to confirm that at least one of the given
  4767. * property keys is either not present or not strictly equal to the given
  4768. * property value. For instance:
  4769. *
  4770. * var obj1 = {a: 1}
  4771. * , obj2 = {b: 2};
  4772. * assert.notInclude([obj1, obj2], {a: 1});
  4773. * assert.notInclude({foo: obj1, bar: obj2}, {foo: {a: 1}});
  4774. * assert.notInclude({foo: obj1, bar: obj2}, {foo: obj1, bar: {b: 2}});
  4775. *
  4776. * @name notInclude
  4777. * @param {Array|String} haystack
  4778. * @param {Mixed} needle
  4779. * @param {String} message
  4780. * @namespace Assert
  4781. * @api public
  4782. */
  4783. assert.notInclude = function (exp, inc, msg) {
  4784. new Assertion(exp, msg, assert.notInclude, true).not.include(inc);
  4785. };
  4786. /**
  4787. * ### .deepInclude(haystack, needle, [message])
  4788. *
  4789. * Asserts that `haystack` includes `needle`. Can be used to assert the
  4790. * inclusion of a value in an array or a subset of properties in an object.
  4791. * Deep equality is used.
  4792. *
  4793. * var obj1 = {a: 1}
  4794. * , obj2 = {b: 2};
  4795. * assert.deepInclude([obj1, obj2], {a: 1});
  4796. * assert.deepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}});
  4797. * assert.deepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}, bar: {b: 2}});
  4798. *
  4799. * @name deepInclude
  4800. * @param {Array|String} haystack
  4801. * @param {Mixed} needle
  4802. * @param {String} message
  4803. * @namespace Assert
  4804. * @api public
  4805. */
  4806. assert.deepInclude = function (exp, inc, msg) {
  4807. new Assertion(exp, msg, assert.deepInclude, true).deep.include(inc);
  4808. };
  4809. /**
  4810. * ### .notDeepInclude(haystack, needle, [message])
  4811. *
  4812. * Asserts that `haystack` does not include `needle`. Can be used to assert
  4813. * the absence of a value in an array or a subset of properties in an object.
  4814. * Deep equality is used.
  4815. *
  4816. * var obj1 = {a: 1}
  4817. * , obj2 = {b: 2};
  4818. * assert.notDeepInclude([obj1, obj2], {a: 9});
  4819. * assert.notDeepInclude({foo: obj1, bar: obj2}, {foo: {a: 9}});
  4820. * assert.notDeepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}, bar: {b: 9}});
  4821. *
  4822. * @name notDeepInclude
  4823. * @param {Array|String} haystack
  4824. * @param {Mixed} needle
  4825. * @param {String} message
  4826. * @namespace Assert
  4827. * @api public
  4828. */
  4829. assert.notDeepInclude = function (exp, inc, msg) {
  4830. new Assertion(exp, msg, assert.notDeepInclude, true).not.deep.include(inc);
  4831. };
  4832. /**
  4833. * ### .nestedInclude(haystack, needle, [message])
  4834. *
  4835. * Asserts that 'haystack' includes 'needle'.
  4836. * Can be used to assert the inclusion of a subset of properties in an
  4837. * object.
  4838. * Enables the use of dot- and bracket-notation for referencing nested
  4839. * properties.
  4840. * '[]' and '.' in property names can be escaped using double backslashes.
  4841. *
  4842. * assert.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'});
  4843. * assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'});
  4844. *
  4845. * @name nestedInclude
  4846. * @param {Object} haystack
  4847. * @param {Object} needle
  4848. * @param {String} message
  4849. * @namespace Assert
  4850. * @api public
  4851. */
  4852. assert.nestedInclude = function (exp, inc, msg) {
  4853. new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc);
  4854. };
  4855. /**
  4856. * ### .notNestedInclude(haystack, needle, [message])
  4857. *
  4858. * Asserts that 'haystack' does not include 'needle'.
  4859. * Can be used to assert the absence of a subset of properties in an
  4860. * object.
  4861. * Enables the use of dot- and bracket-notation for referencing nested
  4862. * properties.
  4863. * '[]' and '.' in property names can be escaped using double backslashes.
  4864. *
  4865. * assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'});
  4866. * assert.notNestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'y'});
  4867. *
  4868. * @name notNestedInclude
  4869. * @param {Object} haystack
  4870. * @param {Object} needle
  4871. * @param {String} message
  4872. * @namespace Assert
  4873. * @api public
  4874. */
  4875. assert.notNestedInclude = function (exp, inc, msg) {
  4876. new Assertion(exp, msg, assert.notNestedInclude, true)
  4877. .not.nested.include(inc);
  4878. };
  4879. /**
  4880. * ### .deepNestedInclude(haystack, needle, [message])
  4881. *
  4882. * Asserts that 'haystack' includes 'needle'.
  4883. * Can be used to assert the inclusion of a subset of properties in an
  4884. * object while checking for deep equality.
  4885. * Enables the use of dot- and bracket-notation for referencing nested
  4886. * properties.
  4887. * '[]' and '.' in property names can be escaped using double backslashes.
  4888. *
  4889. * assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}});
  4890. * assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}});
  4891. *
  4892. * @name deepNestedInclude
  4893. * @param {Object} haystack
  4894. * @param {Object} needle
  4895. * @param {String} message
  4896. * @namespace Assert
  4897. * @api public
  4898. */
  4899. assert.deepNestedInclude = function(exp, inc, msg) {
  4900. new Assertion(exp, msg, assert.deepNestedInclude, true)
  4901. .deep.nested.include(inc);
  4902. };
  4903. /**
  4904. * ### .notDeepNestedInclude(haystack, needle, [message])
  4905. *
  4906. * Asserts that 'haystack' does not include 'needle'.
  4907. * Can be used to assert the absence of a subset of properties in an
  4908. * object while checking for deep equality.
  4909. * Enables the use of dot- and bracket-notation for referencing nested
  4910. * properties.
  4911. * '[]' and '.' in property names can be escaped using double backslashes.
  4912. *
  4913. * assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}})
  4914. * assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}});
  4915. *
  4916. * @name notDeepNestedInclude
  4917. * @param {Object} haystack
  4918. * @param {Object} needle
  4919. * @param {String} message
  4920. * @namespace Assert
  4921. * @api public
  4922. */
  4923. assert.notDeepNestedInclude = function(exp, inc, msg) {
  4924. new Assertion(exp, msg, assert.notDeepNestedInclude, true)
  4925. .not.deep.nested.include(inc);
  4926. };
  4927. /**
  4928. * ### .ownInclude(haystack, needle, [message])
  4929. *
  4930. * Asserts that 'haystack' includes 'needle'.
  4931. * Can be used to assert the inclusion of a subset of properties in an
  4932. * object while ignoring inherited properties.
  4933. *
  4934. * assert.ownInclude({ a: 1 }, { a: 1 });
  4935. *
  4936. * @name ownInclude
  4937. * @param {Object} haystack
  4938. * @param {Object} needle
  4939. * @param {String} message
  4940. * @namespace Assert
  4941. * @api public
  4942. */
  4943. assert.ownInclude = function(exp, inc, msg) {
  4944. new Assertion(exp, msg, assert.ownInclude, true).own.include(inc);
  4945. };
  4946. /**
  4947. * ### .notOwnInclude(haystack, needle, [message])
  4948. *
  4949. * Asserts that 'haystack' includes 'needle'.
  4950. * Can be used to assert the absence of a subset of properties in an
  4951. * object while ignoring inherited properties.
  4952. *
  4953. * Object.prototype.b = 2;
  4954. *
  4955. * assert.notOwnInclude({ a: 1 }, { b: 2 });
  4956. *
  4957. * @name notOwnInclude
  4958. * @param {Object} haystack
  4959. * @param {Object} needle
  4960. * @param {String} message
  4961. * @namespace Assert
  4962. * @api public
  4963. */
  4964. assert.notOwnInclude = function(exp, inc, msg) {
  4965. new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc);
  4966. };
  4967. /**
  4968. * ### .deepOwnInclude(haystack, needle, [message])
  4969. *
  4970. * Asserts that 'haystack' includes 'needle'.
  4971. * Can be used to assert the inclusion of a subset of properties in an
  4972. * object while ignoring inherited properties and checking for deep equality.
  4973. *
  4974. * assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}});
  4975. *
  4976. * @name deepOwnInclude
  4977. * @param {Object} haystack
  4978. * @param {Object} needle
  4979. * @param {String} message
  4980. * @namespace Assert
  4981. * @api public
  4982. */
  4983. assert.deepOwnInclude = function(exp, inc, msg) {
  4984. new Assertion(exp, msg, assert.deepOwnInclude, true)
  4985. .deep.own.include(inc);
  4986. };
  4987. /**
  4988. * ### .notDeepOwnInclude(haystack, needle, [message])
  4989. *
  4990. * Asserts that 'haystack' includes 'needle'.
  4991. * Can be used to assert the absence of a subset of properties in an
  4992. * object while ignoring inherited properties and checking for deep equality.
  4993. *
  4994. * assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}});
  4995. *
  4996. * @name notDeepOwnInclude
  4997. * @param {Object} haystack
  4998. * @param {Object} needle
  4999. * @param {String} message
  5000. * @namespace Assert
  5001. * @api public
  5002. */
  5003. assert.notDeepOwnInclude = function(exp, inc, msg) {
  5004. new Assertion(exp, msg, assert.notDeepOwnInclude, true)
  5005. .not.deep.own.include(inc);
  5006. };
  5007. /**
  5008. * ### .match(value, regexp, [message])
  5009. *
  5010. * Asserts that `value` matches the regular expression `regexp`.
  5011. *
  5012. * assert.match('foobar', /^foo/, 'regexp matches');
  5013. *
  5014. * @name match
  5015. * @param {Mixed} value
  5016. * @param {RegExp} regexp
  5017. * @param {String} message
  5018. * @namespace Assert
  5019. * @api public
  5020. */
  5021. assert.match = function (exp, re, msg) {
  5022. new Assertion(exp, msg, assert.match, true).to.match(re);
  5023. };
  5024. /**
  5025. * ### .notMatch(value, regexp, [message])
  5026. *
  5027. * Asserts that `value` does not match the regular expression `regexp`.
  5028. *
  5029. * assert.notMatch('foobar', /^foo/, 'regexp does not match');
  5030. *
  5031. * @name notMatch
  5032. * @param {Mixed} value
  5033. * @param {RegExp} regexp
  5034. * @param {String} message
  5035. * @namespace Assert
  5036. * @api public
  5037. */
  5038. assert.notMatch = function (exp, re, msg) {
  5039. new Assertion(exp, msg, assert.notMatch, true).to.not.match(re);
  5040. };
  5041. /**
  5042. * ### .property(object, property, [message])
  5043. *
  5044. * Asserts that `object` has a direct or inherited property named by
  5045. * `property`.
  5046. *
  5047. * assert.property({ tea: { green: 'matcha' }}, 'tea');
  5048. * assert.property({ tea: { green: 'matcha' }}, 'toString');
  5049. *
  5050. * @name property
  5051. * @param {Object} object
  5052. * @param {String} property
  5053. * @param {String} message
  5054. * @namespace Assert
  5055. * @api public
  5056. */
  5057. assert.property = function (obj, prop, msg) {
  5058. new Assertion(obj, msg, assert.property, true).to.have.property(prop);
  5059. };
  5060. /**
  5061. * ### .notProperty(object, property, [message])
  5062. *
  5063. * Asserts that `object` does _not_ have a direct or inherited property named
  5064. * by `property`.
  5065. *
  5066. * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
  5067. *
  5068. * @name notProperty
  5069. * @param {Object} object
  5070. * @param {String} property
  5071. * @param {String} message
  5072. * @namespace Assert
  5073. * @api public
  5074. */
  5075. assert.notProperty = function (obj, prop, msg) {
  5076. new Assertion(obj, msg, assert.notProperty, true)
  5077. .to.not.have.property(prop);
  5078. };
  5079. /**
  5080. * ### .propertyVal(object, property, value, [message])
  5081. *
  5082. * Asserts that `object` has a direct or inherited property named by
  5083. * `property` with a value given by `value`. Uses a strict equality check
  5084. * (===).
  5085. *
  5086. * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
  5087. *
  5088. * @name propertyVal
  5089. * @param {Object} object
  5090. * @param {String} property
  5091. * @param {Mixed} value
  5092. * @param {String} message
  5093. * @namespace Assert
  5094. * @api public
  5095. */
  5096. assert.propertyVal = function (obj, prop, val, msg) {
  5097. new Assertion(obj, msg, assert.propertyVal, true)
  5098. .to.have.property(prop, val);
  5099. };
  5100. /**
  5101. * ### .notPropertyVal(object, property, value, [message])
  5102. *
  5103. * Asserts that `object` does _not_ have a direct or inherited property named
  5104. * by `property` with value given by `value`. Uses a strict equality check
  5105. * (===).
  5106. *
  5107. * assert.notPropertyVal({ tea: 'is good' }, 'tea', 'is bad');
  5108. * assert.notPropertyVal({ tea: 'is good' }, 'coffee', 'is good');
  5109. *
  5110. * @name notPropertyVal
  5111. * @param {Object} object
  5112. * @param {String} property
  5113. * @param {Mixed} value
  5114. * @param {String} message
  5115. * @namespace Assert
  5116. * @api public
  5117. */
  5118. assert.notPropertyVal = function (obj, prop, val, msg) {
  5119. new Assertion(obj, msg, assert.notPropertyVal, true)
  5120. .to.not.have.property(prop, val);
  5121. };
  5122. /**
  5123. * ### .deepPropertyVal(object, property, value, [message])
  5124. *
  5125. * Asserts that `object` has a direct or inherited property named by
  5126. * `property` with a value given by `value`. Uses a deep equality check.
  5127. *
  5128. * assert.deepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'matcha' });
  5129. *
  5130. * @name deepPropertyVal
  5131. * @param {Object} object
  5132. * @param {String} property
  5133. * @param {Mixed} value
  5134. * @param {String} message
  5135. * @namespace Assert
  5136. * @api public
  5137. */
  5138. assert.deepPropertyVal = function (obj, prop, val, msg) {
  5139. new Assertion(obj, msg, assert.deepPropertyVal, true)
  5140. .to.have.deep.property(prop, val);
  5141. };
  5142. /**
  5143. * ### .notDeepPropertyVal(object, property, value, [message])
  5144. *
  5145. * Asserts that `object` does _not_ have a direct or inherited property named
  5146. * by `property` with value given by `value`. Uses a deep equality check.
  5147. *
  5148. * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { black: 'matcha' });
  5149. * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'oolong' });
  5150. * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'coffee', { green: 'matcha' });
  5151. *
  5152. * @name notDeepPropertyVal
  5153. * @param {Object} object
  5154. * @param {String} property
  5155. * @param {Mixed} value
  5156. * @param {String} message
  5157. * @namespace Assert
  5158. * @api public
  5159. */
  5160. assert.notDeepPropertyVal = function (obj, prop, val, msg) {
  5161. new Assertion(obj, msg, assert.notDeepPropertyVal, true)
  5162. .to.not.have.deep.property(prop, val);
  5163. };
  5164. /**
  5165. * ### .ownProperty(object, property, [message])
  5166. *
  5167. * Asserts that `object` has a direct property named by `property`. Inherited
  5168. * properties aren't checked.
  5169. *
  5170. * assert.ownProperty({ tea: { green: 'matcha' }}, 'tea');
  5171. *
  5172. * @name ownProperty
  5173. * @param {Object} object
  5174. * @param {String} property
  5175. * @param {String} message
  5176. * @api public
  5177. */
  5178. assert.ownProperty = function (obj, prop, msg) {
  5179. new Assertion(obj, msg, assert.ownProperty, true)
  5180. .to.have.own.property(prop);
  5181. };
  5182. /**
  5183. * ### .notOwnProperty(object, property, [message])
  5184. *
  5185. * Asserts that `object` does _not_ have a direct property named by
  5186. * `property`. Inherited properties aren't checked.
  5187. *
  5188. * assert.notOwnProperty({ tea: { green: 'matcha' }}, 'coffee');
  5189. * assert.notOwnProperty({}, 'toString');
  5190. *
  5191. * @name notOwnProperty
  5192. * @param {Object} object
  5193. * @param {String} property
  5194. * @param {String} message
  5195. * @api public
  5196. */
  5197. assert.notOwnProperty = function (obj, prop, msg) {
  5198. new Assertion(obj, msg, assert.notOwnProperty, true)
  5199. .to.not.have.own.property(prop);
  5200. };
  5201. /**
  5202. * ### .ownPropertyVal(object, property, value, [message])
  5203. *
  5204. * Asserts that `object` has a direct property named by `property` and a value
  5205. * equal to the provided `value`. Uses a strict equality check (===).
  5206. * Inherited properties aren't checked.
  5207. *
  5208. * assert.ownPropertyVal({ coffee: 'is good'}, 'coffee', 'is good');
  5209. *
  5210. * @name ownPropertyVal
  5211. * @param {Object} object
  5212. * @param {String} property
  5213. * @param {Mixed} value
  5214. * @param {String} message
  5215. * @api public
  5216. */
  5217. assert.ownPropertyVal = function (obj, prop, value, msg) {
  5218. new Assertion(obj, msg, assert.ownPropertyVal, true)
  5219. .to.have.own.property(prop, value);
  5220. };
  5221. /**
  5222. * ### .notOwnPropertyVal(object, property, value, [message])
  5223. *
  5224. * Asserts that `object` does _not_ have a direct property named by `property`
  5225. * with a value equal to the provided `value`. Uses a strict equality check
  5226. * (===). Inherited properties aren't checked.
  5227. *
  5228. * assert.notOwnPropertyVal({ tea: 'is better'}, 'tea', 'is worse');
  5229. * assert.notOwnPropertyVal({}, 'toString', Object.prototype.toString);
  5230. *
  5231. * @name notOwnPropertyVal
  5232. * @param {Object} object
  5233. * @param {String} property
  5234. * @param {Mixed} value
  5235. * @param {String} message
  5236. * @api public
  5237. */
  5238. assert.notOwnPropertyVal = function (obj, prop, value, msg) {
  5239. new Assertion(obj, msg, assert.notOwnPropertyVal, true)
  5240. .to.not.have.own.property(prop, value);
  5241. };
  5242. /**
  5243. * ### .deepOwnPropertyVal(object, property, value, [message])
  5244. *
  5245. * Asserts that `object` has a direct property named by `property` and a value
  5246. * equal to the provided `value`. Uses a deep equality check. Inherited
  5247. * properties aren't checked.
  5248. *
  5249. * assert.deepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'matcha' });
  5250. *
  5251. * @name deepOwnPropertyVal
  5252. * @param {Object} object
  5253. * @param {String} property
  5254. * @param {Mixed} value
  5255. * @param {String} message
  5256. * @api public
  5257. */
  5258. assert.deepOwnPropertyVal = function (obj, prop, value, msg) {
  5259. new Assertion(obj, msg, assert.deepOwnPropertyVal, true)
  5260. .to.have.deep.own.property(prop, value);
  5261. };
  5262. /**
  5263. * ### .notDeepOwnPropertyVal(object, property, value, [message])
  5264. *
  5265. * Asserts that `object` does _not_ have a direct property named by `property`
  5266. * with a value equal to the provided `value`. Uses a deep equality check.
  5267. * Inherited properties aren't checked.
  5268. *
  5269. * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { black: 'matcha' });
  5270. * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'oolong' });
  5271. * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'coffee', { green: 'matcha' });
  5272. * assert.notDeepOwnPropertyVal({}, 'toString', Object.prototype.toString);
  5273. *
  5274. * @name notDeepOwnPropertyVal
  5275. * @param {Object} object
  5276. * @param {String} property
  5277. * @param {Mixed} value
  5278. * @param {String} message
  5279. * @api public
  5280. */
  5281. assert.notDeepOwnPropertyVal = function (obj, prop, value, msg) {
  5282. new Assertion(obj, msg, assert.notDeepOwnPropertyVal, true)
  5283. .to.not.have.deep.own.property(prop, value);
  5284. };
  5285. /**
  5286. * ### .nestedProperty(object, property, [message])
  5287. *
  5288. * Asserts that `object` has a direct or inherited property named by
  5289. * `property`, which can be a string using dot- and bracket-notation for
  5290. * nested reference.
  5291. *
  5292. * assert.nestedProperty({ tea: { green: 'matcha' }}, 'tea.green');
  5293. *
  5294. * @name nestedProperty
  5295. * @param {Object} object
  5296. * @param {String} property
  5297. * @param {String} message
  5298. * @namespace Assert
  5299. * @api public
  5300. */
  5301. assert.nestedProperty = function (obj, prop, msg) {
  5302. new Assertion(obj, msg, assert.nestedProperty, true)
  5303. .to.have.nested.property(prop);
  5304. };
  5305. /**
  5306. * ### .notNestedProperty(object, property, [message])
  5307. *
  5308. * Asserts that `object` does _not_ have a property named by `property`, which
  5309. * can be a string using dot- and bracket-notation for nested reference. The
  5310. * property cannot exist on the object nor anywhere in its prototype chain.
  5311. *
  5312. * assert.notNestedProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
  5313. *
  5314. * @name notNestedProperty
  5315. * @param {Object} object
  5316. * @param {String} property
  5317. * @param {String} message
  5318. * @namespace Assert
  5319. * @api public
  5320. */
  5321. assert.notNestedProperty = function (obj, prop, msg) {
  5322. new Assertion(obj, msg, assert.notNestedProperty, true)
  5323. .to.not.have.nested.property(prop);
  5324. };
  5325. /**
  5326. * ### .nestedPropertyVal(object, property, value, [message])
  5327. *
  5328. * Asserts that `object` has a property named by `property` with value given
  5329. * by `value`. `property` can use dot- and bracket-notation for nested
  5330. * reference. Uses a strict equality check (===).
  5331. *
  5332. * assert.nestedPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
  5333. *
  5334. * @name nestedPropertyVal
  5335. * @param {Object} object
  5336. * @param {String} property
  5337. * @param {Mixed} value
  5338. * @param {String} message
  5339. * @namespace Assert
  5340. * @api public
  5341. */
  5342. assert.nestedPropertyVal = function (obj, prop, val, msg) {
  5343. new Assertion(obj, msg, assert.nestedPropertyVal, true)
  5344. .to.have.nested.property(prop, val);
  5345. };
  5346. /**
  5347. * ### .notNestedPropertyVal(object, property, value, [message])
  5348. *
  5349. * Asserts that `object` does _not_ have a property named by `property` with
  5350. * value given by `value`. `property` can use dot- and bracket-notation for
  5351. * nested reference. Uses a strict equality check (===).
  5352. *
  5353. * assert.notNestedPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
  5354. * assert.notNestedPropertyVal({ tea: { green: 'matcha' }}, 'coffee.green', 'matcha');
  5355. *
  5356. * @name notNestedPropertyVal
  5357. * @param {Object} object
  5358. * @param {String} property
  5359. * @param {Mixed} value
  5360. * @param {String} message
  5361. * @namespace Assert
  5362. * @api public
  5363. */
  5364. assert.notNestedPropertyVal = function (obj, prop, val, msg) {
  5365. new Assertion(obj, msg, assert.notNestedPropertyVal, true)
  5366. .to.not.have.nested.property(prop, val);
  5367. };
  5368. /**
  5369. * ### .deepNestedPropertyVal(object, property, value, [message])
  5370. *
  5371. * Asserts that `object` has a property named by `property` with a value given
  5372. * by `value`. `property` can use dot- and bracket-notation for nested
  5373. * reference. Uses a deep equality check.
  5374. *
  5375. * assert.deepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { matcha: 'yum' });
  5376. *
  5377. * @name deepNestedPropertyVal
  5378. * @param {Object} object
  5379. * @param {String} property
  5380. * @param {Mixed} value
  5381. * @param {String} message
  5382. * @namespace Assert
  5383. * @api public
  5384. */
  5385. assert.deepNestedPropertyVal = function (obj, prop, val, msg) {
  5386. new Assertion(obj, msg, assert.deepNestedPropertyVal, true)
  5387. .to.have.deep.nested.property(prop, val);
  5388. };
  5389. /**
  5390. * ### .notDeepNestedPropertyVal(object, property, value, [message])
  5391. *
  5392. * Asserts that `object` does _not_ have a property named by `property` with
  5393. * value given by `value`. `property` can use dot- and bracket-notation for
  5394. * nested reference. Uses a deep equality check.
  5395. *
  5396. * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { oolong: 'yum' });
  5397. * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { matcha: 'yuck' });
  5398. * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.black', { matcha: 'yum' });
  5399. *
  5400. * @name notDeepNestedPropertyVal
  5401. * @param {Object} object
  5402. * @param {String} property
  5403. * @param {Mixed} value
  5404. * @param {String} message
  5405. * @namespace Assert
  5406. * @api public
  5407. */
  5408. assert.notDeepNestedPropertyVal = function (obj, prop, val, msg) {
  5409. new Assertion(obj, msg, assert.notDeepNestedPropertyVal, true)
  5410. .to.not.have.deep.nested.property(prop, val);
  5411. }
  5412. /**
  5413. * ### .lengthOf(object, length, [message])
  5414. *
  5415. * Asserts that `object` has a `length` or `size` with the expected value.
  5416. *
  5417. * assert.lengthOf([1,2,3], 3, 'array has length of 3');
  5418. * assert.lengthOf('foobar', 6, 'string has length of 6');
  5419. * assert.lengthOf(new Set([1,2,3]), 3, 'set has size of 3');
  5420. * assert.lengthOf(new Map([['a',1],['b',2],['c',3]]), 3, 'map has size of 3');
  5421. *
  5422. * @name lengthOf
  5423. * @param {Mixed} object
  5424. * @param {Number} length
  5425. * @param {String} message
  5426. * @namespace Assert
  5427. * @api public
  5428. */
  5429. assert.lengthOf = function (exp, len, msg) {
  5430. new Assertion(exp, msg, assert.lengthOf, true).to.have.lengthOf(len);
  5431. };
  5432. /**
  5433. * ### .hasAnyKeys(object, [keys], [message])
  5434. *
  5435. * Asserts that `object` has at least one of the `keys` provided.
  5436. * You can also provide a single object instead of a `keys` array and its keys
  5437. * will be used as the expected set of keys.
  5438. *
  5439. * assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'iDontExist', 'baz']);
  5440. * assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, iDontExist: 99, baz: 1337});
  5441. * assert.hasAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
  5442. * assert.hasAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
  5443. *
  5444. * @name hasAnyKeys
  5445. * @param {Mixed} object
  5446. * @param {Array|Object} keys
  5447. * @param {String} message
  5448. * @namespace Assert
  5449. * @api public
  5450. */
  5451. assert.hasAnyKeys = function (obj, keys, msg) {
  5452. new Assertion(obj, msg, assert.hasAnyKeys, true).to.have.any.keys(keys);
  5453. }
  5454. /**
  5455. * ### .hasAllKeys(object, [keys], [message])
  5456. *
  5457. * Asserts that `object` has all and only all of the `keys` provided.
  5458. * You can also provide a single object instead of a `keys` array and its keys
  5459. * will be used as the expected set of keys.
  5460. *
  5461. * assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']);
  5462. * assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337]);
  5463. * assert.hasAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
  5464. * assert.hasAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}, 'anotherKey']);
  5465. *
  5466. * @name hasAllKeys
  5467. * @param {Mixed} object
  5468. * @param {String[]} keys
  5469. * @param {String} message
  5470. * @namespace Assert
  5471. * @api public
  5472. */
  5473. assert.hasAllKeys = function (obj, keys, msg) {
  5474. new Assertion(obj, msg, assert.hasAllKeys, true).to.have.all.keys(keys);
  5475. }
  5476. /**
  5477. * ### .containsAllKeys(object, [keys], [message])
  5478. *
  5479. * Asserts that `object` has all of the `keys` provided but may have more keys not listed.
  5480. * You can also provide a single object instead of a `keys` array and its keys
  5481. * will be used as the expected set of keys.
  5482. *
  5483. * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'baz']);
  5484. * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']);
  5485. * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, baz: 1337});
  5486. * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337});
  5487. * assert.containsAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}]);
  5488. * assert.containsAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
  5489. * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}]);
  5490. * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}, 'anotherKey']);
  5491. *
  5492. * @name containsAllKeys
  5493. * @param {Mixed} object
  5494. * @param {String[]} keys
  5495. * @param {String} message
  5496. * @namespace Assert
  5497. * @api public
  5498. */
  5499. assert.containsAllKeys = function (obj, keys, msg) {
  5500. new Assertion(obj, msg, assert.containsAllKeys, true)
  5501. .to.contain.all.keys(keys);
  5502. }
  5503. /**
  5504. * ### .doesNotHaveAnyKeys(object, [keys], [message])
  5505. *
  5506. * Asserts that `object` has none of the `keys` provided.
  5507. * You can also provide a single object instead of a `keys` array and its keys
  5508. * will be used as the expected set of keys.
  5509. *
  5510. * assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']);
  5511. * assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'});
  5512. * assert.doesNotHaveAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']);
  5513. * assert.doesNotHaveAnyKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{one: 'two'}, 'example']);
  5514. *
  5515. * @name doesNotHaveAnyKeys
  5516. * @param {Mixed} object
  5517. * @param {String[]} keys
  5518. * @param {String} message
  5519. * @namespace Assert
  5520. * @api public
  5521. */
  5522. assert.doesNotHaveAnyKeys = function (obj, keys, msg) {
  5523. new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true)
  5524. .to.not.have.any.keys(keys);
  5525. }
  5526. /**
  5527. * ### .doesNotHaveAllKeys(object, [keys], [message])
  5528. *
  5529. * Asserts that `object` does not have at least one of the `keys` provided.
  5530. * You can also provide a single object instead of a `keys` array and its keys
  5531. * will be used as the expected set of keys.
  5532. *
  5533. * assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']);
  5534. * assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'});
  5535. * assert.doesNotHaveAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']);
  5536. * assert.doesNotHaveAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{one: 'two'}, 'example']);
  5537. *
  5538. * @name doesNotHaveAllKeys
  5539. * @param {Mixed} object
  5540. * @param {String[]} keys
  5541. * @param {String} message
  5542. * @namespace Assert
  5543. * @api public
  5544. */
  5545. assert.doesNotHaveAllKeys = function (obj, keys, msg) {
  5546. new Assertion(obj, msg, assert.doesNotHaveAllKeys, true)
  5547. .to.not.have.all.keys(keys);
  5548. }
  5549. /**
  5550. * ### .hasAnyDeepKeys(object, [keys], [message])
  5551. *
  5552. * Asserts that `object` has at least one of the `keys` provided.
  5553. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5554. * a deep comparison.
  5555. * You can also provide a single object instead of a `keys` array and its keys
  5556. * will be used as the expected set of keys.
  5557. *
  5558. * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {one: 'one'});
  5559. * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), [{one: 'one'}, {two: 'two'}]);
  5560. * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
  5561. * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {one: 'one'});
  5562. * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {three: 'three'}]);
  5563. * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
  5564. *
  5565. * @name hasAnyDeepKeys
  5566. * @param {Mixed} object
  5567. * @param {Array|Object} keys
  5568. * @param {String} message
  5569. * @namespace Assert
  5570. * @api public
  5571. */
  5572. assert.hasAnyDeepKeys = function (obj, keys, msg) {
  5573. new Assertion(obj, msg, assert.hasAnyDeepKeys, true)
  5574. .to.have.any.deep.keys(keys);
  5575. }
  5576. /**
  5577. * ### .hasAllDeepKeys(object, [keys], [message])
  5578. *
  5579. * Asserts that `object` has all and only all of the `keys` provided.
  5580. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5581. * a deep comparison.
  5582. * You can also provide a single object instead of a `keys` array and its keys
  5583. * will be used as the expected set of keys.
  5584. *
  5585. * assert.hasAllDeepKeys(new Map([[{one: 'one'}, 'valueOne']]), {one: 'one'});
  5586. * assert.hasAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
  5587. * assert.hasAllDeepKeys(new Set([{one: 'one'}]), {one: 'one'});
  5588. * assert.hasAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
  5589. *
  5590. * @name hasAllDeepKeys
  5591. * @param {Mixed} object
  5592. * @param {Array|Object} keys
  5593. * @param {String} message
  5594. * @namespace Assert
  5595. * @api public
  5596. */
  5597. assert.hasAllDeepKeys = function (obj, keys, msg) {
  5598. new Assertion(obj, msg, assert.hasAllDeepKeys, true)
  5599. .to.have.all.deep.keys(keys);
  5600. }
  5601. /**
  5602. * ### .containsAllDeepKeys(object, [keys], [message])
  5603. *
  5604. * Asserts that `object` contains all of the `keys` provided.
  5605. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5606. * a deep comparison.
  5607. * You can also provide a single object instead of a `keys` array and its keys
  5608. * will be used as the expected set of keys.
  5609. *
  5610. * assert.containsAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {one: 'one'});
  5611. * assert.containsAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
  5612. * assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {one: 'one'});
  5613. * assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
  5614. *
  5615. * @name containsAllDeepKeys
  5616. * @param {Mixed} object
  5617. * @param {Array|Object} keys
  5618. * @param {String} message
  5619. * @namespace Assert
  5620. * @api public
  5621. */
  5622. assert.containsAllDeepKeys = function (obj, keys, msg) {
  5623. new Assertion(obj, msg, assert.containsAllDeepKeys, true)
  5624. .to.contain.all.deep.keys(keys);
  5625. }
  5626. /**
  5627. * ### .doesNotHaveAnyDeepKeys(object, [keys], [message])
  5628. *
  5629. * Asserts that `object` has none of the `keys` provided.
  5630. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5631. * a deep comparison.
  5632. * You can also provide a single object instead of a `keys` array and its keys
  5633. * will be used as the expected set of keys.
  5634. *
  5635. * assert.doesNotHaveAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {thisDoesNot: 'exist'});
  5636. * assert.doesNotHaveAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{twenty: 'twenty'}, {fifty: 'fifty'}]);
  5637. * assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {twenty: 'twenty'});
  5638. * assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{twenty: 'twenty'}, {fifty: 'fifty'}]);
  5639. *
  5640. * @name doesNotHaveAnyDeepKeys
  5641. * @param {Mixed} object
  5642. * @param {Array|Object} keys
  5643. * @param {String} message
  5644. * @namespace Assert
  5645. * @api public
  5646. */
  5647. assert.doesNotHaveAnyDeepKeys = function (obj, keys, msg) {
  5648. new Assertion(obj, msg, assert.doesNotHaveAnyDeepKeys, true)
  5649. .to.not.have.any.deep.keys(keys);
  5650. }
  5651. /**
  5652. * ### .doesNotHaveAllDeepKeys(object, [keys], [message])
  5653. *
  5654. * Asserts that `object` does not have at least one of the `keys` provided.
  5655. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5656. * a deep comparison.
  5657. * You can also provide a single object instead of a `keys` array and its keys
  5658. * will be used as the expected set of keys.
  5659. *
  5660. * assert.doesNotHaveAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {thisDoesNot: 'exist'});
  5661. * assert.doesNotHaveAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{twenty: 'twenty'}, {one: 'one'}]);
  5662. * assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {twenty: 'twenty'});
  5663. * assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {fifty: 'fifty'}]);
  5664. *
  5665. * @name doesNotHaveAllDeepKeys
  5666. * @param {Mixed} object
  5667. * @param {Array|Object} keys
  5668. * @param {String} message
  5669. * @namespace Assert
  5670. * @api public
  5671. */
  5672. assert.doesNotHaveAllDeepKeys = function (obj, keys, msg) {
  5673. new Assertion(obj, msg, assert.doesNotHaveAllDeepKeys, true)
  5674. .to.not.have.all.deep.keys(keys);
  5675. }
  5676. /**
  5677. * ### .throws(fn, [errorLike/string/regexp], [string/regexp], [message])
  5678. *
  5679. * If `errorLike` is an `Error` constructor, asserts that `fn` will throw an error that is an
  5680. * instance of `errorLike`.
  5681. * If `errorLike` is an `Error` instance, asserts that the error thrown is the same
  5682. * instance as `errorLike`.
  5683. * If `errMsgMatcher` is provided, it also asserts that the error thrown will have a
  5684. * message matching `errMsgMatcher`.
  5685. *
  5686. * assert.throws(fn, 'Error thrown must have this msg');
  5687. * assert.throws(fn, /Error thrown must have a msg that matches this/);
  5688. * assert.throws(fn, ReferenceError);
  5689. * assert.throws(fn, errorInstance);
  5690. * assert.throws(fn, ReferenceError, 'Error thrown must be a ReferenceError and have this msg');
  5691. * assert.throws(fn, errorInstance, 'Error thrown must be the same errorInstance and have this msg');
  5692. * assert.throws(fn, ReferenceError, /Error thrown must be a ReferenceError and match this/);
  5693. * assert.throws(fn, errorInstance, /Error thrown must be the same errorInstance and match this/);
  5694. *
  5695. * @name throws
  5696. * @alias throw
  5697. * @alias Throw
  5698. * @param {Function} fn
  5699. * @param {ErrorConstructor|Error} errorLike
  5700. * @param {RegExp|String} errMsgMatcher
  5701. * @param {String} message
  5702. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  5703. * @namespace Assert
  5704. * @api public
  5705. */
  5706. assert.throws = function (fn, errorLike, errMsgMatcher, msg) {
  5707. if ('string' === typeof errorLike || errorLike instanceof RegExp) {
  5708. errMsgMatcher = errorLike;
  5709. errorLike = null;
  5710. }
  5711. var assertErr = new Assertion(fn, msg, assert.throws, true)
  5712. .to.throw(errorLike, errMsgMatcher);
  5713. return flag(assertErr, 'object');
  5714. };
  5715. /**
  5716. * ### .doesNotThrow(fn, [errorLike/string/regexp], [string/regexp], [message])
  5717. *
  5718. * If `errorLike` is an `Error` constructor, asserts that `fn` will _not_ throw an error that is an
  5719. * instance of `errorLike`.
  5720. * If `errorLike` is an `Error` instance, asserts that the error thrown is _not_ the same
  5721. * instance as `errorLike`.
  5722. * If `errMsgMatcher` is provided, it also asserts that the error thrown will _not_ have a
  5723. * message matching `errMsgMatcher`.
  5724. *
  5725. * assert.doesNotThrow(fn, 'Any Error thrown must not have this message');
  5726. * assert.doesNotThrow(fn, /Any Error thrown must not match this/);
  5727. * assert.doesNotThrow(fn, Error);
  5728. * assert.doesNotThrow(fn, errorInstance);
  5729. * assert.doesNotThrow(fn, Error, 'Error must not have this message');
  5730. * assert.doesNotThrow(fn, errorInstance, 'Error must not have this message');
  5731. * assert.doesNotThrow(fn, Error, /Error must not match this/);
  5732. * assert.doesNotThrow(fn, errorInstance, /Error must not match this/);
  5733. *
  5734. * @name doesNotThrow
  5735. * @param {Function} fn
  5736. * @param {ErrorConstructor} errorLike
  5737. * @param {RegExp|String} errMsgMatcher
  5738. * @param {String} message
  5739. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  5740. * @namespace Assert
  5741. * @api public
  5742. */
  5743. assert.doesNotThrow = function (fn, errorLike, errMsgMatcher, msg) {
  5744. if ('string' === typeof errorLike || errorLike instanceof RegExp) {
  5745. errMsgMatcher = errorLike;
  5746. errorLike = null;
  5747. }
  5748. new Assertion(fn, msg, assert.doesNotThrow, true)
  5749. .to.not.throw(errorLike, errMsgMatcher);
  5750. };
  5751. /**
  5752. * ### .operator(val1, operator, val2, [message])
  5753. *
  5754. * Compares two values using `operator`.
  5755. *
  5756. * assert.operator(1, '<', 2, 'everything is ok');
  5757. * assert.operator(1, '>', 2, 'this will fail');
  5758. *
  5759. * @name operator
  5760. * @param {Mixed} val1
  5761. * @param {String} operator
  5762. * @param {Mixed} val2
  5763. * @param {String} message
  5764. * @namespace Assert
  5765. * @api public
  5766. */
  5767. assert.operator = function (val, operator, val2, msg) {
  5768. var ok;
  5769. switch(operator) {
  5770. case '==':
  5771. ok = val == val2;
  5772. break;
  5773. case '===':
  5774. ok = val === val2;
  5775. break;
  5776. case '>':
  5777. ok = val > val2;
  5778. break;
  5779. case '>=':
  5780. ok = val >= val2;
  5781. break;
  5782. case '<':
  5783. ok = val < val2;
  5784. break;
  5785. case '<=':
  5786. ok = val <= val2;
  5787. break;
  5788. case '!=':
  5789. ok = val != val2;
  5790. break;
  5791. case '!==':
  5792. ok = val !== val2;
  5793. break;
  5794. default:
  5795. msg = msg ? msg + ': ' : msg;
  5796. throw new chai.AssertionError(
  5797. msg + 'Invalid operator "' + operator + '"',
  5798. undefined,
  5799. assert.operator
  5800. );
  5801. }
  5802. var test = new Assertion(ok, msg, assert.operator, true);
  5803. test.assert(
  5804. true === flag(test, 'object')
  5805. , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
  5806. , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
  5807. };
  5808. /**
  5809. * ### .closeTo(actual, expected, delta, [message])
  5810. *
  5811. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  5812. *
  5813. * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
  5814. *
  5815. * @name closeTo
  5816. * @param {Number} actual
  5817. * @param {Number} expected
  5818. * @param {Number} delta
  5819. * @param {String} message
  5820. * @namespace Assert
  5821. * @api public
  5822. */
  5823. assert.closeTo = function (act, exp, delta, msg) {
  5824. new Assertion(act, msg, assert.closeTo, true).to.be.closeTo(exp, delta);
  5825. };
  5826. /**
  5827. * ### .approximately(actual, expected, delta, [message])
  5828. *
  5829. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  5830. *
  5831. * assert.approximately(1.5, 1, 0.5, 'numbers are close');
  5832. *
  5833. * @name approximately
  5834. * @param {Number} actual
  5835. * @param {Number} expected
  5836. * @param {Number} delta
  5837. * @param {String} message
  5838. * @namespace Assert
  5839. * @api public
  5840. */
  5841. assert.approximately = function (act, exp, delta, msg) {
  5842. new Assertion(act, msg, assert.approximately, true)
  5843. .to.be.approximately(exp, delta);
  5844. };
  5845. /**
  5846. * ### .sameMembers(set1, set2, [message])
  5847. *
  5848. * Asserts that `set1` and `set2` have the same members in any order. Uses a
  5849. * strict equality check (===).
  5850. *
  5851. * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
  5852. *
  5853. * @name sameMembers
  5854. * @param {Array} set1
  5855. * @param {Array} set2
  5856. * @param {String} message
  5857. * @namespace Assert
  5858. * @api public
  5859. */
  5860. assert.sameMembers = function (set1, set2, msg) {
  5861. new Assertion(set1, msg, assert.sameMembers, true)
  5862. .to.have.same.members(set2);
  5863. }
  5864. /**
  5865. * ### .notSameMembers(set1, set2, [message])
  5866. *
  5867. * Asserts that `set1` and `set2` don't have the same members in any order.
  5868. * Uses a strict equality check (===).
  5869. *
  5870. * assert.notSameMembers([ 1, 2, 3 ], [ 5, 1, 3 ], 'not same members');
  5871. *
  5872. * @name notSameMembers
  5873. * @param {Array} set1
  5874. * @param {Array} set2
  5875. * @param {String} message
  5876. * @namespace Assert
  5877. * @api public
  5878. */
  5879. assert.notSameMembers = function (set1, set2, msg) {
  5880. new Assertion(set1, msg, assert.notSameMembers, true)
  5881. .to.not.have.same.members(set2);
  5882. }
  5883. /**
  5884. * ### .sameDeepMembers(set1, set2, [message])
  5885. *
  5886. * Asserts that `set1` and `set2` have the same members in any order. Uses a
  5887. * deep equality check.
  5888. *
  5889. * assert.sameDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [{ b: 2 }, { a: 1 }, { c: 3 }], 'same deep members');
  5890. *
  5891. * @name sameDeepMembers
  5892. * @param {Array} set1
  5893. * @param {Array} set2
  5894. * @param {String} message
  5895. * @namespace Assert
  5896. * @api public
  5897. */
  5898. assert.sameDeepMembers = function (set1, set2, msg) {
  5899. new Assertion(set1, msg, assert.sameDeepMembers, true)
  5900. .to.have.same.deep.members(set2);
  5901. }
  5902. /**
  5903. * ### .notSameDeepMembers(set1, set2, [message])
  5904. *
  5905. * Asserts that `set1` and `set2` don't have the same members in any order.
  5906. * Uses a deep equality check.
  5907. *
  5908. * assert.notSameDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [{ b: 2 }, { a: 1 }, { f: 5 }], 'not same deep members');
  5909. *
  5910. * @name notSameDeepMembers
  5911. * @param {Array} set1
  5912. * @param {Array} set2
  5913. * @param {String} message
  5914. * @namespace Assert
  5915. * @api public
  5916. */
  5917. assert.notSameDeepMembers = function (set1, set2, msg) {
  5918. new Assertion(set1, msg, assert.notSameDeepMembers, true)
  5919. .to.not.have.same.deep.members(set2);
  5920. }
  5921. /**
  5922. * ### .sameOrderedMembers(set1, set2, [message])
  5923. *
  5924. * Asserts that `set1` and `set2` have the same members in the same order.
  5925. * Uses a strict equality check (===).
  5926. *
  5927. * assert.sameOrderedMembers([ 1, 2, 3 ], [ 1, 2, 3 ], 'same ordered members');
  5928. *
  5929. * @name sameOrderedMembers
  5930. * @param {Array} set1
  5931. * @param {Array} set2
  5932. * @param {String} message
  5933. * @namespace Assert
  5934. * @api public
  5935. */
  5936. assert.sameOrderedMembers = function (set1, set2, msg) {
  5937. new Assertion(set1, msg, assert.sameOrderedMembers, true)
  5938. .to.have.same.ordered.members(set2);
  5939. }
  5940. /**
  5941. * ### .notSameOrderedMembers(set1, set2, [message])
  5942. *
  5943. * Asserts that `set1` and `set2` don't have the same members in the same
  5944. * order. Uses a strict equality check (===).
  5945. *
  5946. * assert.notSameOrderedMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'not same ordered members');
  5947. *
  5948. * @name notSameOrderedMembers
  5949. * @param {Array} set1
  5950. * @param {Array} set2
  5951. * @param {String} message
  5952. * @namespace Assert
  5953. * @api public
  5954. */
  5955. assert.notSameOrderedMembers = function (set1, set2, msg) {
  5956. new Assertion(set1, msg, assert.notSameOrderedMembers, true)
  5957. .to.not.have.same.ordered.members(set2);
  5958. }
  5959. /**
  5960. * ### .sameDeepOrderedMembers(set1, set2, [message])
  5961. *
  5962. * Asserts that `set1` and `set2` have the same members in the same order.
  5963. * Uses a deep equality check.
  5964. *
  5965. * assert.sameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { c: 3 } ], 'same deep ordered members');
  5966. *
  5967. * @name sameDeepOrderedMembers
  5968. * @param {Array} set1
  5969. * @param {Array} set2
  5970. * @param {String} message
  5971. * @namespace Assert
  5972. * @api public
  5973. */
  5974. assert.sameDeepOrderedMembers = function (set1, set2, msg) {
  5975. new Assertion(set1, msg, assert.sameDeepOrderedMembers, true)
  5976. .to.have.same.deep.ordered.members(set2);
  5977. }
  5978. /**
  5979. * ### .notSameDeepOrderedMembers(set1, set2, [message])
  5980. *
  5981. * Asserts that `set1` and `set2` don't have the same members in the same
  5982. * order. Uses a deep equality check.
  5983. *
  5984. * assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { z: 5 } ], 'not same deep ordered members');
  5985. * assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 }, { c: 3 } ], 'not same deep ordered members');
  5986. *
  5987. * @name notSameDeepOrderedMembers
  5988. * @param {Array} set1
  5989. * @param {Array} set2
  5990. * @param {String} message
  5991. * @namespace Assert
  5992. * @api public
  5993. */
  5994. assert.notSameDeepOrderedMembers = function (set1, set2, msg) {
  5995. new Assertion(set1, msg, assert.notSameDeepOrderedMembers, true)
  5996. .to.not.have.same.deep.ordered.members(set2);
  5997. }
  5998. /**
  5999. * ### .includeMembers(superset, subset, [message])
  6000. *
  6001. * Asserts that `subset` is included in `superset` in any order. Uses a
  6002. * strict equality check (===). Duplicates are ignored.
  6003. *
  6004. * assert.includeMembers([ 1, 2, 3 ], [ 2, 1, 2 ], 'include members');
  6005. *
  6006. * @name includeMembers
  6007. * @param {Array} superset
  6008. * @param {Array} subset
  6009. * @param {String} message
  6010. * @namespace Assert
  6011. * @api public
  6012. */
  6013. assert.includeMembers = function (superset, subset, msg) {
  6014. new Assertion(superset, msg, assert.includeMembers, true)
  6015. .to.include.members(subset);
  6016. }
  6017. /**
  6018. * ### .notIncludeMembers(superset, subset, [message])
  6019. *
  6020. * Asserts that `subset` isn't included in `superset` in any order. Uses a
  6021. * strict equality check (===). Duplicates are ignored.
  6022. *
  6023. * assert.notIncludeMembers([ 1, 2, 3 ], [ 5, 1 ], 'not include members');
  6024. *
  6025. * @name notIncludeMembers
  6026. * @param {Array} superset
  6027. * @param {Array} subset
  6028. * @param {String} message
  6029. * @namespace Assert
  6030. * @api public
  6031. */
  6032. assert.notIncludeMembers = function (superset, subset, msg) {
  6033. new Assertion(superset, msg, assert.notIncludeMembers, true)
  6034. .to.not.include.members(subset);
  6035. }
  6036. /**
  6037. * ### .includeDeepMembers(superset, subset, [message])
  6038. *
  6039. * Asserts that `subset` is included in `superset` in any order. Uses a deep
  6040. * equality check. Duplicates are ignored.
  6041. *
  6042. * assert.includeDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 }, { b: 2 } ], 'include deep members');
  6043. *
  6044. * @name includeDeepMembers
  6045. * @param {Array} superset
  6046. * @param {Array} subset
  6047. * @param {String} message
  6048. * @namespace Assert
  6049. * @api public
  6050. */
  6051. assert.includeDeepMembers = function (superset, subset, msg) {
  6052. new Assertion(superset, msg, assert.includeDeepMembers, true)
  6053. .to.include.deep.members(subset);
  6054. }
  6055. /**
  6056. * ### .notIncludeDeepMembers(superset, subset, [message])
  6057. *
  6058. * Asserts that `subset` isn't included in `superset` in any order. Uses a
  6059. * deep equality check. Duplicates are ignored.
  6060. *
  6061. * assert.notIncludeDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { f: 5 } ], 'not include deep members');
  6062. *
  6063. * @name notIncludeDeepMembers
  6064. * @param {Array} superset
  6065. * @param {Array} subset
  6066. * @param {String} message
  6067. * @namespace Assert
  6068. * @api public
  6069. */
  6070. assert.notIncludeDeepMembers = function (superset, subset, msg) {
  6071. new Assertion(superset, msg, assert.notIncludeDeepMembers, true)
  6072. .to.not.include.deep.members(subset);
  6073. }
  6074. /**
  6075. * ### .includeOrderedMembers(superset, subset, [message])
  6076. *
  6077. * Asserts that `subset` is included in `superset` in the same order
  6078. * beginning with the first element in `superset`. Uses a strict equality
  6079. * check (===).
  6080. *
  6081. * assert.includeOrderedMembers([ 1, 2, 3 ], [ 1, 2 ], 'include ordered members');
  6082. *
  6083. * @name includeOrderedMembers
  6084. * @param {Array} superset
  6085. * @param {Array} subset
  6086. * @param {String} message
  6087. * @namespace Assert
  6088. * @api public
  6089. */
  6090. assert.includeOrderedMembers = function (superset, subset, msg) {
  6091. new Assertion(superset, msg, assert.includeOrderedMembers, true)
  6092. .to.include.ordered.members(subset);
  6093. }
  6094. /**
  6095. * ### .notIncludeOrderedMembers(superset, subset, [message])
  6096. *
  6097. * Asserts that `subset` isn't included in `superset` in the same order
  6098. * beginning with the first element in `superset`. Uses a strict equality
  6099. * check (===).
  6100. *
  6101. * assert.notIncludeOrderedMembers([ 1, 2, 3 ], [ 2, 1 ], 'not include ordered members');
  6102. * assert.notIncludeOrderedMembers([ 1, 2, 3 ], [ 2, 3 ], 'not include ordered members');
  6103. *
  6104. * @name notIncludeOrderedMembers
  6105. * @param {Array} superset
  6106. * @param {Array} subset
  6107. * @param {String} message
  6108. * @namespace Assert
  6109. * @api public
  6110. */
  6111. assert.notIncludeOrderedMembers = function (superset, subset, msg) {
  6112. new Assertion(superset, msg, assert.notIncludeOrderedMembers, true)
  6113. .to.not.include.ordered.members(subset);
  6114. }
  6115. /**
  6116. * ### .includeDeepOrderedMembers(superset, subset, [message])
  6117. *
  6118. * Asserts that `subset` is included in `superset` in the same order
  6119. * beginning with the first element in `superset`. Uses a deep equality
  6120. * check.
  6121. *
  6122. * assert.includeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 } ], 'include deep ordered members');
  6123. *
  6124. * @name includeDeepOrderedMembers
  6125. * @param {Array} superset
  6126. * @param {Array} subset
  6127. * @param {String} message
  6128. * @namespace Assert
  6129. * @api public
  6130. */
  6131. assert.includeDeepOrderedMembers = function (superset, subset, msg) {
  6132. new Assertion(superset, msg, assert.includeDeepOrderedMembers, true)
  6133. .to.include.deep.ordered.members(subset);
  6134. }
  6135. /**
  6136. * ### .notIncludeDeepOrderedMembers(superset, subset, [message])
  6137. *
  6138. * Asserts that `subset` isn't included in `superset` in the same order
  6139. * beginning with the first element in `superset`. Uses a deep equality
  6140. * check.
  6141. *
  6142. * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { f: 5 } ], 'not include deep ordered members');
  6143. * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 } ], 'not include deep ordered members');
  6144. * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { c: 3 } ], 'not include deep ordered members');
  6145. *
  6146. * @name notIncludeDeepOrderedMembers
  6147. * @param {Array} superset
  6148. * @param {Array} subset
  6149. * @param {String} message
  6150. * @namespace Assert
  6151. * @api public
  6152. */
  6153. assert.notIncludeDeepOrderedMembers = function (superset, subset, msg) {
  6154. new Assertion(superset, msg, assert.notIncludeDeepOrderedMembers, true)
  6155. .to.not.include.deep.ordered.members(subset);
  6156. }
  6157. /**
  6158. * ### .oneOf(inList, list, [message])
  6159. *
  6160. * Asserts that non-object, non-array value `inList` appears in the flat array `list`.
  6161. *
  6162. * assert.oneOf(1, [ 2, 1 ], 'Not found in list');
  6163. *
  6164. * @name oneOf
  6165. * @param {*} inList
  6166. * @param {Array<*>} list
  6167. * @param {String} message
  6168. * @namespace Assert
  6169. * @api public
  6170. */
  6171. assert.oneOf = function (inList, list, msg) {
  6172. new Assertion(inList, msg, assert.oneOf, true).to.be.oneOf(list);
  6173. }
  6174. /**
  6175. * ### .changes(function, object, property, [message])
  6176. *
  6177. * Asserts that a function changes the value of a property.
  6178. *
  6179. * var obj = { val: 10 };
  6180. * var fn = function() { obj.val = 22 };
  6181. * assert.changes(fn, obj, 'val');
  6182. *
  6183. * @name changes
  6184. * @param {Function} modifier function
  6185. * @param {Object} object or getter function
  6186. * @param {String} property name _optional_
  6187. * @param {String} message _optional_
  6188. * @namespace Assert
  6189. * @api public
  6190. */
  6191. assert.changes = function (fn, obj, prop, msg) {
  6192. if (arguments.length === 3 && typeof obj === 'function') {
  6193. msg = prop;
  6194. prop = null;
  6195. }
  6196. new Assertion(fn, msg, assert.changes, true).to.change(obj, prop);
  6197. }
  6198. /**
  6199. * ### .changesBy(function, object, property, delta, [message])
  6200. *
  6201. * Asserts that a function changes the value of a property by an amount (delta).
  6202. *
  6203. * var obj = { val: 10 };
  6204. * var fn = function() { obj.val += 2 };
  6205. * assert.changesBy(fn, obj, 'val', 2);
  6206. *
  6207. * @name changesBy
  6208. * @param {Function} modifier function
  6209. * @param {Object} object or getter function
  6210. * @param {String} property name _optional_
  6211. * @param {Number} change amount (delta)
  6212. * @param {String} message _optional_
  6213. * @namespace Assert
  6214. * @api public
  6215. */
  6216. assert.changesBy = function (fn, obj, prop, delta, msg) {
  6217. if (arguments.length === 4 && typeof obj === 'function') {
  6218. var tmpMsg = delta;
  6219. delta = prop;
  6220. msg = tmpMsg;
  6221. } else if (arguments.length === 3) {
  6222. delta = prop;
  6223. prop = null;
  6224. }
  6225. new Assertion(fn, msg, assert.changesBy, true)
  6226. .to.change(obj, prop).by(delta);
  6227. }
  6228. /**
  6229. * ### .doesNotChange(function, object, property, [message])
  6230. *
  6231. * Asserts that a function does not change the value of a property.
  6232. *
  6233. * var obj = { val: 10 };
  6234. * var fn = function() { console.log('foo'); };
  6235. * assert.doesNotChange(fn, obj, 'val');
  6236. *
  6237. * @name doesNotChange
  6238. * @param {Function} modifier function
  6239. * @param {Object} object or getter function
  6240. * @param {String} property name _optional_
  6241. * @param {String} message _optional_
  6242. * @namespace Assert
  6243. * @api public
  6244. */
  6245. assert.doesNotChange = function (fn, obj, prop, msg) {
  6246. if (arguments.length === 3 && typeof obj === 'function') {
  6247. msg = prop;
  6248. prop = null;
  6249. }
  6250. return new Assertion(fn, msg, assert.doesNotChange, true)
  6251. .to.not.change(obj, prop);
  6252. }
  6253. /**
  6254. * ### .changesButNotBy(function, object, property, delta, [message])
  6255. *
  6256. * Asserts that a function does not change the value of a property or of a function's return value by an amount (delta)
  6257. *
  6258. * var obj = { val: 10 };
  6259. * var fn = function() { obj.val += 10 };
  6260. * assert.changesButNotBy(fn, obj, 'val', 5);
  6261. *
  6262. * @name changesButNotBy
  6263. * @param {Function} modifier function
  6264. * @param {Object} object or getter function
  6265. * @param {String} property name _optional_
  6266. * @param {Number} change amount (delta)
  6267. * @param {String} message _optional_
  6268. * @namespace Assert
  6269. * @api public
  6270. */
  6271. assert.changesButNotBy = function (fn, obj, prop, delta, msg) {
  6272. if (arguments.length === 4 && typeof obj === 'function') {
  6273. var tmpMsg = delta;
  6274. delta = prop;
  6275. msg = tmpMsg;
  6276. } else if (arguments.length === 3) {
  6277. delta = prop;
  6278. prop = null;
  6279. }
  6280. new Assertion(fn, msg, assert.changesButNotBy, true)
  6281. .to.change(obj, prop).but.not.by(delta);
  6282. }
  6283. /**
  6284. * ### .increases(function, object, property, [message])
  6285. *
  6286. * Asserts that a function increases a numeric object property.
  6287. *
  6288. * var obj = { val: 10 };
  6289. * var fn = function() { obj.val = 13 };
  6290. * assert.increases(fn, obj, 'val');
  6291. *
  6292. * @name increases
  6293. * @param {Function} modifier function
  6294. * @param {Object} object or getter function
  6295. * @param {String} property name _optional_
  6296. * @param {String} message _optional_
  6297. * @namespace Assert
  6298. * @api public
  6299. */
  6300. assert.increases = function (fn, obj, prop, msg) {
  6301. if (arguments.length === 3 && typeof obj === 'function') {
  6302. msg = prop;
  6303. prop = null;
  6304. }
  6305. return new Assertion(fn, msg, assert.increases, true)
  6306. .to.increase(obj, prop);
  6307. }
  6308. /**
  6309. * ### .increasesBy(function, object, property, delta, [message])
  6310. *
  6311. * Asserts that a function increases a numeric object property or a function's return value by an amount (delta).
  6312. *
  6313. * var obj = { val: 10 };
  6314. * var fn = function() { obj.val += 10 };
  6315. * assert.increasesBy(fn, obj, 'val', 10);
  6316. *
  6317. * @name increasesBy
  6318. * @param {Function} modifier function
  6319. * @param {Object} object or getter function
  6320. * @param {String} property name _optional_
  6321. * @param {Number} change amount (delta)
  6322. * @param {String} message _optional_
  6323. * @namespace Assert
  6324. * @api public
  6325. */
  6326. assert.increasesBy = function (fn, obj, prop, delta, msg) {
  6327. if (arguments.length === 4 && typeof obj === 'function') {
  6328. var tmpMsg = delta;
  6329. delta = prop;
  6330. msg = tmpMsg;
  6331. } else if (arguments.length === 3) {
  6332. delta = prop;
  6333. prop = null;
  6334. }
  6335. new Assertion(fn, msg, assert.increasesBy, true)
  6336. .to.increase(obj, prop).by(delta);
  6337. }
  6338. /**
  6339. * ### .doesNotIncrease(function, object, property, [message])
  6340. *
  6341. * Asserts that a function does not increase a numeric object property.
  6342. *
  6343. * var obj = { val: 10 };
  6344. * var fn = function() { obj.val = 8 };
  6345. * assert.doesNotIncrease(fn, obj, 'val');
  6346. *
  6347. * @name doesNotIncrease
  6348. * @param {Function} modifier function
  6349. * @param {Object} object or getter function
  6350. * @param {String} property name _optional_
  6351. * @param {String} message _optional_
  6352. * @namespace Assert
  6353. * @api public
  6354. */
  6355. assert.doesNotIncrease = function (fn, obj, prop, msg) {
  6356. if (arguments.length === 3 && typeof obj === 'function') {
  6357. msg = prop;
  6358. prop = null;
  6359. }
  6360. return new Assertion(fn, msg, assert.doesNotIncrease, true)
  6361. .to.not.increase(obj, prop);
  6362. }
  6363. /**
  6364. * ### .increasesButNotBy(function, object, property, delta, [message])
  6365. *
  6366. * Asserts that a function does not increase a numeric object property or function's return value by an amount (delta).
  6367. *
  6368. * var obj = { val: 10 };
  6369. * var fn = function() { obj.val = 15 };
  6370. * assert.increasesButNotBy(fn, obj, 'val', 10);
  6371. *
  6372. * @name increasesButNotBy
  6373. * @param {Function} modifier function
  6374. * @param {Object} object or getter function
  6375. * @param {String} property name _optional_
  6376. * @param {Number} change amount (delta)
  6377. * @param {String} message _optional_
  6378. * @namespace Assert
  6379. * @api public
  6380. */
  6381. assert.increasesButNotBy = function (fn, obj, prop, delta, msg) {
  6382. if (arguments.length === 4 && typeof obj === 'function') {
  6383. var tmpMsg = delta;
  6384. delta = prop;
  6385. msg = tmpMsg;
  6386. } else if (arguments.length === 3) {
  6387. delta = prop;
  6388. prop = null;
  6389. }
  6390. new Assertion(fn, msg, assert.increasesButNotBy, true)
  6391. .to.increase(obj, prop).but.not.by(delta);
  6392. }
  6393. /**
  6394. * ### .decreases(function, object, property, [message])
  6395. *
  6396. * Asserts that a function decreases a numeric object property.
  6397. *
  6398. * var obj = { val: 10 };
  6399. * var fn = function() { obj.val = 5 };
  6400. * assert.decreases(fn, obj, 'val');
  6401. *
  6402. * @name decreases
  6403. * @param {Function} modifier function
  6404. * @param {Object} object or getter function
  6405. * @param {String} property name _optional_
  6406. * @param {String} message _optional_
  6407. * @namespace Assert
  6408. * @api public
  6409. */
  6410. assert.decreases = function (fn, obj, prop, msg) {
  6411. if (arguments.length === 3 && typeof obj === 'function') {
  6412. msg = prop;
  6413. prop = null;
  6414. }
  6415. return new Assertion(fn, msg, assert.decreases, true)
  6416. .to.decrease(obj, prop);
  6417. }
  6418. /**
  6419. * ### .decreasesBy(function, object, property, delta, [message])
  6420. *
  6421. * Asserts that a function decreases a numeric object property or a function's return value by an amount (delta)
  6422. *
  6423. * var obj = { val: 10 };
  6424. * var fn = function() { obj.val -= 5 };
  6425. * assert.decreasesBy(fn, obj, 'val', 5);
  6426. *
  6427. * @name decreasesBy
  6428. * @param {Function} modifier function
  6429. * @param {Object} object or getter function
  6430. * @param {String} property name _optional_
  6431. * @param {Number} change amount (delta)
  6432. * @param {String} message _optional_
  6433. * @namespace Assert
  6434. * @api public
  6435. */
  6436. assert.decreasesBy = function (fn, obj, prop, delta, msg) {
  6437. if (arguments.length === 4 && typeof obj === 'function') {
  6438. var tmpMsg = delta;
  6439. delta = prop;
  6440. msg = tmpMsg;
  6441. } else if (arguments.length === 3) {
  6442. delta = prop;
  6443. prop = null;
  6444. }
  6445. new Assertion(fn, msg, assert.decreasesBy, true)
  6446. .to.decrease(obj, prop).by(delta);
  6447. }
  6448. /**
  6449. * ### .doesNotDecrease(function, object, property, [message])
  6450. *
  6451. * Asserts that a function does not decreases a numeric object property.
  6452. *
  6453. * var obj = { val: 10 };
  6454. * var fn = function() { obj.val = 15 };
  6455. * assert.doesNotDecrease(fn, obj, 'val');
  6456. *
  6457. * @name doesNotDecrease
  6458. * @param {Function} modifier function
  6459. * @param {Object} object or getter function
  6460. * @param {String} property name _optional_
  6461. * @param {String} message _optional_
  6462. * @namespace Assert
  6463. * @api public
  6464. */
  6465. assert.doesNotDecrease = function (fn, obj, prop, msg) {
  6466. if (arguments.length === 3 && typeof obj === 'function') {
  6467. msg = prop;
  6468. prop = null;
  6469. }
  6470. return new Assertion(fn, msg, assert.doesNotDecrease, true)
  6471. .to.not.decrease(obj, prop);
  6472. }
  6473. /**
  6474. * ### .doesNotDecreaseBy(function, object, property, delta, [message])
  6475. *
  6476. * Asserts that a function does not decreases a numeric object property or a function's return value by an amount (delta)
  6477. *
  6478. * var obj = { val: 10 };
  6479. * var fn = function() { obj.val = 5 };
  6480. * assert.doesNotDecreaseBy(fn, obj, 'val', 1);
  6481. *
  6482. * @name doesNotDecreaseBy
  6483. * @param {Function} modifier function
  6484. * @param {Object} object or getter function
  6485. * @param {String} property name _optional_
  6486. * @param {Number} change amount (delta)
  6487. * @param {String} message _optional_
  6488. * @namespace Assert
  6489. * @api public
  6490. */
  6491. assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) {
  6492. if (arguments.length === 4 && typeof obj === 'function') {
  6493. var tmpMsg = delta;
  6494. delta = prop;
  6495. msg = tmpMsg;
  6496. } else if (arguments.length === 3) {
  6497. delta = prop;
  6498. prop = null;
  6499. }
  6500. return new Assertion(fn, msg, assert.doesNotDecreaseBy, true)
  6501. .to.not.decrease(obj, prop).by(delta);
  6502. }
  6503. /**
  6504. * ### .decreasesButNotBy(function, object, property, delta, [message])
  6505. *
  6506. * Asserts that a function does not decreases a numeric object property or a function's return value by an amount (delta)
  6507. *
  6508. * var obj = { val: 10 };
  6509. * var fn = function() { obj.val = 5 };
  6510. * assert.decreasesButNotBy(fn, obj, 'val', 1);
  6511. *
  6512. * @name decreasesButNotBy
  6513. * @param {Function} modifier function
  6514. * @param {Object} object or getter function
  6515. * @param {String} property name _optional_
  6516. * @param {Number} change amount (delta)
  6517. * @param {String} message _optional_
  6518. * @namespace Assert
  6519. * @api public
  6520. */
  6521. assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) {
  6522. if (arguments.length === 4 && typeof obj === 'function') {
  6523. var tmpMsg = delta;
  6524. delta = prop;
  6525. msg = tmpMsg;
  6526. } else if (arguments.length === 3) {
  6527. delta = prop;
  6528. prop = null;
  6529. }
  6530. new Assertion(fn, msg, assert.decreasesButNotBy, true)
  6531. .to.decrease(obj, prop).but.not.by(delta);
  6532. }
  6533. /*!
  6534. * ### .ifError(object)
  6535. *
  6536. * Asserts if value is not a false value, and throws if it is a true value.
  6537. * This is added to allow for chai to be a drop-in replacement for Node's
  6538. * assert class.
  6539. *
  6540. * var err = new Error('I am a custom error');
  6541. * assert.ifError(err); // Rethrows err!
  6542. *
  6543. * @name ifError
  6544. * @param {Object} object
  6545. * @namespace Assert
  6546. * @api public
  6547. */
  6548. assert.ifError = function (val) {
  6549. if (val) {
  6550. throw(val);
  6551. }
  6552. };
  6553. /**
  6554. * ### .isExtensible(object)
  6555. *
  6556. * Asserts that `object` is extensible (can have new properties added to it).
  6557. *
  6558. * assert.isExtensible({});
  6559. *
  6560. * @name isExtensible
  6561. * @alias extensible
  6562. * @param {Object} object
  6563. * @param {String} message _optional_
  6564. * @namespace Assert
  6565. * @api public
  6566. */
  6567. assert.isExtensible = function (obj, msg) {
  6568. new Assertion(obj, msg, assert.isExtensible, true).to.be.extensible;
  6569. };
  6570. /**
  6571. * ### .isNotExtensible(object)
  6572. *
  6573. * Asserts that `object` is _not_ extensible.
  6574. *
  6575. * var nonExtensibleObject = Object.preventExtensions({});
  6576. * var sealedObject = Object.seal({});
  6577. * var frozenObject = Object.freeze({});
  6578. *
  6579. * assert.isNotExtensible(nonExtensibleObject);
  6580. * assert.isNotExtensible(sealedObject);
  6581. * assert.isNotExtensible(frozenObject);
  6582. *
  6583. * @name isNotExtensible
  6584. * @alias notExtensible
  6585. * @param {Object} object
  6586. * @param {String} message _optional_
  6587. * @namespace Assert
  6588. * @api public
  6589. */
  6590. assert.isNotExtensible = function (obj, msg) {
  6591. new Assertion(obj, msg, assert.isNotExtensible, true).to.not.be.extensible;
  6592. };
  6593. /**
  6594. * ### .isSealed(object)
  6595. *
  6596. * Asserts that `object` is sealed (cannot have new properties added to it
  6597. * and its existing properties cannot be removed).
  6598. *
  6599. * var sealedObject = Object.seal({});
  6600. * var frozenObject = Object.seal({});
  6601. *
  6602. * assert.isSealed(sealedObject);
  6603. * assert.isSealed(frozenObject);
  6604. *
  6605. * @name isSealed
  6606. * @alias sealed
  6607. * @param {Object} object
  6608. * @param {String} message _optional_
  6609. * @namespace Assert
  6610. * @api public
  6611. */
  6612. assert.isSealed = function (obj, msg) {
  6613. new Assertion(obj, msg, assert.isSealed, true).to.be.sealed;
  6614. };
  6615. /**
  6616. * ### .isNotSealed(object)
  6617. *
  6618. * Asserts that `object` is _not_ sealed.
  6619. *
  6620. * assert.isNotSealed({});
  6621. *
  6622. * @name isNotSealed
  6623. * @alias notSealed
  6624. * @param {Object} object
  6625. * @param {String} message _optional_
  6626. * @namespace Assert
  6627. * @api public
  6628. */
  6629. assert.isNotSealed = function (obj, msg) {
  6630. new Assertion(obj, msg, assert.isNotSealed, true).to.not.be.sealed;
  6631. };
  6632. /**
  6633. * ### .isFrozen(object)
  6634. *
  6635. * Asserts that `object` is frozen (cannot have new properties added to it
  6636. * and its existing properties cannot be modified).
  6637. *
  6638. * var frozenObject = Object.freeze({});
  6639. * assert.frozen(frozenObject);
  6640. *
  6641. * @name isFrozen
  6642. * @alias frozen
  6643. * @param {Object} object
  6644. * @param {String} message _optional_
  6645. * @namespace Assert
  6646. * @api public
  6647. */
  6648. assert.isFrozen = function (obj, msg) {
  6649. new Assertion(obj, msg, assert.isFrozen, true).to.be.frozen;
  6650. };
  6651. /**
  6652. * ### .isNotFrozen(object)
  6653. *
  6654. * Asserts that `object` is _not_ frozen.
  6655. *
  6656. * assert.isNotFrozen({});
  6657. *
  6658. * @name isNotFrozen
  6659. * @alias notFrozen
  6660. * @param {Object} object
  6661. * @param {String} message _optional_
  6662. * @namespace Assert
  6663. * @api public
  6664. */
  6665. assert.isNotFrozen = function (obj, msg) {
  6666. new Assertion(obj, msg, assert.isNotFrozen, true).to.not.be.frozen;
  6667. };
  6668. /**
  6669. * ### .isEmpty(target)
  6670. *
  6671. * Asserts that the target does not contain any values.
  6672. * For arrays and strings, it checks the `length` property.
  6673. * For `Map` and `Set` instances, it checks the `size` property.
  6674. * For non-function objects, it gets the count of own
  6675. * enumerable string keys.
  6676. *
  6677. * assert.isEmpty([]);
  6678. * assert.isEmpty('');
  6679. * assert.isEmpty(new Map);
  6680. * assert.isEmpty({});
  6681. *
  6682. * @name isEmpty
  6683. * @alias empty
  6684. * @param {Object|Array|String|Map|Set} target
  6685. * @param {String} message _optional_
  6686. * @namespace Assert
  6687. * @api public
  6688. */
  6689. assert.isEmpty = function(val, msg) {
  6690. new Assertion(val, msg, assert.isEmpty, true).to.be.empty;
  6691. };
  6692. /**
  6693. * ### .isNotEmpty(target)
  6694. *
  6695. * Asserts that the target contains values.
  6696. * For arrays and strings, it checks the `length` property.
  6697. * For `Map` and `Set` instances, it checks the `size` property.
  6698. * For non-function objects, it gets the count of own
  6699. * enumerable string keys.
  6700. *
  6701. * assert.isNotEmpty([1, 2]);
  6702. * assert.isNotEmpty('34');
  6703. * assert.isNotEmpty(new Set([5, 6]));
  6704. * assert.isNotEmpty({ key: 7 });
  6705. *
  6706. * @name isNotEmpty
  6707. * @alias notEmpty
  6708. * @param {Object|Array|String|Map|Set} target
  6709. * @param {String} message _optional_
  6710. * @namespace Assert
  6711. * @api public
  6712. */
  6713. assert.isNotEmpty = function(val, msg) {
  6714. new Assertion(val, msg, assert.isNotEmpty, true).to.not.be.empty;
  6715. };
  6716. /*!
  6717. * Aliases.
  6718. */
  6719. (function alias(name, as){
  6720. assert[as] = assert[name];
  6721. return alias;
  6722. })
  6723. ('isOk', 'ok')
  6724. ('isNotOk', 'notOk')
  6725. ('throws', 'throw')
  6726. ('throws', 'Throw')
  6727. ('isExtensible', 'extensible')
  6728. ('isNotExtensible', 'notExtensible')
  6729. ('isSealed', 'sealed')
  6730. ('isNotSealed', 'notSealed')
  6731. ('isFrozen', 'frozen')
  6732. ('isNotFrozen', 'notFrozen')
  6733. ('isEmpty', 'empty')
  6734. ('isNotEmpty', 'notEmpty');
  6735. };
  6736. },{}],7:[function(require,module,exports){
  6737. /*!
  6738. * chai
  6739. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  6740. * MIT Licensed
  6741. */
  6742. module.exports = function (chai, util) {
  6743. chai.expect = function (val, message) {
  6744. return new chai.Assertion(val, message);
  6745. };
  6746. /**
  6747. * ### .fail([message])
  6748. * ### .fail(actual, expected, [message], [operator])
  6749. *
  6750. * Throw a failure.
  6751. *
  6752. * expect.fail();
  6753. * expect.fail("custom error message");
  6754. * expect.fail(1, 2);
  6755. * expect.fail(1, 2, "custom error message");
  6756. * expect.fail(1, 2, "custom error message", ">");
  6757. * expect.fail(1, 2, undefined, ">");
  6758. *
  6759. * @name fail
  6760. * @param {Mixed} actual
  6761. * @param {Mixed} expected
  6762. * @param {String} message
  6763. * @param {String} operator
  6764. * @namespace BDD
  6765. * @api public
  6766. */
  6767. chai.expect.fail = function (actual, expected, message, operator) {
  6768. if (arguments.length < 2) {
  6769. message = actual;
  6770. actual = undefined;
  6771. }
  6772. message = message || 'expect.fail()';
  6773. throw new chai.AssertionError(message, {
  6774. actual: actual
  6775. , expected: expected
  6776. , operator: operator
  6777. }, chai.expect.fail);
  6778. };
  6779. };
  6780. },{}],8:[function(require,module,exports){
  6781. /*!
  6782. * chai
  6783. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  6784. * MIT Licensed
  6785. */
  6786. module.exports = function (chai, util) {
  6787. var Assertion = chai.Assertion;
  6788. function loadShould () {
  6789. // explicitly define this method as function as to have it's name to include as `ssfi`
  6790. function shouldGetter() {
  6791. if (this instanceof String
  6792. || this instanceof Number
  6793. || this instanceof Boolean
  6794. || typeof Symbol === 'function' && this instanceof Symbol
  6795. || typeof BigInt === 'function' && this instanceof BigInt) {
  6796. return new Assertion(this.valueOf(), null, shouldGetter);
  6797. }
  6798. return new Assertion(this, null, shouldGetter);
  6799. }
  6800. function shouldSetter(value) {
  6801. // See https://github.com/chaijs/chai/issues/86: this makes
  6802. // `whatever.should = someValue` actually set `someValue`, which is
  6803. // especially useful for `global.should = require('chai').should()`.
  6804. //
  6805. // Note that we have to use [[DefineProperty]] instead of [[Put]]
  6806. // since otherwise we would trigger this very setter!
  6807. Object.defineProperty(this, 'should', {
  6808. value: value,
  6809. enumerable: true,
  6810. configurable: true,
  6811. writable: true
  6812. });
  6813. }
  6814. // modify Object.prototype to have `should`
  6815. Object.defineProperty(Object.prototype, 'should', {
  6816. set: shouldSetter
  6817. , get: shouldGetter
  6818. , configurable: true
  6819. });
  6820. var should = {};
  6821. /**
  6822. * ### .fail([message])
  6823. * ### .fail(actual, expected, [message], [operator])
  6824. *
  6825. * Throw a failure.
  6826. *
  6827. * should.fail();
  6828. * should.fail("custom error message");
  6829. * should.fail(1, 2);
  6830. * should.fail(1, 2, "custom error message");
  6831. * should.fail(1, 2, "custom error message", ">");
  6832. * should.fail(1, 2, undefined, ">");
  6833. *
  6834. *
  6835. * @name fail
  6836. * @param {Mixed} actual
  6837. * @param {Mixed} expected
  6838. * @param {String} message
  6839. * @param {String} operator
  6840. * @namespace BDD
  6841. * @api public
  6842. */
  6843. should.fail = function (actual, expected, message, operator) {
  6844. if (arguments.length < 2) {
  6845. message = actual;
  6846. actual = undefined;
  6847. }
  6848. message = message || 'should.fail()';
  6849. throw new chai.AssertionError(message, {
  6850. actual: actual
  6851. , expected: expected
  6852. , operator: operator
  6853. }, should.fail);
  6854. };
  6855. /**
  6856. * ### .equal(actual, expected, [message])
  6857. *
  6858. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  6859. *
  6860. * should.equal(3, '3', '== coerces values to strings');
  6861. *
  6862. * @name equal
  6863. * @param {Mixed} actual
  6864. * @param {Mixed} expected
  6865. * @param {String} message
  6866. * @namespace Should
  6867. * @api public
  6868. */
  6869. should.equal = function (val1, val2, msg) {
  6870. new Assertion(val1, msg).to.equal(val2);
  6871. };
  6872. /**
  6873. * ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
  6874. *
  6875. * Asserts that `function` will throw an error that is an instance of
  6876. * `constructor`, or alternately that it will throw an error with message
  6877. * matching `regexp`.
  6878. *
  6879. * should.throw(fn, 'function throws a reference error');
  6880. * should.throw(fn, /function throws a reference error/);
  6881. * should.throw(fn, ReferenceError);
  6882. * should.throw(fn, ReferenceError, 'function throws a reference error');
  6883. * should.throw(fn, ReferenceError, /function throws a reference error/);
  6884. *
  6885. * @name throw
  6886. * @alias Throw
  6887. * @param {Function} function
  6888. * @param {ErrorConstructor} constructor
  6889. * @param {RegExp} regexp
  6890. * @param {String} message
  6891. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  6892. * @namespace Should
  6893. * @api public
  6894. */
  6895. should.Throw = function (fn, errt, errs, msg) {
  6896. new Assertion(fn, msg).to.Throw(errt, errs);
  6897. };
  6898. /**
  6899. * ### .exist
  6900. *
  6901. * Asserts that the target is neither `null` nor `undefined`.
  6902. *
  6903. * var foo = 'hi';
  6904. *
  6905. * should.exist(foo, 'foo exists');
  6906. *
  6907. * @name exist
  6908. * @namespace Should
  6909. * @api public
  6910. */
  6911. should.exist = function (val, msg) {
  6912. new Assertion(val, msg).to.exist;
  6913. }
  6914. // negation
  6915. should.not = {}
  6916. /**
  6917. * ### .not.equal(actual, expected, [message])
  6918. *
  6919. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  6920. *
  6921. * should.not.equal(3, 4, 'these numbers are not equal');
  6922. *
  6923. * @name not.equal
  6924. * @param {Mixed} actual
  6925. * @param {Mixed} expected
  6926. * @param {String} message
  6927. * @namespace Should
  6928. * @api public
  6929. */
  6930. should.not.equal = function (val1, val2, msg) {
  6931. new Assertion(val1, msg).to.not.equal(val2);
  6932. };
  6933. /**
  6934. * ### .throw(function, [constructor/regexp], [message])
  6935. *
  6936. * Asserts that `function` will _not_ throw an error that is an instance of
  6937. * `constructor`, or alternately that it will not throw an error with message
  6938. * matching `regexp`.
  6939. *
  6940. * should.not.throw(fn, Error, 'function does not throw');
  6941. *
  6942. * @name not.throw
  6943. * @alias not.Throw
  6944. * @param {Function} function
  6945. * @param {ErrorConstructor} constructor
  6946. * @param {RegExp} regexp
  6947. * @param {String} message
  6948. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  6949. * @namespace Should
  6950. * @api public
  6951. */
  6952. should.not.Throw = function (fn, errt, errs, msg) {
  6953. new Assertion(fn, msg).to.not.Throw(errt, errs);
  6954. };
  6955. /**
  6956. * ### .not.exist
  6957. *
  6958. * Asserts that the target is neither `null` nor `undefined`.
  6959. *
  6960. * var bar = null;
  6961. *
  6962. * should.not.exist(bar, 'bar does not exist');
  6963. *
  6964. * @name not.exist
  6965. * @namespace Should
  6966. * @api public
  6967. */
  6968. should.not.exist = function (val, msg) {
  6969. new Assertion(val, msg).to.not.exist;
  6970. }
  6971. should['throw'] = should['Throw'];
  6972. should.not['throw'] = should.not['Throw'];
  6973. return should;
  6974. };
  6975. chai.should = loadShould;
  6976. chai.Should = loadShould;
  6977. };
  6978. },{}],9:[function(require,module,exports){
  6979. /*!
  6980. * Chai - addChainingMethod utility
  6981. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  6982. * MIT Licensed
  6983. */
  6984. /*!
  6985. * Module dependencies
  6986. */
  6987. var addLengthGuard = require('./addLengthGuard');
  6988. var chai = require('../../chai');
  6989. var flag = require('./flag');
  6990. var proxify = require('./proxify');
  6991. var transferFlags = require('./transferFlags');
  6992. /*!
  6993. * Module variables
  6994. */
  6995. // Check whether `Object.setPrototypeOf` is supported
  6996. var canSetPrototype = typeof Object.setPrototypeOf === 'function';
  6997. // Without `Object.setPrototypeOf` support, this module will need to add properties to a function.
  6998. // However, some of functions' own props are not configurable and should be skipped.
  6999. var testFn = function() {};
  7000. var excludeNames = Object.getOwnPropertyNames(testFn).filter(function(name) {
  7001. var propDesc = Object.getOwnPropertyDescriptor(testFn, name);
  7002. // Note: PhantomJS 1.x includes `callee` as one of `testFn`'s own properties,
  7003. // but then returns `undefined` as the property descriptor for `callee`. As a
  7004. // workaround, we perform an otherwise unnecessary type-check for `propDesc`,
  7005. // and then filter it out if it's not an object as it should be.
  7006. if (typeof propDesc !== 'object')
  7007. return true;
  7008. return !propDesc.configurable;
  7009. });
  7010. // Cache `Function` properties
  7011. var call = Function.prototype.call,
  7012. apply = Function.prototype.apply;
  7013. /**
  7014. * ### .addChainableMethod(ctx, name, method, chainingBehavior)
  7015. *
  7016. * Adds a method to an object, such that the method can also be chained.
  7017. *
  7018. * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
  7019. * var obj = utils.flag(this, 'object');
  7020. * new chai.Assertion(obj).to.be.equal(str);
  7021. * });
  7022. *
  7023. * Can also be accessed directly from `chai.Assertion`.
  7024. *
  7025. * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
  7026. *
  7027. * The result can then be used as both a method assertion, executing both `method` and
  7028. * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
  7029. *
  7030. * expect(fooStr).to.be.foo('bar');
  7031. * expect(fooStr).to.be.foo.equal('foo');
  7032. *
  7033. * @param {Object} ctx object to which the method is added
  7034. * @param {String} name of method to add
  7035. * @param {Function} method function to be used for `name`, when called
  7036. * @param {Function} chainingBehavior function to be called every time the property is accessed
  7037. * @namespace Utils
  7038. * @name addChainableMethod
  7039. * @api public
  7040. */
  7041. module.exports = function addChainableMethod(ctx, name, method, chainingBehavior) {
  7042. if (typeof chainingBehavior !== 'function') {
  7043. chainingBehavior = function () { };
  7044. }
  7045. var chainableBehavior = {
  7046. method: method
  7047. , chainingBehavior: chainingBehavior
  7048. };
  7049. // save the methods so we can overwrite them later, if we need to.
  7050. if (!ctx.__methods) {
  7051. ctx.__methods = {};
  7052. }
  7053. ctx.__methods[name] = chainableBehavior;
  7054. Object.defineProperty(ctx, name,
  7055. { get: function chainableMethodGetter() {
  7056. chainableBehavior.chainingBehavior.call(this);
  7057. var chainableMethodWrapper = function () {
  7058. // Setting the `ssfi` flag to `chainableMethodWrapper` causes this
  7059. // function to be the starting point for removing implementation
  7060. // frames from the stack trace of a failed assertion.
  7061. //
  7062. // However, we only want to use this function as the starting point if
  7063. // the `lockSsfi` flag isn't set.
  7064. //
  7065. // If the `lockSsfi` flag is set, then this assertion is being
  7066. // invoked from inside of another assertion. In this case, the `ssfi`
  7067. // flag has already been set by the outer assertion.
  7068. //
  7069. // Note that overwriting a chainable method merely replaces the saved
  7070. // methods in `ctx.__methods` instead of completely replacing the
  7071. // overwritten assertion. Therefore, an overwriting assertion won't
  7072. // set the `ssfi` or `lockSsfi` flags.
  7073. if (!flag(this, 'lockSsfi')) {
  7074. flag(this, 'ssfi', chainableMethodWrapper);
  7075. }
  7076. var result = chainableBehavior.method.apply(this, arguments);
  7077. if (result !== undefined) {
  7078. return result;
  7079. }
  7080. var newAssertion = new chai.Assertion();
  7081. transferFlags(this, newAssertion);
  7082. return newAssertion;
  7083. };
  7084. addLengthGuard(chainableMethodWrapper, name, true);
  7085. // Use `Object.setPrototypeOf` if available
  7086. if (canSetPrototype) {
  7087. // Inherit all properties from the object by replacing the `Function` prototype
  7088. var prototype = Object.create(this);
  7089. // Restore the `call` and `apply` methods from `Function`
  7090. prototype.call = call;
  7091. prototype.apply = apply;
  7092. Object.setPrototypeOf(chainableMethodWrapper, prototype);
  7093. }
  7094. // Otherwise, redefine all properties (slow!)
  7095. else {
  7096. var asserterNames = Object.getOwnPropertyNames(ctx);
  7097. asserterNames.forEach(function (asserterName) {
  7098. if (excludeNames.indexOf(asserterName) !== -1) {
  7099. return;
  7100. }
  7101. var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
  7102. Object.defineProperty(chainableMethodWrapper, asserterName, pd);
  7103. });
  7104. }
  7105. transferFlags(this, chainableMethodWrapper);
  7106. return proxify(chainableMethodWrapper);
  7107. }
  7108. , configurable: true
  7109. });
  7110. };
  7111. },{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":31,"./transferFlags":33}],10:[function(require,module,exports){
  7112. var fnLengthDesc = Object.getOwnPropertyDescriptor(function () {}, 'length');
  7113. /*!
  7114. * Chai - addLengthGuard utility
  7115. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7116. * MIT Licensed
  7117. */
  7118. /**
  7119. * ### .addLengthGuard(fn, assertionName, isChainable)
  7120. *
  7121. * Define `length` as a getter on the given uninvoked method assertion. The
  7122. * getter acts as a guard against chaining `length` directly off of an uninvoked
  7123. * method assertion, which is a problem because it references `function`'s
  7124. * built-in `length` property instead of Chai's `length` assertion. When the
  7125. * getter catches the user making this mistake, it throws an error with a
  7126. * helpful message.
  7127. *
  7128. * There are two ways in which this mistake can be made. The first way is by
  7129. * chaining the `length` assertion directly off of an uninvoked chainable
  7130. * method. In this case, Chai suggests that the user use `lengthOf` instead. The
  7131. * second way is by chaining the `length` assertion directly off of an uninvoked
  7132. * non-chainable method. Non-chainable methods must be invoked prior to
  7133. * chaining. In this case, Chai suggests that the user consult the docs for the
  7134. * given assertion.
  7135. *
  7136. * If the `length` property of functions is unconfigurable, then return `fn`
  7137. * without modification.
  7138. *
  7139. * Note that in ES6, the function's `length` property is configurable, so once
  7140. * support for legacy environments is dropped, Chai's `length` property can
  7141. * replace the built-in function's `length` property, and this length guard will
  7142. * no longer be necessary. In the mean time, maintaining consistency across all
  7143. * environments is the priority.
  7144. *
  7145. * @param {Function} fn
  7146. * @param {String} assertionName
  7147. * @param {Boolean} isChainable
  7148. * @namespace Utils
  7149. * @name addLengthGuard
  7150. */
  7151. module.exports = function addLengthGuard (fn, assertionName, isChainable) {
  7152. if (!fnLengthDesc.configurable) return fn;
  7153. Object.defineProperty(fn, 'length', {
  7154. get: function () {
  7155. if (isChainable) {
  7156. throw Error('Invalid Chai property: ' + assertionName + '.length. Due' +
  7157. ' to a compatibility issue, "length" cannot directly follow "' +
  7158. assertionName + '". Use "' + assertionName + '.lengthOf" instead.');
  7159. }
  7160. throw Error('Invalid Chai property: ' + assertionName + '.length. See' +
  7161. ' docs for proper usage of "' + assertionName + '".');
  7162. }
  7163. });
  7164. return fn;
  7165. };
  7166. },{}],11:[function(require,module,exports){
  7167. /*!
  7168. * Chai - addMethod utility
  7169. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7170. * MIT Licensed
  7171. */
  7172. var addLengthGuard = require('./addLengthGuard');
  7173. var chai = require('../../chai');
  7174. var flag = require('./flag');
  7175. var proxify = require('./proxify');
  7176. var transferFlags = require('./transferFlags');
  7177. /**
  7178. * ### .addMethod(ctx, name, method)
  7179. *
  7180. * Adds a method to the prototype of an object.
  7181. *
  7182. * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
  7183. * var obj = utils.flag(this, 'object');
  7184. * new chai.Assertion(obj).to.be.equal(str);
  7185. * });
  7186. *
  7187. * Can also be accessed directly from `chai.Assertion`.
  7188. *
  7189. * chai.Assertion.addMethod('foo', fn);
  7190. *
  7191. * Then can be used as any other assertion.
  7192. *
  7193. * expect(fooStr).to.be.foo('bar');
  7194. *
  7195. * @param {Object} ctx object to which the method is added
  7196. * @param {String} name of method to add
  7197. * @param {Function} method function to be used for name
  7198. * @namespace Utils
  7199. * @name addMethod
  7200. * @api public
  7201. */
  7202. module.exports = function addMethod(ctx, name, method) {
  7203. var methodWrapper = function () {
  7204. // Setting the `ssfi` flag to `methodWrapper` causes this function to be the
  7205. // starting point for removing implementation frames from the stack trace of
  7206. // a failed assertion.
  7207. //
  7208. // However, we only want to use this function as the starting point if the
  7209. // `lockSsfi` flag isn't set.
  7210. //
  7211. // If the `lockSsfi` flag is set, then either this assertion has been
  7212. // overwritten by another assertion, or this assertion is being invoked from
  7213. // inside of another assertion. In the first case, the `ssfi` flag has
  7214. // already been set by the overwriting assertion. In the second case, the
  7215. // `ssfi` flag has already been set by the outer assertion.
  7216. if (!flag(this, 'lockSsfi')) {
  7217. flag(this, 'ssfi', methodWrapper);
  7218. }
  7219. var result = method.apply(this, arguments);
  7220. if (result !== undefined)
  7221. return result;
  7222. var newAssertion = new chai.Assertion();
  7223. transferFlags(this, newAssertion);
  7224. return newAssertion;
  7225. };
  7226. addLengthGuard(methodWrapper, name, false);
  7227. ctx[name] = proxify(methodWrapper, name);
  7228. };
  7229. },{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":31,"./transferFlags":33}],12:[function(require,module,exports){
  7230. /*!
  7231. * Chai - addProperty utility
  7232. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7233. * MIT Licensed
  7234. */
  7235. var chai = require('../../chai');
  7236. var flag = require('./flag');
  7237. var isProxyEnabled = require('./isProxyEnabled');
  7238. var transferFlags = require('./transferFlags');
  7239. /**
  7240. * ### .addProperty(ctx, name, getter)
  7241. *
  7242. * Adds a property to the prototype of an object.
  7243. *
  7244. * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
  7245. * var obj = utils.flag(this, 'object');
  7246. * new chai.Assertion(obj).to.be.instanceof(Foo);
  7247. * });
  7248. *
  7249. * Can also be accessed directly from `chai.Assertion`.
  7250. *
  7251. * chai.Assertion.addProperty('foo', fn);
  7252. *
  7253. * Then can be used as any other assertion.
  7254. *
  7255. * expect(myFoo).to.be.foo;
  7256. *
  7257. * @param {Object} ctx object to which the property is added
  7258. * @param {String} name of property to add
  7259. * @param {Function} getter function to be used for name
  7260. * @namespace Utils
  7261. * @name addProperty
  7262. * @api public
  7263. */
  7264. module.exports = function addProperty(ctx, name, getter) {
  7265. getter = getter === undefined ? function () {} : getter;
  7266. Object.defineProperty(ctx, name,
  7267. { get: function propertyGetter() {
  7268. // Setting the `ssfi` flag to `propertyGetter` causes this function to
  7269. // be the starting point for removing implementation frames from the
  7270. // stack trace of a failed assertion.
  7271. //
  7272. // However, we only want to use this function as the starting point if
  7273. // the `lockSsfi` flag isn't set and proxy protection is disabled.
  7274. //
  7275. // If the `lockSsfi` flag is set, then either this assertion has been
  7276. // overwritten by another assertion, or this assertion is being invoked
  7277. // from inside of another assertion. In the first case, the `ssfi` flag
  7278. // has already been set by the overwriting assertion. In the second
  7279. // case, the `ssfi` flag has already been set by the outer assertion.
  7280. //
  7281. // If proxy protection is enabled, then the `ssfi` flag has already been
  7282. // set by the proxy getter.
  7283. if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
  7284. flag(this, 'ssfi', propertyGetter);
  7285. }
  7286. var result = getter.call(this);
  7287. if (result !== undefined)
  7288. return result;
  7289. var newAssertion = new chai.Assertion();
  7290. transferFlags(this, newAssertion);
  7291. return newAssertion;
  7292. }
  7293. , configurable: true
  7294. });
  7295. };
  7296. },{"../../chai":2,"./flag":15,"./isProxyEnabled":26,"./transferFlags":33}],13:[function(require,module,exports){
  7297. /*!
  7298. * Chai - compareByInspect utility
  7299. * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
  7300. * MIT Licensed
  7301. */
  7302. /*!
  7303. * Module dependencies
  7304. */
  7305. var inspect = require('./inspect');
  7306. /**
  7307. * ### .compareByInspect(mixed, mixed)
  7308. *
  7309. * To be used as a compareFunction with Array.prototype.sort. Compares elements
  7310. * using inspect instead of default behavior of using toString so that Symbols
  7311. * and objects with irregular/missing toString can still be sorted without a
  7312. * TypeError.
  7313. *
  7314. * @param {Mixed} first element to compare
  7315. * @param {Mixed} second element to compare
  7316. * @returns {Number} -1 if 'a' should come before 'b'; otherwise 1
  7317. * @name compareByInspect
  7318. * @namespace Utils
  7319. * @api public
  7320. */
  7321. module.exports = function compareByInspect(a, b) {
  7322. return inspect(a) < inspect(b) ? -1 : 1;
  7323. };
  7324. },{"./inspect":24}],14:[function(require,module,exports){
  7325. /*!
  7326. * Chai - expectTypes utility
  7327. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7328. * MIT Licensed
  7329. */
  7330. /**
  7331. * ### .expectTypes(obj, types)
  7332. *
  7333. * Ensures that the object being tested against is of a valid type.
  7334. *
  7335. * utils.expectTypes(this, ['array', 'object', 'string']);
  7336. *
  7337. * @param {Mixed} obj constructed Assertion
  7338. * @param {Array} type A list of allowed types for this assertion
  7339. * @namespace Utils
  7340. * @name expectTypes
  7341. * @api public
  7342. */
  7343. var AssertionError = require('assertion-error');
  7344. var flag = require('./flag');
  7345. var type = require('type-detect');
  7346. module.exports = function expectTypes(obj, types) {
  7347. var flagMsg = flag(obj, 'message');
  7348. var ssfi = flag(obj, 'ssfi');
  7349. flagMsg = flagMsg ? flagMsg + ': ' : '';
  7350. obj = flag(obj, 'object');
  7351. types = types.map(function (t) { return t.toLowerCase(); });
  7352. types.sort();
  7353. // Transforms ['lorem', 'ipsum'] into 'a lorem, or an ipsum'
  7354. var str = types.map(function (t, index) {
  7355. var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a';
  7356. var or = types.length > 1 && index === types.length - 1 ? 'or ' : '';
  7357. return or + art + ' ' + t;
  7358. }).join(', ');
  7359. var objType = type(obj).toLowerCase();
  7360. if (!types.some(function (expected) { return objType === expected; })) {
  7361. throw new AssertionError(
  7362. flagMsg + 'object tested must be ' + str + ', but ' + objType + ' given',
  7363. undefined,
  7364. ssfi
  7365. );
  7366. }
  7367. };
  7368. },{"./flag":15,"assertion-error":34,"type-detect":39}],15:[function(require,module,exports){
  7369. /*!
  7370. * Chai - flag utility
  7371. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7372. * MIT Licensed
  7373. */
  7374. /**
  7375. * ### .flag(object, key, [value])
  7376. *
  7377. * Get or set a flag value on an object. If a
  7378. * value is provided it will be set, else it will
  7379. * return the currently set value or `undefined` if
  7380. * the value is not set.
  7381. *
  7382. * utils.flag(this, 'foo', 'bar'); // setter
  7383. * utils.flag(this, 'foo'); // getter, returns `bar`
  7384. *
  7385. * @param {Object} object constructed Assertion
  7386. * @param {String} key
  7387. * @param {Mixed} value (optional)
  7388. * @namespace Utils
  7389. * @name flag
  7390. * @api private
  7391. */
  7392. module.exports = function flag(obj, key, value) {
  7393. var flags = obj.__flags || (obj.__flags = Object.create(null));
  7394. if (arguments.length === 3) {
  7395. flags[key] = value;
  7396. } else {
  7397. return flags[key];
  7398. }
  7399. };
  7400. },{}],16:[function(require,module,exports){
  7401. /*!
  7402. * Chai - getActual utility
  7403. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7404. * MIT Licensed
  7405. */
  7406. /**
  7407. * ### .getActual(object, [actual])
  7408. *
  7409. * Returns the `actual` value for an Assertion.
  7410. *
  7411. * @param {Object} object (constructed Assertion)
  7412. * @param {Arguments} chai.Assertion.prototype.assert arguments
  7413. * @namespace Utils
  7414. * @name getActual
  7415. */
  7416. module.exports = function getActual(obj, args) {
  7417. return args.length > 4 ? args[4] : obj._obj;
  7418. };
  7419. },{}],17:[function(require,module,exports){
  7420. /*!
  7421. * Chai - getEnumerableProperties utility
  7422. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7423. * MIT Licensed
  7424. */
  7425. /**
  7426. * ### .getEnumerableProperties(object)
  7427. *
  7428. * This allows the retrieval of enumerable property names of an object,
  7429. * inherited or not.
  7430. *
  7431. * @param {Object} object
  7432. * @returns {Array}
  7433. * @namespace Utils
  7434. * @name getEnumerableProperties
  7435. * @api public
  7436. */
  7437. module.exports = function getEnumerableProperties(object) {
  7438. var result = [];
  7439. for (var name in object) {
  7440. result.push(name);
  7441. }
  7442. return result;
  7443. };
  7444. },{}],18:[function(require,module,exports){
  7445. /*!
  7446. * Chai - message composition utility
  7447. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7448. * MIT Licensed
  7449. */
  7450. /*!
  7451. * Module dependencies
  7452. */
  7453. var flag = require('./flag')
  7454. , getActual = require('./getActual')
  7455. , objDisplay = require('./objDisplay');
  7456. /**
  7457. * ### .getMessage(object, message, negateMessage)
  7458. *
  7459. * Construct the error message based on flags
  7460. * and template tags. Template tags will return
  7461. * a stringified inspection of the object referenced.
  7462. *
  7463. * Message template tags:
  7464. * - `#{this}` current asserted object
  7465. * - `#{act}` actual value
  7466. * - `#{exp}` expected value
  7467. *
  7468. * @param {Object} object (constructed Assertion)
  7469. * @param {Arguments} chai.Assertion.prototype.assert arguments
  7470. * @namespace Utils
  7471. * @name getMessage
  7472. * @api public
  7473. */
  7474. module.exports = function getMessage(obj, args) {
  7475. var negate = flag(obj, 'negate')
  7476. , val = flag(obj, 'object')
  7477. , expected = args[3]
  7478. , actual = getActual(obj, args)
  7479. , msg = negate ? args[2] : args[1]
  7480. , flagMsg = flag(obj, 'message');
  7481. if(typeof msg === "function") msg = msg();
  7482. msg = msg || '';
  7483. msg = msg
  7484. .replace(/#\{this\}/g, function () { return objDisplay(val); })
  7485. .replace(/#\{act\}/g, function () { return objDisplay(actual); })
  7486. .replace(/#\{exp\}/g, function () { return objDisplay(expected); });
  7487. return flagMsg ? flagMsg + ': ' + msg : msg;
  7488. };
  7489. },{"./flag":15,"./getActual":16,"./objDisplay":27}],19:[function(require,module,exports){
  7490. var type = require('type-detect');
  7491. var flag = require('./flag');
  7492. function isObjectType(obj) {
  7493. var objectType = type(obj);
  7494. var objectTypes = ['Array', 'Object', 'function'];
  7495. return objectTypes.indexOf(objectType) !== -1;
  7496. }
  7497. /**
  7498. * ### .getOperator(message)
  7499. *
  7500. * Extract the operator from error message.
  7501. * Operator defined is based on below link
  7502. * https://nodejs.org/api/assert.html#assert_assert.
  7503. *
  7504. * Returns the `operator` or `undefined` value for an Assertion.
  7505. *
  7506. * @param {Object} object (constructed Assertion)
  7507. * @param {Arguments} chai.Assertion.prototype.assert arguments
  7508. * @namespace Utils
  7509. * @name getOperator
  7510. * @api public
  7511. */
  7512. module.exports = function getOperator(obj, args) {
  7513. var operator = flag(obj, 'operator');
  7514. var negate = flag(obj, 'negate');
  7515. var expected = args[3];
  7516. var msg = negate ? args[2] : args[1];
  7517. if (operator) {
  7518. return operator;
  7519. }
  7520. if (typeof msg === 'function') msg = msg();
  7521. msg = msg || '';
  7522. if (!msg) {
  7523. return undefined;
  7524. }
  7525. if (/\shave\s/.test(msg)) {
  7526. return undefined;
  7527. }
  7528. var isObject = isObjectType(expected);
  7529. if (/\snot\s/.test(msg)) {
  7530. return isObject ? 'notDeepStrictEqual' : 'notStrictEqual';
  7531. }
  7532. return isObject ? 'deepStrictEqual' : 'strictEqual';
  7533. };
  7534. },{"./flag":15,"type-detect":39}],20:[function(require,module,exports){
  7535. /*!
  7536. * Chai - getOwnEnumerableProperties utility
  7537. * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
  7538. * MIT Licensed
  7539. */
  7540. /*!
  7541. * Module dependencies
  7542. */
  7543. var getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols');
  7544. /**
  7545. * ### .getOwnEnumerableProperties(object)
  7546. *
  7547. * This allows the retrieval of directly-owned enumerable property names and
  7548. * symbols of an object. This function is necessary because Object.keys only
  7549. * returns enumerable property names, not enumerable property symbols.
  7550. *
  7551. * @param {Object} object
  7552. * @returns {Array}
  7553. * @namespace Utils
  7554. * @name getOwnEnumerableProperties
  7555. * @api public
  7556. */
  7557. module.exports = function getOwnEnumerableProperties(obj) {
  7558. return Object.keys(obj).concat(getOwnEnumerablePropertySymbols(obj));
  7559. };
  7560. },{"./getOwnEnumerablePropertySymbols":21}],21:[function(require,module,exports){
  7561. /*!
  7562. * Chai - getOwnEnumerablePropertySymbols utility
  7563. * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
  7564. * MIT Licensed
  7565. */
  7566. /**
  7567. * ### .getOwnEnumerablePropertySymbols(object)
  7568. *
  7569. * This allows the retrieval of directly-owned enumerable property symbols of an
  7570. * object. This function is necessary because Object.getOwnPropertySymbols
  7571. * returns both enumerable and non-enumerable property symbols.
  7572. *
  7573. * @param {Object} object
  7574. * @returns {Array}
  7575. * @namespace Utils
  7576. * @name getOwnEnumerablePropertySymbols
  7577. * @api public
  7578. */
  7579. module.exports = function getOwnEnumerablePropertySymbols(obj) {
  7580. if (typeof Object.getOwnPropertySymbols !== 'function') return [];
  7581. return Object.getOwnPropertySymbols(obj).filter(function (sym) {
  7582. return Object.getOwnPropertyDescriptor(obj, sym).enumerable;
  7583. });
  7584. };
  7585. },{}],22:[function(require,module,exports){
  7586. /*!
  7587. * Chai - getProperties utility
  7588. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7589. * MIT Licensed
  7590. */
  7591. /**
  7592. * ### .getProperties(object)
  7593. *
  7594. * This allows the retrieval of property names of an object, enumerable or not,
  7595. * inherited or not.
  7596. *
  7597. * @param {Object} object
  7598. * @returns {Array}
  7599. * @namespace Utils
  7600. * @name getProperties
  7601. * @api public
  7602. */
  7603. module.exports = function getProperties(object) {
  7604. var result = Object.getOwnPropertyNames(object);
  7605. function addProperty(property) {
  7606. if (result.indexOf(property) === -1) {
  7607. result.push(property);
  7608. }
  7609. }
  7610. var proto = Object.getPrototypeOf(object);
  7611. while (proto !== null) {
  7612. Object.getOwnPropertyNames(proto).forEach(addProperty);
  7613. proto = Object.getPrototypeOf(proto);
  7614. }
  7615. return result;
  7616. };
  7617. },{}],23:[function(require,module,exports){
  7618. /*!
  7619. * chai
  7620. * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
  7621. * MIT Licensed
  7622. */
  7623. /*!
  7624. * Dependencies that are used for multiple exports are required here only once
  7625. */
  7626. var pathval = require('pathval');
  7627. /*!
  7628. * test utility
  7629. */
  7630. exports.test = require('./test');
  7631. /*!
  7632. * type utility
  7633. */
  7634. exports.type = require('type-detect');
  7635. /*!
  7636. * expectTypes utility
  7637. */
  7638. exports.expectTypes = require('./expectTypes');
  7639. /*!
  7640. * message utility
  7641. */
  7642. exports.getMessage = require('./getMessage');
  7643. /*!
  7644. * actual utility
  7645. */
  7646. exports.getActual = require('./getActual');
  7647. /*!
  7648. * Inspect util
  7649. */
  7650. exports.inspect = require('./inspect');
  7651. /*!
  7652. * Object Display util
  7653. */
  7654. exports.objDisplay = require('./objDisplay');
  7655. /*!
  7656. * Flag utility
  7657. */
  7658. exports.flag = require('./flag');
  7659. /*!
  7660. * Flag transferring utility
  7661. */
  7662. exports.transferFlags = require('./transferFlags');
  7663. /*!
  7664. * Deep equal utility
  7665. */
  7666. exports.eql = require('deep-eql');
  7667. /*!
  7668. * Deep path info
  7669. */
  7670. exports.getPathInfo = pathval.getPathInfo;
  7671. /*!
  7672. * Check if a property exists
  7673. */
  7674. exports.hasProperty = pathval.hasProperty;
  7675. /*!
  7676. * Function name
  7677. */
  7678. exports.getName = require('get-func-name');
  7679. /*!
  7680. * add Property
  7681. */
  7682. exports.addProperty = require('./addProperty');
  7683. /*!
  7684. * add Method
  7685. */
  7686. exports.addMethod = require('./addMethod');
  7687. /*!
  7688. * overwrite Property
  7689. */
  7690. exports.overwriteProperty = require('./overwriteProperty');
  7691. /*!
  7692. * overwrite Method
  7693. */
  7694. exports.overwriteMethod = require('./overwriteMethod');
  7695. /*!
  7696. * Add a chainable method
  7697. */
  7698. exports.addChainableMethod = require('./addChainableMethod');
  7699. /*!
  7700. * Overwrite chainable method
  7701. */
  7702. exports.overwriteChainableMethod = require('./overwriteChainableMethod');
  7703. /*!
  7704. * Compare by inspect method
  7705. */
  7706. exports.compareByInspect = require('./compareByInspect');
  7707. /*!
  7708. * Get own enumerable property symbols method
  7709. */
  7710. exports.getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols');
  7711. /*!
  7712. * Get own enumerable properties method
  7713. */
  7714. exports.getOwnEnumerableProperties = require('./getOwnEnumerableProperties');
  7715. /*!
  7716. * Checks error against a given set of criteria
  7717. */
  7718. exports.checkError = require('check-error');
  7719. /*!
  7720. * Proxify util
  7721. */
  7722. exports.proxify = require('./proxify');
  7723. /*!
  7724. * addLengthGuard util
  7725. */
  7726. exports.addLengthGuard = require('./addLengthGuard');
  7727. /*!
  7728. * isProxyEnabled helper
  7729. */
  7730. exports.isProxyEnabled = require('./isProxyEnabled');
  7731. /*!
  7732. * isNaN method
  7733. */
  7734. exports.isNaN = require('./isNaN');
  7735. /*!
  7736. * getOperator method
  7737. */
  7738. exports.getOperator = require('./getOperator');
  7739. },{"./addChainableMethod":9,"./addLengthGuard":10,"./addMethod":11,"./addProperty":12,"./compareByInspect":13,"./expectTypes":14,"./flag":15,"./getActual":16,"./getMessage":18,"./getOperator":19,"./getOwnEnumerableProperties":20,"./getOwnEnumerablePropertySymbols":21,"./inspect":24,"./isNaN":25,"./isProxyEnabled":26,"./objDisplay":27,"./overwriteChainableMethod":28,"./overwriteMethod":29,"./overwriteProperty":30,"./proxify":31,"./test":32,"./transferFlags":33,"check-error":35,"deep-eql":36,"get-func-name":37,"pathval":38,"type-detect":39}],24:[function(require,module,exports){
  7740. // This is (almost) directly from Node.js utils
  7741. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
  7742. var getName = require('get-func-name');
  7743. var getProperties = require('./getProperties');
  7744. var getEnumerableProperties = require('./getEnumerableProperties');
  7745. var config = require('../config');
  7746. module.exports = inspect;
  7747. /**
  7748. * ### .inspect(obj, [showHidden], [depth], [colors])
  7749. *
  7750. * Echoes the value of a value. Tries to print the value out
  7751. * in the best way possible given the different types.
  7752. *
  7753. * @param {Object} obj The object to print out.
  7754. * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
  7755. * properties of objects. Default is false.
  7756. * @param {Number} depth Depth in which to descend in object. Default is 2.
  7757. * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
  7758. * output. Default is false (no coloring).
  7759. * @namespace Utils
  7760. * @name inspect
  7761. */
  7762. function inspect(obj, showHidden, depth, colors) {
  7763. var ctx = {
  7764. showHidden: showHidden,
  7765. seen: [],
  7766. stylize: function (str) { return str; }
  7767. };
  7768. return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
  7769. }
  7770. // Returns true if object is a DOM element.
  7771. var isDOMElement = function (object) {
  7772. if (typeof HTMLElement === 'object') {
  7773. return object instanceof HTMLElement;
  7774. } else {
  7775. return object &&
  7776. typeof object === 'object' &&
  7777. 'nodeType' in object &&
  7778. object.nodeType === 1 &&
  7779. typeof object.nodeName === 'string';
  7780. }
  7781. };
  7782. function formatValue(ctx, value, recurseTimes) {
  7783. // Provide a hook for user-specified inspect functions.
  7784. // Check that value is an object with an inspect function on it
  7785. if (value && typeof value.inspect === 'function' &&
  7786. // Filter out the util module, it's inspect function is special
  7787. value.inspect !== exports.inspect &&
  7788. // Also filter out any prototype objects using the circular check.
  7789. !(value.constructor && value.constructor.prototype === value)) {
  7790. var ret = value.inspect(recurseTimes, ctx);
  7791. if (typeof ret !== 'string') {
  7792. ret = formatValue(ctx, ret, recurseTimes);
  7793. }
  7794. return ret;
  7795. }
  7796. // Primitive types cannot have properties
  7797. var primitive = formatPrimitive(ctx, value);
  7798. if (primitive) {
  7799. return primitive;
  7800. }
  7801. // If this is a DOM element, try to get the outer HTML.
  7802. if (isDOMElement(value)) {
  7803. if ('outerHTML' in value) {
  7804. return value.outerHTML;
  7805. // This value does not have an outerHTML attribute,
  7806. // it could still be an XML element
  7807. } else {
  7808. // Attempt to serialize it
  7809. try {
  7810. if (document.xmlVersion) {
  7811. var xmlSerializer = new XMLSerializer();
  7812. return xmlSerializer.serializeToString(value);
  7813. } else {
  7814. // Firefox 11- do not support outerHTML
  7815. // It does, however, support innerHTML
  7816. // Use the following to render the element
  7817. var ns = "http://www.w3.org/1999/xhtml";
  7818. var container = document.createElementNS(ns, '_');
  7819. container.appendChild(value.cloneNode(false));
  7820. var html = container.innerHTML
  7821. .replace('><', '>' + value.innerHTML + '<');
  7822. container.innerHTML = '';
  7823. return html;
  7824. }
  7825. } catch (err) {
  7826. // This could be a non-native DOM implementation,
  7827. // continue with the normal flow:
  7828. // printing the element as if it is an object.
  7829. }
  7830. }
  7831. }
  7832. // Look up the keys of the object.
  7833. var visibleKeys = getEnumerableProperties(value);
  7834. var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
  7835. var name, nameSuffix;
  7836. // Some type of object without properties can be shortcut.
  7837. // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
  7838. // a `stack` plus `description` property; ignore those for consistency.
  7839. if (keys.length === 0 || (isError(value) && (
  7840. (keys.length === 1 && keys[0] === 'stack') ||
  7841. (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
  7842. ))) {
  7843. if (typeof value === 'function') {
  7844. name = getName(value);
  7845. nameSuffix = name ? ': ' + name : '';
  7846. return ctx.stylize('[Function' + nameSuffix + ']', 'special');
  7847. }
  7848. if (isRegExp(value)) {
  7849. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  7850. }
  7851. if (isDate(value)) {
  7852. return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
  7853. }
  7854. if (isError(value)) {
  7855. return formatError(value);
  7856. }
  7857. }
  7858. var base = ''
  7859. , array = false
  7860. , typedArray = false
  7861. , braces = ['{', '}'];
  7862. if (isTypedArray(value)) {
  7863. typedArray = true;
  7864. braces = ['[', ']'];
  7865. }
  7866. // Make Array say that they are Array
  7867. if (isArray(value)) {
  7868. array = true;
  7869. braces = ['[', ']'];
  7870. }
  7871. // Make functions say that they are functions
  7872. if (typeof value === 'function') {
  7873. name = getName(value);
  7874. nameSuffix = name ? ': ' + name : '';
  7875. base = ' [Function' + nameSuffix + ']';
  7876. }
  7877. // Make RegExps say that they are RegExps
  7878. if (isRegExp(value)) {
  7879. base = ' ' + RegExp.prototype.toString.call(value);
  7880. }
  7881. // Make dates with properties first say the date
  7882. if (isDate(value)) {
  7883. base = ' ' + Date.prototype.toUTCString.call(value);
  7884. }
  7885. // Make error with message first say the error
  7886. if (isError(value)) {
  7887. return formatError(value);
  7888. }
  7889. if (keys.length === 0 && (!array || value.length == 0)) {
  7890. return braces[0] + base + braces[1];
  7891. }
  7892. if (recurseTimes < 0) {
  7893. if (isRegExp(value)) {
  7894. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  7895. } else {
  7896. return ctx.stylize('[Object]', 'special');
  7897. }
  7898. }
  7899. ctx.seen.push(value);
  7900. var output;
  7901. if (array) {
  7902. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  7903. } else if (typedArray) {
  7904. return formatTypedArray(value);
  7905. } else {
  7906. output = keys.map(function(key) {
  7907. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  7908. });
  7909. }
  7910. ctx.seen.pop();
  7911. return reduceToSingleString(output, base, braces);
  7912. }
  7913. function formatPrimitive(ctx, value) {
  7914. switch (typeof value) {
  7915. case 'undefined':
  7916. return ctx.stylize('undefined', 'undefined');
  7917. case 'string':
  7918. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  7919. .replace(/'/g, "\\'")
  7920. .replace(/\\"/g, '"') + '\'';
  7921. return ctx.stylize(simple, 'string');
  7922. case 'number':
  7923. if (value === 0 && (1/value) === -Infinity) {
  7924. return ctx.stylize('-0', 'number');
  7925. }
  7926. return ctx.stylize('' + value, 'number');
  7927. case 'boolean':
  7928. return ctx.stylize('' + value, 'boolean');
  7929. case 'symbol':
  7930. return ctx.stylize(value.toString(), 'symbol');
  7931. case 'bigint':
  7932. return ctx.stylize(value.toString() + 'n', 'bigint');
  7933. }
  7934. // For some reason typeof null is "object", so special case here.
  7935. if (value === null) {
  7936. return ctx.stylize('null', 'null');
  7937. }
  7938. }
  7939. function formatError(value) {
  7940. return '[' + Error.prototype.toString.call(value) + ']';
  7941. }
  7942. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  7943. var output = [];
  7944. for (var i = 0, l = value.length; i < l; ++i) {
  7945. if (Object.prototype.hasOwnProperty.call(value, String(i))) {
  7946. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  7947. String(i), true));
  7948. } else {
  7949. output.push('');
  7950. }
  7951. }
  7952. keys.forEach(function(key) {
  7953. if (!key.match(/^\d+$/)) {
  7954. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  7955. key, true));
  7956. }
  7957. });
  7958. return output;
  7959. }
  7960. function formatTypedArray(value) {
  7961. var str = '[ ';
  7962. for (var i = 0; i < value.length; ++i) {
  7963. if (str.length >= config.truncateThreshold - 7) {
  7964. str += '...';
  7965. break;
  7966. }
  7967. str += value[i] + ', ';
  7968. }
  7969. str += ' ]';
  7970. // Removing trailing `, ` if the array was not truncated
  7971. if (str.indexOf(', ]') !== -1) {
  7972. str = str.replace(', ]', ' ]');
  7973. }
  7974. return str;
  7975. }
  7976. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  7977. var name;
  7978. var propDescriptor = Object.getOwnPropertyDescriptor(value, key);
  7979. var str;
  7980. if (propDescriptor) {
  7981. if (propDescriptor.get) {
  7982. if (propDescriptor.set) {
  7983. str = ctx.stylize('[Getter/Setter]', 'special');
  7984. } else {
  7985. str = ctx.stylize('[Getter]', 'special');
  7986. }
  7987. } else {
  7988. if (propDescriptor.set) {
  7989. str = ctx.stylize('[Setter]', 'special');
  7990. }
  7991. }
  7992. }
  7993. if (visibleKeys.indexOf(key) < 0) {
  7994. name = '[' + key + ']';
  7995. }
  7996. if (!str) {
  7997. if (ctx.seen.indexOf(value[key]) < 0) {
  7998. if (recurseTimes === null) {
  7999. str = formatValue(ctx, value[key], null);
  8000. } else {
  8001. str = formatValue(ctx, value[key], recurseTimes - 1);
  8002. }
  8003. if (str.indexOf('\n') > -1) {
  8004. if (array) {
  8005. str = str.split('\n').map(function(line) {
  8006. return ' ' + line;
  8007. }).join('\n').substr(2);
  8008. } else {
  8009. str = '\n' + str.split('\n').map(function(line) {
  8010. return ' ' + line;
  8011. }).join('\n');
  8012. }
  8013. }
  8014. } else {
  8015. str = ctx.stylize('[Circular]', 'special');
  8016. }
  8017. }
  8018. if (typeof name === 'undefined') {
  8019. if (array && key.match(/^\d+$/)) {
  8020. return str;
  8021. }
  8022. name = JSON.stringify('' + key);
  8023. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  8024. name = name.substr(1, name.length - 2);
  8025. name = ctx.stylize(name, 'name');
  8026. } else {
  8027. name = name.replace(/'/g, "\\'")
  8028. .replace(/\\"/g, '"')
  8029. .replace(/(^"|"$)/g, "'");
  8030. name = ctx.stylize(name, 'string');
  8031. }
  8032. }
  8033. return name + ': ' + str;
  8034. }
  8035. function reduceToSingleString(output, base, braces) {
  8036. var length = output.reduce(function(prev, cur) {
  8037. return prev + cur.length + 1;
  8038. }, 0);
  8039. if (length > 60) {
  8040. return braces[0] +
  8041. (base === '' ? '' : base + '\n ') +
  8042. ' ' +
  8043. output.join(',\n ') +
  8044. ' ' +
  8045. braces[1];
  8046. }
  8047. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  8048. }
  8049. function isTypedArray(ar) {
  8050. // Unfortunately there's no way to check if an object is a TypedArray
  8051. // We have to check if it's one of these types
  8052. return (typeof ar === 'object' && /\w+Array]$/.test(objectToString(ar)));
  8053. }
  8054. function isArray(ar) {
  8055. return Array.isArray(ar) ||
  8056. (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  8057. }
  8058. function isRegExp(re) {
  8059. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  8060. }
  8061. function isDate(d) {
  8062. return typeof d === 'object' && objectToString(d) === '[object Date]';
  8063. }
  8064. function isError(e) {
  8065. return typeof e === 'object' && objectToString(e) === '[object Error]';
  8066. }
  8067. function objectToString(o) {
  8068. return Object.prototype.toString.call(o);
  8069. }
  8070. },{"../config":4,"./getEnumerableProperties":17,"./getProperties":22,"get-func-name":37}],25:[function(require,module,exports){
  8071. /*!
  8072. * Chai - isNaN utility
  8073. * Copyright(c) 2012-2015 Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  8074. * MIT Licensed
  8075. */
  8076. /**
  8077. * ### .isNaN(value)
  8078. *
  8079. * Checks if the given value is NaN or not.
  8080. *
  8081. * utils.isNaN(NaN); // true
  8082. *
  8083. * @param {Value} The value which has to be checked if it is NaN
  8084. * @name isNaN
  8085. * @api private
  8086. */
  8087. function isNaN(value) {
  8088. // Refer http://www.ecma-international.org/ecma-262/6.0/#sec-isnan-number
  8089. // section's NOTE.
  8090. return value !== value;
  8091. }
  8092. // If ECMAScript 6's Number.isNaN is present, prefer that.
  8093. module.exports = Number.isNaN || isNaN;
  8094. },{}],26:[function(require,module,exports){
  8095. var config = require('../config');
  8096. /*!
  8097. * Chai - isProxyEnabled helper
  8098. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8099. * MIT Licensed
  8100. */
  8101. /**
  8102. * ### .isProxyEnabled()
  8103. *
  8104. * Helper function to check if Chai's proxy protection feature is enabled. If
  8105. * proxies are unsupported or disabled via the user's Chai config, then return
  8106. * false. Otherwise, return true.
  8107. *
  8108. * @namespace Utils
  8109. * @name isProxyEnabled
  8110. */
  8111. module.exports = function isProxyEnabled() {
  8112. return config.useProxy &&
  8113. typeof Proxy !== 'undefined' &&
  8114. typeof Reflect !== 'undefined';
  8115. };
  8116. },{"../config":4}],27:[function(require,module,exports){
  8117. /*!
  8118. * Chai - flag utility
  8119. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8120. * MIT Licensed
  8121. */
  8122. /*!
  8123. * Module dependencies
  8124. */
  8125. var inspect = require('./inspect');
  8126. var config = require('../config');
  8127. /**
  8128. * ### .objDisplay(object)
  8129. *
  8130. * Determines if an object or an array matches
  8131. * criteria to be inspected in-line for error
  8132. * messages or should be truncated.
  8133. *
  8134. * @param {Mixed} javascript object to inspect
  8135. * @name objDisplay
  8136. * @namespace Utils
  8137. * @api public
  8138. */
  8139. module.exports = function objDisplay(obj) {
  8140. var str = inspect(obj)
  8141. , type = Object.prototype.toString.call(obj);
  8142. if (config.truncateThreshold && str.length >= config.truncateThreshold) {
  8143. if (type === '[object Function]') {
  8144. return !obj.name || obj.name === ''
  8145. ? '[Function]'
  8146. : '[Function: ' + obj.name + ']';
  8147. } else if (type === '[object Array]') {
  8148. return '[ Array(' + obj.length + ') ]';
  8149. } else if (type === '[object Object]') {
  8150. var keys = Object.keys(obj)
  8151. , kstr = keys.length > 2
  8152. ? keys.splice(0, 2).join(', ') + ', ...'
  8153. : keys.join(', ');
  8154. return '{ Object (' + kstr + ') }';
  8155. } else {
  8156. return str;
  8157. }
  8158. } else {
  8159. return str;
  8160. }
  8161. };
  8162. },{"../config":4,"./inspect":24}],28:[function(require,module,exports){
  8163. /*!
  8164. * Chai - overwriteChainableMethod utility
  8165. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8166. * MIT Licensed
  8167. */
  8168. var chai = require('../../chai');
  8169. var transferFlags = require('./transferFlags');
  8170. /**
  8171. * ### .overwriteChainableMethod(ctx, name, method, chainingBehavior)
  8172. *
  8173. * Overwrites an already existing chainable method
  8174. * and provides access to the previous function or
  8175. * property. Must return functions to be used for
  8176. * name.
  8177. *
  8178. * utils.overwriteChainableMethod(chai.Assertion.prototype, 'lengthOf',
  8179. * function (_super) {
  8180. * }
  8181. * , function (_super) {
  8182. * }
  8183. * );
  8184. *
  8185. * Can also be accessed directly from `chai.Assertion`.
  8186. *
  8187. * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
  8188. *
  8189. * Then can be used as any other assertion.
  8190. *
  8191. * expect(myFoo).to.have.lengthOf(3);
  8192. * expect(myFoo).to.have.lengthOf.above(3);
  8193. *
  8194. * @param {Object} ctx object whose method / property is to be overwritten
  8195. * @param {String} name of method / property to overwrite
  8196. * @param {Function} method function that returns a function to be used for name
  8197. * @param {Function} chainingBehavior function that returns a function to be used for property
  8198. * @namespace Utils
  8199. * @name overwriteChainableMethod
  8200. * @api public
  8201. */
  8202. module.exports = function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
  8203. var chainableBehavior = ctx.__methods[name];
  8204. var _chainingBehavior = chainableBehavior.chainingBehavior;
  8205. chainableBehavior.chainingBehavior = function overwritingChainableMethodGetter() {
  8206. var result = chainingBehavior(_chainingBehavior).call(this);
  8207. if (result !== undefined) {
  8208. return result;
  8209. }
  8210. var newAssertion = new chai.Assertion();
  8211. transferFlags(this, newAssertion);
  8212. return newAssertion;
  8213. };
  8214. var _method = chainableBehavior.method;
  8215. chainableBehavior.method = function overwritingChainableMethodWrapper() {
  8216. var result = method(_method).apply(this, arguments);
  8217. if (result !== undefined) {
  8218. return result;
  8219. }
  8220. var newAssertion = new chai.Assertion();
  8221. transferFlags(this, newAssertion);
  8222. return newAssertion;
  8223. };
  8224. };
  8225. },{"../../chai":2,"./transferFlags":33}],29:[function(require,module,exports){
  8226. /*!
  8227. * Chai - overwriteMethod utility
  8228. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8229. * MIT Licensed
  8230. */
  8231. var addLengthGuard = require('./addLengthGuard');
  8232. var chai = require('../../chai');
  8233. var flag = require('./flag');
  8234. var proxify = require('./proxify');
  8235. var transferFlags = require('./transferFlags');
  8236. /**
  8237. * ### .overwriteMethod(ctx, name, fn)
  8238. *
  8239. * Overwrites an already existing method and provides
  8240. * access to previous function. Must return function
  8241. * to be used for name.
  8242. *
  8243. * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
  8244. * return function (str) {
  8245. * var obj = utils.flag(this, 'object');
  8246. * if (obj instanceof Foo) {
  8247. * new chai.Assertion(obj.value).to.equal(str);
  8248. * } else {
  8249. * _super.apply(this, arguments);
  8250. * }
  8251. * }
  8252. * });
  8253. *
  8254. * Can also be accessed directly from `chai.Assertion`.
  8255. *
  8256. * chai.Assertion.overwriteMethod('foo', fn);
  8257. *
  8258. * Then can be used as any other assertion.
  8259. *
  8260. * expect(myFoo).to.equal('bar');
  8261. *
  8262. * @param {Object} ctx object whose method is to be overwritten
  8263. * @param {String} name of method to overwrite
  8264. * @param {Function} method function that returns a function to be used for name
  8265. * @namespace Utils
  8266. * @name overwriteMethod
  8267. * @api public
  8268. */
  8269. module.exports = function overwriteMethod(ctx, name, method) {
  8270. var _method = ctx[name]
  8271. , _super = function () {
  8272. throw new Error(name + ' is not a function');
  8273. };
  8274. if (_method && 'function' === typeof _method)
  8275. _super = _method;
  8276. var overwritingMethodWrapper = function () {
  8277. // Setting the `ssfi` flag to `overwritingMethodWrapper` causes this
  8278. // function to be the starting point for removing implementation frames from
  8279. // the stack trace of a failed assertion.
  8280. //
  8281. // However, we only want to use this function as the starting point if the
  8282. // `lockSsfi` flag isn't set.
  8283. //
  8284. // If the `lockSsfi` flag is set, then either this assertion has been
  8285. // overwritten by another assertion, or this assertion is being invoked from
  8286. // inside of another assertion. In the first case, the `ssfi` flag has
  8287. // already been set by the overwriting assertion. In the second case, the
  8288. // `ssfi` flag has already been set by the outer assertion.
  8289. if (!flag(this, 'lockSsfi')) {
  8290. flag(this, 'ssfi', overwritingMethodWrapper);
  8291. }
  8292. // Setting the `lockSsfi` flag to `true` prevents the overwritten assertion
  8293. // from changing the `ssfi` flag. By this point, the `ssfi` flag is already
  8294. // set to the correct starting point for this assertion.
  8295. var origLockSsfi = flag(this, 'lockSsfi');
  8296. flag(this, 'lockSsfi', true);
  8297. var result = method(_super).apply(this, arguments);
  8298. flag(this, 'lockSsfi', origLockSsfi);
  8299. if (result !== undefined) {
  8300. return result;
  8301. }
  8302. var newAssertion = new chai.Assertion();
  8303. transferFlags(this, newAssertion);
  8304. return newAssertion;
  8305. }
  8306. addLengthGuard(overwritingMethodWrapper, name, false);
  8307. ctx[name] = proxify(overwritingMethodWrapper, name);
  8308. };
  8309. },{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":31,"./transferFlags":33}],30:[function(require,module,exports){
  8310. /*!
  8311. * Chai - overwriteProperty utility
  8312. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8313. * MIT Licensed
  8314. */
  8315. var chai = require('../../chai');
  8316. var flag = require('./flag');
  8317. var isProxyEnabled = require('./isProxyEnabled');
  8318. var transferFlags = require('./transferFlags');
  8319. /**
  8320. * ### .overwriteProperty(ctx, name, fn)
  8321. *
  8322. * Overwrites an already existing property getter and provides
  8323. * access to previous value. Must return function to use as getter.
  8324. *
  8325. * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
  8326. * return function () {
  8327. * var obj = utils.flag(this, 'object');
  8328. * if (obj instanceof Foo) {
  8329. * new chai.Assertion(obj.name).to.equal('bar');
  8330. * } else {
  8331. * _super.call(this);
  8332. * }
  8333. * }
  8334. * });
  8335. *
  8336. *
  8337. * Can also be accessed directly from `chai.Assertion`.
  8338. *
  8339. * chai.Assertion.overwriteProperty('foo', fn);
  8340. *
  8341. * Then can be used as any other assertion.
  8342. *
  8343. * expect(myFoo).to.be.ok;
  8344. *
  8345. * @param {Object} ctx object whose property is to be overwritten
  8346. * @param {String} name of property to overwrite
  8347. * @param {Function} getter function that returns a getter function to be used for name
  8348. * @namespace Utils
  8349. * @name overwriteProperty
  8350. * @api public
  8351. */
  8352. module.exports = function overwriteProperty(ctx, name, getter) {
  8353. var _get = Object.getOwnPropertyDescriptor(ctx, name)
  8354. , _super = function () {};
  8355. if (_get && 'function' === typeof _get.get)
  8356. _super = _get.get
  8357. Object.defineProperty(ctx, name,
  8358. { get: function overwritingPropertyGetter() {
  8359. // Setting the `ssfi` flag to `overwritingPropertyGetter` causes this
  8360. // function to be the starting point for removing implementation frames
  8361. // from the stack trace of a failed assertion.
  8362. //
  8363. // However, we only want to use this function as the starting point if
  8364. // the `lockSsfi` flag isn't set and proxy protection is disabled.
  8365. //
  8366. // If the `lockSsfi` flag is set, then either this assertion has been
  8367. // overwritten by another assertion, or this assertion is being invoked
  8368. // from inside of another assertion. In the first case, the `ssfi` flag
  8369. // has already been set by the overwriting assertion. In the second
  8370. // case, the `ssfi` flag has already been set by the outer assertion.
  8371. //
  8372. // If proxy protection is enabled, then the `ssfi` flag has already been
  8373. // set by the proxy getter.
  8374. if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
  8375. flag(this, 'ssfi', overwritingPropertyGetter);
  8376. }
  8377. // Setting the `lockSsfi` flag to `true` prevents the overwritten
  8378. // assertion from changing the `ssfi` flag. By this point, the `ssfi`
  8379. // flag is already set to the correct starting point for this assertion.
  8380. var origLockSsfi = flag(this, 'lockSsfi');
  8381. flag(this, 'lockSsfi', true);
  8382. var result = getter(_super).call(this);
  8383. flag(this, 'lockSsfi', origLockSsfi);
  8384. if (result !== undefined) {
  8385. return result;
  8386. }
  8387. var newAssertion = new chai.Assertion();
  8388. transferFlags(this, newAssertion);
  8389. return newAssertion;
  8390. }
  8391. , configurable: true
  8392. });
  8393. };
  8394. },{"../../chai":2,"./flag":15,"./isProxyEnabled":26,"./transferFlags":33}],31:[function(require,module,exports){
  8395. var config = require('../config');
  8396. var flag = require('./flag');
  8397. var getProperties = require('./getProperties');
  8398. var isProxyEnabled = require('./isProxyEnabled');
  8399. /*!
  8400. * Chai - proxify utility
  8401. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8402. * MIT Licensed
  8403. */
  8404. /**
  8405. * ### .proxify(object)
  8406. *
  8407. * Return a proxy of given object that throws an error when a non-existent
  8408. * property is read. By default, the root cause is assumed to be a misspelled
  8409. * property, and thus an attempt is made to offer a reasonable suggestion from
  8410. * the list of existing properties. However, if a nonChainableMethodName is
  8411. * provided, then the root cause is instead a failure to invoke a non-chainable
  8412. * method prior to reading the non-existent property.
  8413. *
  8414. * If proxies are unsupported or disabled via the user's Chai config, then
  8415. * return object without modification.
  8416. *
  8417. * @param {Object} obj
  8418. * @param {String} nonChainableMethodName
  8419. * @namespace Utils
  8420. * @name proxify
  8421. */
  8422. var builtins = ['__flags', '__methods', '_obj', 'assert'];
  8423. module.exports = function proxify(obj, nonChainableMethodName) {
  8424. if (!isProxyEnabled()) return obj;
  8425. return new Proxy(obj, {
  8426. get: function proxyGetter(target, property) {
  8427. // This check is here because we should not throw errors on Symbol properties
  8428. // such as `Symbol.toStringTag`.
  8429. // The values for which an error should be thrown can be configured using
  8430. // the `config.proxyExcludedKeys` setting.
  8431. if (typeof property === 'string' &&
  8432. config.proxyExcludedKeys.indexOf(property) === -1 &&
  8433. !Reflect.has(target, property)) {
  8434. // Special message for invalid property access of non-chainable methods.
  8435. if (nonChainableMethodName) {
  8436. throw Error('Invalid Chai property: ' + nonChainableMethodName + '.' +
  8437. property + '. See docs for proper usage of "' +
  8438. nonChainableMethodName + '".');
  8439. }
  8440. // If the property is reasonably close to an existing Chai property,
  8441. // suggest that property to the user. Only suggest properties with a
  8442. // distance less than 4.
  8443. var suggestion = null;
  8444. var suggestionDistance = 4;
  8445. getProperties(target).forEach(function(prop) {
  8446. if (
  8447. !Object.prototype.hasOwnProperty(prop) &&
  8448. builtins.indexOf(prop) === -1
  8449. ) {
  8450. var dist = stringDistanceCapped(
  8451. property,
  8452. prop,
  8453. suggestionDistance
  8454. );
  8455. if (dist < suggestionDistance) {
  8456. suggestion = prop;
  8457. suggestionDistance = dist;
  8458. }
  8459. }
  8460. });
  8461. if (suggestion !== null) {
  8462. throw Error('Invalid Chai property: ' + property +
  8463. '. Did you mean "' + suggestion + '"?');
  8464. } else {
  8465. throw Error('Invalid Chai property: ' + property);
  8466. }
  8467. }
  8468. // Use this proxy getter as the starting point for removing implementation
  8469. // frames from the stack trace of a failed assertion. For property
  8470. // assertions, this prevents the proxy getter from showing up in the stack
  8471. // trace since it's invoked before the property getter. For method and
  8472. // chainable method assertions, this flag will end up getting changed to
  8473. // the method wrapper, which is good since this frame will no longer be in
  8474. // the stack once the method is invoked. Note that Chai builtin assertion
  8475. // properties such as `__flags` are skipped since this is only meant to
  8476. // capture the starting point of an assertion. This step is also skipped
  8477. // if the `lockSsfi` flag is set, thus indicating that this assertion is
  8478. // being called from within another assertion. In that case, the `ssfi`
  8479. // flag is already set to the outer assertion's starting point.
  8480. if (builtins.indexOf(property) === -1 && !flag(target, 'lockSsfi')) {
  8481. flag(target, 'ssfi', proxyGetter);
  8482. }
  8483. return Reflect.get(target, property);
  8484. }
  8485. });
  8486. };
  8487. /**
  8488. * # stringDistanceCapped(strA, strB, cap)
  8489. * Return the Levenshtein distance between two strings, but no more than cap.
  8490. * @param {string} strA
  8491. * @param {string} strB
  8492. * @param {number} number
  8493. * @return {number} min(string distance between strA and strB, cap)
  8494. * @api private
  8495. */
  8496. function stringDistanceCapped(strA, strB, cap) {
  8497. if (Math.abs(strA.length - strB.length) >= cap) {
  8498. return cap;
  8499. }
  8500. var memo = [];
  8501. // `memo` is a two-dimensional array containing distances.
  8502. // memo[i][j] is the distance between strA.slice(0, i) and
  8503. // strB.slice(0, j).
  8504. for (var i = 0; i <= strA.length; i++) {
  8505. memo[i] = Array(strB.length + 1).fill(0);
  8506. memo[i][0] = i;
  8507. }
  8508. for (var j = 0; j < strB.length; j++) {
  8509. memo[0][j] = j;
  8510. }
  8511. for (var i = 1; i <= strA.length; i++) {
  8512. var ch = strA.charCodeAt(i - 1);
  8513. for (var j = 1; j <= strB.length; j++) {
  8514. if (Math.abs(i - j) >= cap) {
  8515. memo[i][j] = cap;
  8516. continue;
  8517. }
  8518. memo[i][j] = Math.min(
  8519. memo[i - 1][j] + 1,
  8520. memo[i][j - 1] + 1,
  8521. memo[i - 1][j - 1] +
  8522. (ch === strB.charCodeAt(j - 1) ? 0 : 1)
  8523. );
  8524. }
  8525. }
  8526. return memo[strA.length][strB.length];
  8527. }
  8528. },{"../config":4,"./flag":15,"./getProperties":22,"./isProxyEnabled":26}],32:[function(require,module,exports){
  8529. /*!
  8530. * Chai - test utility
  8531. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8532. * MIT Licensed
  8533. */
  8534. /*!
  8535. * Module dependencies
  8536. */
  8537. var flag = require('./flag');
  8538. /**
  8539. * ### .test(object, expression)
  8540. *
  8541. * Test and object for expression.
  8542. *
  8543. * @param {Object} object (constructed Assertion)
  8544. * @param {Arguments} chai.Assertion.prototype.assert arguments
  8545. * @namespace Utils
  8546. * @name test
  8547. */
  8548. module.exports = function test(obj, args) {
  8549. var negate = flag(obj, 'negate')
  8550. , expr = args[0];
  8551. return negate ? !expr : expr;
  8552. };
  8553. },{"./flag":15}],33:[function(require,module,exports){
  8554. /*!
  8555. * Chai - transferFlags utility
  8556. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8557. * MIT Licensed
  8558. */
  8559. /**
  8560. * ### .transferFlags(assertion, object, includeAll = true)
  8561. *
  8562. * Transfer all the flags for `assertion` to `object`. If
  8563. * `includeAll` is set to `false`, then the base Chai
  8564. * assertion flags (namely `object`, `ssfi`, `lockSsfi`,
  8565. * and `message`) will not be transferred.
  8566. *
  8567. *
  8568. * var newAssertion = new Assertion();
  8569. * utils.transferFlags(assertion, newAssertion);
  8570. *
  8571. * var anotherAssertion = new Assertion(myObj);
  8572. * utils.transferFlags(assertion, anotherAssertion, false);
  8573. *
  8574. * @param {Assertion} assertion the assertion to transfer the flags from
  8575. * @param {Object} object the object to transfer the flags to; usually a new assertion
  8576. * @param {Boolean} includeAll
  8577. * @namespace Utils
  8578. * @name transferFlags
  8579. * @api private
  8580. */
  8581. module.exports = function transferFlags(assertion, object, includeAll) {
  8582. var flags = assertion.__flags || (assertion.__flags = Object.create(null));
  8583. if (!object.__flags) {
  8584. object.__flags = Object.create(null);
  8585. }
  8586. includeAll = arguments.length === 3 ? includeAll : true;
  8587. for (var flag in flags) {
  8588. if (includeAll ||
  8589. (flag !== 'object' && flag !== 'ssfi' && flag !== 'lockSsfi' && flag != 'message')) {
  8590. object.__flags[flag] = flags[flag];
  8591. }
  8592. }
  8593. };
  8594. },{}],34:[function(require,module,exports){
  8595. /*!
  8596. * assertion-error
  8597. * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
  8598. * MIT Licensed
  8599. */
  8600. /*!
  8601. * Return a function that will copy properties from
  8602. * one object to another excluding any originally
  8603. * listed. Returned function will create a new `{}`.
  8604. *
  8605. * @param {String} excluded properties ...
  8606. * @return {Function}
  8607. */
  8608. function exclude () {
  8609. var excludes = [].slice.call(arguments);
  8610. function excludeProps (res, obj) {
  8611. Object.keys(obj).forEach(function (key) {
  8612. if (!~excludes.indexOf(key)) res[key] = obj[key];
  8613. });
  8614. }
  8615. return function extendExclude () {
  8616. var args = [].slice.call(arguments)
  8617. , i = 0
  8618. , res = {};
  8619. for (; i < args.length; i++) {
  8620. excludeProps(res, args[i]);
  8621. }
  8622. return res;
  8623. };
  8624. };
  8625. /*!
  8626. * Primary Exports
  8627. */
  8628. module.exports = AssertionError;
  8629. /**
  8630. * ### AssertionError
  8631. *
  8632. * An extension of the JavaScript `Error` constructor for
  8633. * assertion and validation scenarios.
  8634. *
  8635. * @param {String} message
  8636. * @param {Object} properties to include (optional)
  8637. * @param {callee} start stack function (optional)
  8638. */
  8639. function AssertionError (message, _props, ssf) {
  8640. var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
  8641. , props = extend(_props || {});
  8642. // default values
  8643. this.message = message || 'Unspecified AssertionError';
  8644. this.showDiff = false;
  8645. // copy from properties
  8646. for (var key in props) {
  8647. this[key] = props[key];
  8648. }
  8649. // capture stack trace
  8650. ssf = ssf || AssertionError;
  8651. if (Error.captureStackTrace) {
  8652. Error.captureStackTrace(this, ssf);
  8653. } else {
  8654. try {
  8655. throw new Error();
  8656. } catch(e) {
  8657. this.stack = e.stack;
  8658. }
  8659. }
  8660. }
  8661. /*!
  8662. * Inherit from Error.prototype
  8663. */
  8664. AssertionError.prototype = Object.create(Error.prototype);
  8665. /*!
  8666. * Statically set name
  8667. */
  8668. AssertionError.prototype.name = 'AssertionError';
  8669. /*!
  8670. * Ensure correct constructor
  8671. */
  8672. AssertionError.prototype.constructor = AssertionError;
  8673. /**
  8674. * Allow errors to be converted to JSON for static transfer.
  8675. *
  8676. * @param {Boolean} include stack (default: `true`)
  8677. * @return {Object} object that can be `JSON.stringify`
  8678. */
  8679. AssertionError.prototype.toJSON = function (stack) {
  8680. var extend = exclude('constructor', 'toJSON', 'stack')
  8681. , props = extend({ name: this.name }, this);
  8682. // include stack if exists and not turned off
  8683. if (false !== stack && this.stack) {
  8684. props.stack = this.stack;
  8685. }
  8686. return props;
  8687. };
  8688. },{}],35:[function(require,module,exports){
  8689. 'use strict';
  8690. /* !
  8691. * Chai - checkError utility
  8692. * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
  8693. * MIT Licensed
  8694. */
  8695. /**
  8696. * ### .checkError
  8697. *
  8698. * Checks that an error conforms to a given set of criteria and/or retrieves information about it.
  8699. *
  8700. * @api public
  8701. */
  8702. /**
  8703. * ### .compatibleInstance(thrown, errorLike)
  8704. *
  8705. * Checks if two instances are compatible (strict equal).
  8706. * Returns false if errorLike is not an instance of Error, because instances
  8707. * can only be compatible if they're both error instances.
  8708. *
  8709. * @name compatibleInstance
  8710. * @param {Error} thrown error
  8711. * @param {Error|ErrorConstructor} errorLike object to compare against
  8712. * @namespace Utils
  8713. * @api public
  8714. */
  8715. function compatibleInstance(thrown, errorLike) {
  8716. return errorLike instanceof Error && thrown === errorLike;
  8717. }
  8718. /**
  8719. * ### .compatibleConstructor(thrown, errorLike)
  8720. *
  8721. * Checks if two constructors are compatible.
  8722. * This function can receive either an error constructor or
  8723. * an error instance as the `errorLike` argument.
  8724. * Constructors are compatible if they're the same or if one is
  8725. * an instance of another.
  8726. *
  8727. * @name compatibleConstructor
  8728. * @param {Error} thrown error
  8729. * @param {Error|ErrorConstructor} errorLike object to compare against
  8730. * @namespace Utils
  8731. * @api public
  8732. */
  8733. function compatibleConstructor(thrown, errorLike) {
  8734. if (errorLike instanceof Error) {
  8735. // If `errorLike` is an instance of any error we compare their constructors
  8736. return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
  8737. } else if (errorLike.prototype instanceof Error || errorLike === Error) {
  8738. // If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly
  8739. return thrown.constructor === errorLike || thrown instanceof errorLike;
  8740. }
  8741. return false;
  8742. }
  8743. /**
  8744. * ### .compatibleMessage(thrown, errMatcher)
  8745. *
  8746. * Checks if an error's message is compatible with a matcher (String or RegExp).
  8747. * If the message contains the String or passes the RegExp test,
  8748. * it is considered compatible.
  8749. *
  8750. * @name compatibleMessage
  8751. * @param {Error} thrown error
  8752. * @param {String|RegExp} errMatcher to look for into the message
  8753. * @namespace Utils
  8754. * @api public
  8755. */
  8756. function compatibleMessage(thrown, errMatcher) {
  8757. var comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
  8758. if (errMatcher instanceof RegExp) {
  8759. return errMatcher.test(comparisonString);
  8760. } else if (typeof errMatcher === 'string') {
  8761. return comparisonString.indexOf(errMatcher) !== -1; // eslint-disable-line no-magic-numbers
  8762. }
  8763. return false;
  8764. }
  8765. /**
  8766. * ### .getFunctionName(constructorFn)
  8767. *
  8768. * Returns the name of a function.
  8769. * This also includes a polyfill function if `constructorFn.name` is not defined.
  8770. *
  8771. * @name getFunctionName
  8772. * @param {Function} constructorFn
  8773. * @namespace Utils
  8774. * @api private
  8775. */
  8776. var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\(\/]+)/;
  8777. function getFunctionName(constructorFn) {
  8778. var name = '';
  8779. if (typeof constructorFn.name === 'undefined') {
  8780. // Here we run a polyfill if constructorFn.name is not defined
  8781. var match = String(constructorFn).match(functionNameMatch);
  8782. if (match) {
  8783. name = match[1];
  8784. }
  8785. } else {
  8786. name = constructorFn.name;
  8787. }
  8788. return name;
  8789. }
  8790. /**
  8791. * ### .getConstructorName(errorLike)
  8792. *
  8793. * Gets the constructor name for an Error instance or constructor itself.
  8794. *
  8795. * @name getConstructorName
  8796. * @param {Error|ErrorConstructor} errorLike
  8797. * @namespace Utils
  8798. * @api public
  8799. */
  8800. function getConstructorName(errorLike) {
  8801. var constructorName = errorLike;
  8802. if (errorLike instanceof Error) {
  8803. constructorName = getFunctionName(errorLike.constructor);
  8804. } else if (typeof errorLike === 'function') {
  8805. // If `err` is not an instance of Error it is an error constructor itself or another function.
  8806. // If we've got a common function we get its name, otherwise we may need to create a new instance
  8807. // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
  8808. constructorName = getFunctionName(errorLike).trim() ||
  8809. getFunctionName(new errorLike()); // eslint-disable-line new-cap
  8810. }
  8811. return constructorName;
  8812. }
  8813. /**
  8814. * ### .getMessage(errorLike)
  8815. *
  8816. * Gets the error message from an error.
  8817. * If `err` is a String itself, we return it.
  8818. * If the error has no message, we return an empty string.
  8819. *
  8820. * @name getMessage
  8821. * @param {Error|String} errorLike
  8822. * @namespace Utils
  8823. * @api public
  8824. */
  8825. function getMessage(errorLike) {
  8826. var msg = '';
  8827. if (errorLike && errorLike.message) {
  8828. msg = errorLike.message;
  8829. } else if (typeof errorLike === 'string') {
  8830. msg = errorLike;
  8831. }
  8832. return msg;
  8833. }
  8834. module.exports = {
  8835. compatibleInstance: compatibleInstance,
  8836. compatibleConstructor: compatibleConstructor,
  8837. compatibleMessage: compatibleMessage,
  8838. getMessage: getMessage,
  8839. getConstructorName: getConstructorName,
  8840. };
  8841. },{}],36:[function(require,module,exports){
  8842. 'use strict';
  8843. /* globals Symbol: false, Uint8Array: false, WeakMap: false */
  8844. /*!
  8845. * deep-eql
  8846. * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
  8847. * MIT Licensed
  8848. */
  8849. var type = require('type-detect');
  8850. function FakeMap() {
  8851. this._key = 'chai/deep-eql__' + Math.random() + Date.now();
  8852. }
  8853. FakeMap.prototype = {
  8854. get: function getMap(key) {
  8855. return key[this._key];
  8856. },
  8857. set: function setMap(key, value) {
  8858. if (Object.isExtensible(key)) {
  8859. Object.defineProperty(key, this._key, {
  8860. value: value,
  8861. configurable: true,
  8862. });
  8863. }
  8864. },
  8865. };
  8866. var MemoizeMap = typeof WeakMap === 'function' ? WeakMap : FakeMap;
  8867. /*!
  8868. * Check to see if the MemoizeMap has recorded a result of the two operands
  8869. *
  8870. * @param {Mixed} leftHandOperand
  8871. * @param {Mixed} rightHandOperand
  8872. * @param {MemoizeMap} memoizeMap
  8873. * @returns {Boolean|null} result
  8874. */
  8875. function memoizeCompare(leftHandOperand, rightHandOperand, memoizeMap) {
  8876. // Technically, WeakMap keys can *only* be objects, not primitives.
  8877. if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  8878. return null;
  8879. }
  8880. var leftHandMap = memoizeMap.get(leftHandOperand);
  8881. if (leftHandMap) {
  8882. var result = leftHandMap.get(rightHandOperand);
  8883. if (typeof result === 'boolean') {
  8884. return result;
  8885. }
  8886. }
  8887. return null;
  8888. }
  8889. /*!
  8890. * Set the result of the equality into the MemoizeMap
  8891. *
  8892. * @param {Mixed} leftHandOperand
  8893. * @param {Mixed} rightHandOperand
  8894. * @param {MemoizeMap} memoizeMap
  8895. * @param {Boolean} result
  8896. */
  8897. function memoizeSet(leftHandOperand, rightHandOperand, memoizeMap, result) {
  8898. // Technically, WeakMap keys can *only* be objects, not primitives.
  8899. if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  8900. return;
  8901. }
  8902. var leftHandMap = memoizeMap.get(leftHandOperand);
  8903. if (leftHandMap) {
  8904. leftHandMap.set(rightHandOperand, result);
  8905. } else {
  8906. leftHandMap = new MemoizeMap();
  8907. leftHandMap.set(rightHandOperand, result);
  8908. memoizeMap.set(leftHandOperand, leftHandMap);
  8909. }
  8910. }
  8911. /*!
  8912. * Primary Export
  8913. */
  8914. module.exports = deepEqual;
  8915. module.exports.MemoizeMap = MemoizeMap;
  8916. /**
  8917. * Assert deeply nested sameValue equality between two objects of any type.
  8918. *
  8919. * @param {Mixed} leftHandOperand
  8920. * @param {Mixed} rightHandOperand
  8921. * @param {Object} [options] (optional) Additional options
  8922. * @param {Array} [options.comparator] (optional) Override default algorithm, determining custom equality.
  8923. * @param {Array} [options.memoize] (optional) Provide a custom memoization object which will cache the results of
  8924. complex objects for a speed boost. By passing `false` you can disable memoization, but this will cause circular
  8925. references to blow the stack.
  8926. * @return {Boolean} equal match
  8927. */
  8928. function deepEqual(leftHandOperand, rightHandOperand, options) {
  8929. // If we have a comparator, we can't assume anything; so bail to its check first.
  8930. if (options && options.comparator) {
  8931. return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
  8932. }
  8933. var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
  8934. if (simpleResult !== null) {
  8935. return simpleResult;
  8936. }
  8937. // Deeper comparisons are pushed through to a larger function
  8938. return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
  8939. }
  8940. /**
  8941. * Many comparisons can be canceled out early via simple equality or primitive checks.
  8942. * @param {Mixed} leftHandOperand
  8943. * @param {Mixed} rightHandOperand
  8944. * @return {Boolean|null} equal match
  8945. */
  8946. function simpleEqual(leftHandOperand, rightHandOperand) {
  8947. // Equal references (except for Numbers) can be returned early
  8948. if (leftHandOperand === rightHandOperand) {
  8949. // Handle +-0 cases
  8950. return leftHandOperand !== 0 || 1 / leftHandOperand === 1 / rightHandOperand;
  8951. }
  8952. // handle NaN cases
  8953. if (
  8954. leftHandOperand !== leftHandOperand && // eslint-disable-line no-self-compare
  8955. rightHandOperand !== rightHandOperand // eslint-disable-line no-self-compare
  8956. ) {
  8957. return true;
  8958. }
  8959. // Anything that is not an 'object', i.e. symbols, functions, booleans, numbers,
  8960. // strings, and undefined, can be compared by reference.
  8961. if (isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  8962. // Easy out b/c it would have passed the first equality check
  8963. return false;
  8964. }
  8965. return null;
  8966. }
  8967. /*!
  8968. * The main logic of the `deepEqual` function.
  8969. *
  8970. * @param {Mixed} leftHandOperand
  8971. * @param {Mixed} rightHandOperand
  8972. * @param {Object} [options] (optional) Additional options
  8973. * @param {Array} [options.comparator] (optional) Override default algorithm, determining custom equality.
  8974. * @param {Array} [options.memoize] (optional) Provide a custom memoization object which will cache the results of
  8975. complex objects for a speed boost. By passing `false` you can disable memoization, but this will cause circular
  8976. references to blow the stack.
  8977. * @return {Boolean} equal match
  8978. */
  8979. function extensiveDeepEqual(leftHandOperand, rightHandOperand, options) {
  8980. options = options || {};
  8981. options.memoize = options.memoize === false ? false : options.memoize || new MemoizeMap();
  8982. var comparator = options && options.comparator;
  8983. // Check if a memoized result exists.
  8984. var memoizeResultLeft = memoizeCompare(leftHandOperand, rightHandOperand, options.memoize);
  8985. if (memoizeResultLeft !== null) {
  8986. return memoizeResultLeft;
  8987. }
  8988. var memoizeResultRight = memoizeCompare(rightHandOperand, leftHandOperand, options.memoize);
  8989. if (memoizeResultRight !== null) {
  8990. return memoizeResultRight;
  8991. }
  8992. // If a comparator is present, use it.
  8993. if (comparator) {
  8994. var comparatorResult = comparator(leftHandOperand, rightHandOperand);
  8995. // Comparators may return null, in which case we want to go back to default behavior.
  8996. if (comparatorResult === false || comparatorResult === true) {
  8997. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, comparatorResult);
  8998. return comparatorResult;
  8999. }
  9000. // To allow comparators to override *any* behavior, we ran them first. Since it didn't decide
  9001. // what to do, we need to make sure to return the basic tests first before we move on.
  9002. var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
  9003. if (simpleResult !== null) {
  9004. // Don't memoize this, it takes longer to set/retrieve than to just compare.
  9005. return simpleResult;
  9006. }
  9007. }
  9008. var leftHandType = type(leftHandOperand);
  9009. if (leftHandType !== type(rightHandOperand)) {
  9010. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, false);
  9011. return false;
  9012. }
  9013. // Temporarily set the operands in the memoize object to prevent blowing the stack
  9014. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, true);
  9015. var result = extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options);
  9016. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, result);
  9017. return result;
  9018. }
  9019. function extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options) {
  9020. switch (leftHandType) {
  9021. case 'String':
  9022. case 'Number':
  9023. case 'Boolean':
  9024. case 'Date':
  9025. // If these types are their instance types (e.g. `new Number`) then re-deepEqual against their values
  9026. return deepEqual(leftHandOperand.valueOf(), rightHandOperand.valueOf());
  9027. case 'Promise':
  9028. case 'Symbol':
  9029. case 'function':
  9030. case 'WeakMap':
  9031. case 'WeakSet':
  9032. case 'Error':
  9033. return leftHandOperand === rightHandOperand;
  9034. case 'Arguments':
  9035. case 'Int8Array':
  9036. case 'Uint8Array':
  9037. case 'Uint8ClampedArray':
  9038. case 'Int16Array':
  9039. case 'Uint16Array':
  9040. case 'Int32Array':
  9041. case 'Uint32Array':
  9042. case 'Float32Array':
  9043. case 'Float64Array':
  9044. case 'Array':
  9045. return iterableEqual(leftHandOperand, rightHandOperand, options);
  9046. case 'RegExp':
  9047. return regexpEqual(leftHandOperand, rightHandOperand);
  9048. case 'Generator':
  9049. return generatorEqual(leftHandOperand, rightHandOperand, options);
  9050. case 'DataView':
  9051. return iterableEqual(new Uint8Array(leftHandOperand.buffer), new Uint8Array(rightHandOperand.buffer), options);
  9052. case 'ArrayBuffer':
  9053. return iterableEqual(new Uint8Array(leftHandOperand), new Uint8Array(rightHandOperand), options);
  9054. case 'Set':
  9055. return entriesEqual(leftHandOperand, rightHandOperand, options);
  9056. case 'Map':
  9057. return entriesEqual(leftHandOperand, rightHandOperand, options);
  9058. default:
  9059. return objectEqual(leftHandOperand, rightHandOperand, options);
  9060. }
  9061. }
  9062. /*!
  9063. * Compare two Regular Expressions for equality.
  9064. *
  9065. * @param {RegExp} leftHandOperand
  9066. * @param {RegExp} rightHandOperand
  9067. * @return {Boolean} result
  9068. */
  9069. function regexpEqual(leftHandOperand, rightHandOperand) {
  9070. return leftHandOperand.toString() === rightHandOperand.toString();
  9071. }
  9072. /*!
  9073. * Compare two Sets/Maps for equality. Faster than other equality functions.
  9074. *
  9075. * @param {Set} leftHandOperand
  9076. * @param {Set} rightHandOperand
  9077. * @param {Object} [options] (Optional)
  9078. * @return {Boolean} result
  9079. */
  9080. function entriesEqual(leftHandOperand, rightHandOperand, options) {
  9081. // IE11 doesn't support Set#entries or Set#@@iterator, so we need manually populate using Set#forEach
  9082. if (leftHandOperand.size !== rightHandOperand.size) {
  9083. return false;
  9084. }
  9085. if (leftHandOperand.size === 0) {
  9086. return true;
  9087. }
  9088. var leftHandItems = [];
  9089. var rightHandItems = [];
  9090. leftHandOperand.forEach(function gatherEntries(key, value) {
  9091. leftHandItems.push([ key, value ]);
  9092. });
  9093. rightHandOperand.forEach(function gatherEntries(key, value) {
  9094. rightHandItems.push([ key, value ]);
  9095. });
  9096. return iterableEqual(leftHandItems.sort(), rightHandItems.sort(), options);
  9097. }
  9098. /*!
  9099. * Simple equality for flat iterable objects such as Arrays, TypedArrays or Node.js buffers.
  9100. *
  9101. * @param {Iterable} leftHandOperand
  9102. * @param {Iterable} rightHandOperand
  9103. * @param {Object} [options] (Optional)
  9104. * @return {Boolean} result
  9105. */
  9106. function iterableEqual(leftHandOperand, rightHandOperand, options) {
  9107. var length = leftHandOperand.length;
  9108. if (length !== rightHandOperand.length) {
  9109. return false;
  9110. }
  9111. if (length === 0) {
  9112. return true;
  9113. }
  9114. var index = -1;
  9115. while (++index < length) {
  9116. if (deepEqual(leftHandOperand[index], rightHandOperand[index], options) === false) {
  9117. return false;
  9118. }
  9119. }
  9120. return true;
  9121. }
  9122. /*!
  9123. * Simple equality for generator objects such as those returned by generator functions.
  9124. *
  9125. * @param {Iterable} leftHandOperand
  9126. * @param {Iterable} rightHandOperand
  9127. * @param {Object} [options] (Optional)
  9128. * @return {Boolean} result
  9129. */
  9130. function generatorEqual(leftHandOperand, rightHandOperand, options) {
  9131. return iterableEqual(getGeneratorEntries(leftHandOperand), getGeneratorEntries(rightHandOperand), options);
  9132. }
  9133. /*!
  9134. * Determine if the given object has an @@iterator function.
  9135. *
  9136. * @param {Object} target
  9137. * @return {Boolean} `true` if the object has an @@iterator function.
  9138. */
  9139. function hasIteratorFunction(target) {
  9140. return typeof Symbol !== 'undefined' &&
  9141. typeof target === 'object' &&
  9142. typeof Symbol.iterator !== 'undefined' &&
  9143. typeof target[Symbol.iterator] === 'function';
  9144. }
  9145. /*!
  9146. * Gets all iterator entries from the given Object. If the Object has no @@iterator function, returns an empty array.
  9147. * This will consume the iterator - which could have side effects depending on the @@iterator implementation.
  9148. *
  9149. * @param {Object} target
  9150. * @returns {Array} an array of entries from the @@iterator function
  9151. */
  9152. function getIteratorEntries(target) {
  9153. if (hasIteratorFunction(target)) {
  9154. try {
  9155. return getGeneratorEntries(target[Symbol.iterator]());
  9156. } catch (iteratorError) {
  9157. return [];
  9158. }
  9159. }
  9160. return [];
  9161. }
  9162. /*!
  9163. * Gets all entries from a Generator. This will consume the generator - which could have side effects.
  9164. *
  9165. * @param {Generator} target
  9166. * @returns {Array} an array of entries from the Generator.
  9167. */
  9168. function getGeneratorEntries(generator) {
  9169. var generatorResult = generator.next();
  9170. var accumulator = [ generatorResult.value ];
  9171. while (generatorResult.done === false) {
  9172. generatorResult = generator.next();
  9173. accumulator.push(generatorResult.value);
  9174. }
  9175. return accumulator;
  9176. }
  9177. /*!
  9178. * Gets all own and inherited enumerable keys from a target.
  9179. *
  9180. * @param {Object} target
  9181. * @returns {Array} an array of own and inherited enumerable keys from the target.
  9182. */
  9183. function getEnumerableKeys(target) {
  9184. var keys = [];
  9185. for (var key in target) {
  9186. keys.push(key);
  9187. }
  9188. return keys;
  9189. }
  9190. /*!
  9191. * Determines if two objects have matching values, given a set of keys. Defers to deepEqual for the equality check of
  9192. * each key. If any value of the given key is not equal, the function will return false (early).
  9193. *
  9194. * @param {Mixed} leftHandOperand
  9195. * @param {Mixed} rightHandOperand
  9196. * @param {Array} keys An array of keys to compare the values of leftHandOperand and rightHandOperand against
  9197. * @param {Object} [options] (Optional)
  9198. * @return {Boolean} result
  9199. */
  9200. function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
  9201. var length = keys.length;
  9202. if (length === 0) {
  9203. return true;
  9204. }
  9205. for (var i = 0; i < length; i += 1) {
  9206. if (deepEqual(leftHandOperand[keys[i]], rightHandOperand[keys[i]], options) === false) {
  9207. return false;
  9208. }
  9209. }
  9210. return true;
  9211. }
  9212. /*!
  9213. * Recursively check the equality of two Objects. Once basic sameness has been established it will defer to `deepEqual`
  9214. * for each enumerable key in the object.
  9215. *
  9216. * @param {Mixed} leftHandOperand
  9217. * @param {Mixed} rightHandOperand
  9218. * @param {Object} [options] (Optional)
  9219. * @return {Boolean} result
  9220. */
  9221. function objectEqual(leftHandOperand, rightHandOperand, options) {
  9222. var leftHandKeys = getEnumerableKeys(leftHandOperand);
  9223. var rightHandKeys = getEnumerableKeys(rightHandOperand);
  9224. if (leftHandKeys.length && leftHandKeys.length === rightHandKeys.length) {
  9225. leftHandKeys.sort();
  9226. rightHandKeys.sort();
  9227. if (iterableEqual(leftHandKeys, rightHandKeys) === false) {
  9228. return false;
  9229. }
  9230. return keysEqual(leftHandOperand, rightHandOperand, leftHandKeys, options);
  9231. }
  9232. var leftHandEntries = getIteratorEntries(leftHandOperand);
  9233. var rightHandEntries = getIteratorEntries(rightHandOperand);
  9234. if (leftHandEntries.length && leftHandEntries.length === rightHandEntries.length) {
  9235. leftHandEntries.sort();
  9236. rightHandEntries.sort();
  9237. return iterableEqual(leftHandEntries, rightHandEntries, options);
  9238. }
  9239. if (leftHandKeys.length === 0 &&
  9240. leftHandEntries.length === 0 &&
  9241. rightHandKeys.length === 0 &&
  9242. rightHandEntries.length === 0) {
  9243. return true;
  9244. }
  9245. return false;
  9246. }
  9247. /*!
  9248. * Returns true if the argument is a primitive.
  9249. *
  9250. * This intentionally returns true for all objects that can be compared by reference,
  9251. * including functions and symbols.
  9252. *
  9253. * @param {Mixed} value
  9254. * @return {Boolean} result
  9255. */
  9256. function isPrimitive(value) {
  9257. return value === null || typeof value !== 'object';
  9258. }
  9259. },{"type-detect":39}],37:[function(require,module,exports){
  9260. 'use strict';
  9261. /* !
  9262. * Chai - getFuncName utility
  9263. * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
  9264. * MIT Licensed
  9265. */
  9266. /**
  9267. * ### .getFuncName(constructorFn)
  9268. *
  9269. * Returns the name of a function.
  9270. * When a non-function instance is passed, returns `null`.
  9271. * This also includes a polyfill function if `aFunc.name` is not defined.
  9272. *
  9273. * @name getFuncName
  9274. * @param {Function} funct
  9275. * @namespace Utils
  9276. * @api public
  9277. */
  9278. var toString = Function.prototype.toString;
  9279. var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
  9280. function getFuncName(aFunc) {
  9281. if (typeof aFunc !== 'function') {
  9282. return null;
  9283. }
  9284. var name = '';
  9285. if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
  9286. // Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
  9287. var match = toString.call(aFunc).match(functionNameMatch);
  9288. if (match) {
  9289. name = match[1];
  9290. }
  9291. } else {
  9292. // If we've got a `name` property we just use it
  9293. name = aFunc.name;
  9294. }
  9295. return name;
  9296. }
  9297. module.exports = getFuncName;
  9298. },{}],38:[function(require,module,exports){
  9299. 'use strict';
  9300. /* !
  9301. * Chai - pathval utility
  9302. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9303. * @see https://github.com/logicalparadox/filtr
  9304. * MIT Licensed
  9305. */
  9306. /**
  9307. * ### .hasProperty(object, name)
  9308. *
  9309. * This allows checking whether an object has own
  9310. * or inherited from prototype chain named property.
  9311. *
  9312. * Basically does the same thing as the `in`
  9313. * operator but works properly with null/undefined values
  9314. * and other primitives.
  9315. *
  9316. * var obj = {
  9317. * arr: ['a', 'b', 'c']
  9318. * , str: 'Hello'
  9319. * }
  9320. *
  9321. * The following would be the results.
  9322. *
  9323. * hasProperty(obj, 'str'); // true
  9324. * hasProperty(obj, 'constructor'); // true
  9325. * hasProperty(obj, 'bar'); // false
  9326. *
  9327. * hasProperty(obj.str, 'length'); // true
  9328. * hasProperty(obj.str, 1); // true
  9329. * hasProperty(obj.str, 5); // false
  9330. *
  9331. * hasProperty(obj.arr, 'length'); // true
  9332. * hasProperty(obj.arr, 2); // true
  9333. * hasProperty(obj.arr, 3); // false
  9334. *
  9335. * @param {Object} object
  9336. * @param {String|Symbol} name
  9337. * @returns {Boolean} whether it exists
  9338. * @namespace Utils
  9339. * @name hasProperty
  9340. * @api public
  9341. */
  9342. function hasProperty(obj, name) {
  9343. if (typeof obj === 'undefined' || obj === null) {
  9344. return false;
  9345. }
  9346. // The `in` operator does not work with primitives.
  9347. return name in Object(obj);
  9348. }
  9349. /* !
  9350. * ## parsePath(path)
  9351. *
  9352. * Helper function used to parse string object
  9353. * paths. Use in conjunction with `internalGetPathValue`.
  9354. *
  9355. * var parsed = parsePath('myobject.property.subprop');
  9356. *
  9357. * ### Paths:
  9358. *
  9359. * * Can be infinitely deep and nested.
  9360. * * Arrays are also valid using the formal `myobject.document[3].property`.
  9361. * * Literal dots and brackets (not delimiter) must be backslash-escaped.
  9362. *
  9363. * @param {String} path
  9364. * @returns {Object} parsed
  9365. * @api private
  9366. */
  9367. function parsePath(path) {
  9368. var str = path.replace(/([^\\])\[/g, '$1.[');
  9369. var parts = str.match(/(\\\.|[^.]+?)+/g);
  9370. return parts.map(function mapMatches(value) {
  9371. if (
  9372. value === 'constructor' ||
  9373. value === '__proto__' ||
  9374. value === 'prototype'
  9375. ) {
  9376. return {};
  9377. }
  9378. var regexp = /^\[(\d+)\]$/;
  9379. var mArr = regexp.exec(value);
  9380. var parsed = null;
  9381. if (mArr) {
  9382. parsed = { i: parseFloat(mArr[1]) };
  9383. } else {
  9384. parsed = { p: value.replace(/\\([.[\]])/g, '$1') };
  9385. }
  9386. return parsed;
  9387. });
  9388. }
  9389. /* !
  9390. * ## internalGetPathValue(obj, parsed[, pathDepth])
  9391. *
  9392. * Helper companion function for `.parsePath` that returns
  9393. * the value located at the parsed address.
  9394. *
  9395. * var value = getPathValue(obj, parsed);
  9396. *
  9397. * @param {Object} object to search against
  9398. * @param {Object} parsed definition from `parsePath`.
  9399. * @param {Number} depth (nesting level) of the property we want to retrieve
  9400. * @returns {Object|Undefined} value
  9401. * @api private
  9402. */
  9403. function internalGetPathValue(obj, parsed, pathDepth) {
  9404. var temporaryValue = obj;
  9405. var res = null;
  9406. pathDepth = typeof pathDepth === 'undefined' ? parsed.length : pathDepth;
  9407. for (var i = 0; i < pathDepth; i++) {
  9408. var part = parsed[i];
  9409. if (temporaryValue) {
  9410. if (typeof part.p === 'undefined') {
  9411. temporaryValue = temporaryValue[part.i];
  9412. } else {
  9413. temporaryValue = temporaryValue[part.p];
  9414. }
  9415. if (i === pathDepth - 1) {
  9416. res = temporaryValue;
  9417. }
  9418. }
  9419. }
  9420. return res;
  9421. }
  9422. /* !
  9423. * ## internalSetPathValue(obj, value, parsed)
  9424. *
  9425. * Companion function for `parsePath` that sets
  9426. * the value located at a parsed address.
  9427. *
  9428. * internalSetPathValue(obj, 'value', parsed);
  9429. *
  9430. * @param {Object} object to search and define on
  9431. * @param {*} value to use upon set
  9432. * @param {Object} parsed definition from `parsePath`
  9433. * @api private
  9434. */
  9435. function internalSetPathValue(obj, val, parsed) {
  9436. var tempObj = obj;
  9437. var pathDepth = parsed.length;
  9438. var part = null;
  9439. // Here we iterate through every part of the path
  9440. for (var i = 0; i < pathDepth; i++) {
  9441. var propName = null;
  9442. var propVal = null;
  9443. part = parsed[i];
  9444. // If it's the last part of the path, we set the 'propName' value with the property name
  9445. if (i === pathDepth - 1) {
  9446. propName = typeof part.p === 'undefined' ? part.i : part.p;
  9447. // Now we set the property with the name held by 'propName' on object with the desired val
  9448. tempObj[propName] = val;
  9449. } else if (typeof part.p !== 'undefined' && tempObj[part.p]) {
  9450. tempObj = tempObj[part.p];
  9451. } else if (typeof part.i !== 'undefined' && tempObj[part.i]) {
  9452. tempObj = tempObj[part.i];
  9453. } else {
  9454. // If the obj doesn't have the property we create one with that name to define it
  9455. var next = parsed[i + 1];
  9456. // Here we set the name of the property which will be defined
  9457. propName = typeof part.p === 'undefined' ? part.i : part.p;
  9458. // Here we decide if this property will be an array or a new object
  9459. propVal = typeof next.p === 'undefined' ? [] : {};
  9460. tempObj[propName] = propVal;
  9461. tempObj = tempObj[propName];
  9462. }
  9463. }
  9464. }
  9465. /**
  9466. * ### .getPathInfo(object, path)
  9467. *
  9468. * This allows the retrieval of property info in an
  9469. * object given a string path.
  9470. *
  9471. * The path info consists of an object with the
  9472. * following properties:
  9473. *
  9474. * * parent - The parent object of the property referenced by `path`
  9475. * * name - The name of the final property, a number if it was an array indexer
  9476. * * value - The value of the property, if it exists, otherwise `undefined`
  9477. * * exists - Whether the property exists or not
  9478. *
  9479. * @param {Object} object
  9480. * @param {String} path
  9481. * @returns {Object} info
  9482. * @namespace Utils
  9483. * @name getPathInfo
  9484. * @api public
  9485. */
  9486. function getPathInfo(obj, path) {
  9487. var parsed = parsePath(path);
  9488. var last = parsed[parsed.length - 1];
  9489. var info = {
  9490. parent:
  9491. parsed.length > 1 ?
  9492. internalGetPathValue(obj, parsed, parsed.length - 1) :
  9493. obj,
  9494. name: last.p || last.i,
  9495. value: internalGetPathValue(obj, parsed),
  9496. };
  9497. info.exists = hasProperty(info.parent, info.name);
  9498. return info;
  9499. }
  9500. /**
  9501. * ### .getPathValue(object, path)
  9502. *
  9503. * This allows the retrieval of values in an
  9504. * object given a string path.
  9505. *
  9506. * var obj = {
  9507. * prop1: {
  9508. * arr: ['a', 'b', 'c']
  9509. * , str: 'Hello'
  9510. * }
  9511. * , prop2: {
  9512. * arr: [ { nested: 'Universe' } ]
  9513. * , str: 'Hello again!'
  9514. * }
  9515. * }
  9516. *
  9517. * The following would be the results.
  9518. *
  9519. * getPathValue(obj, 'prop1.str'); // Hello
  9520. * getPathValue(obj, 'prop1.att[2]'); // b
  9521. * getPathValue(obj, 'prop2.arr[0].nested'); // Universe
  9522. *
  9523. * @param {Object} object
  9524. * @param {String} path
  9525. * @returns {Object} value or `undefined`
  9526. * @namespace Utils
  9527. * @name getPathValue
  9528. * @api public
  9529. */
  9530. function getPathValue(obj, path) {
  9531. var info = getPathInfo(obj, path);
  9532. return info.value;
  9533. }
  9534. /**
  9535. * ### .setPathValue(object, path, value)
  9536. *
  9537. * Define the value in an object at a given string path.
  9538. *
  9539. * ```js
  9540. * var obj = {
  9541. * prop1: {
  9542. * arr: ['a', 'b', 'c']
  9543. * , str: 'Hello'
  9544. * }
  9545. * , prop2: {
  9546. * arr: [ { nested: 'Universe' } ]
  9547. * , str: 'Hello again!'
  9548. * }
  9549. * };
  9550. * ```
  9551. *
  9552. * The following would be acceptable.
  9553. *
  9554. * ```js
  9555. * var properties = require('tea-properties');
  9556. * properties.set(obj, 'prop1.str', 'Hello Universe!');
  9557. * properties.set(obj, 'prop1.arr[2]', 'B');
  9558. * properties.set(obj, 'prop2.arr[0].nested.value', { hello: 'universe' });
  9559. * ```
  9560. *
  9561. * @param {Object} object
  9562. * @param {String} path
  9563. * @param {Mixed} value
  9564. * @api private
  9565. */
  9566. function setPathValue(obj, path, val) {
  9567. var parsed = parsePath(path);
  9568. internalSetPathValue(obj, val, parsed);
  9569. return obj;
  9570. }
  9571. module.exports = {
  9572. hasProperty: hasProperty,
  9573. getPathInfo: getPathInfo,
  9574. getPathValue: getPathValue,
  9575. setPathValue: setPathValue,
  9576. };
  9577. },{}],39:[function(require,module,exports){
  9578. (function (global, factory) {
  9579. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  9580. typeof define === 'function' && define.amd ? define(factory) :
  9581. (global.typeDetect = factory());
  9582. }(this, (function () { 'use strict';
  9583. /* !
  9584. * type-detect
  9585. * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
  9586. * MIT Licensed
  9587. */
  9588. var promiseExists = typeof Promise === 'function';
  9589. /* eslint-disable no-undef */
  9590. var globalObject = typeof self === 'object' ? self : global; // eslint-disable-line id-blacklist
  9591. var symbolExists = typeof Symbol !== 'undefined';
  9592. var mapExists = typeof Map !== 'undefined';
  9593. var setExists = typeof Set !== 'undefined';
  9594. var weakMapExists = typeof WeakMap !== 'undefined';
  9595. var weakSetExists = typeof WeakSet !== 'undefined';
  9596. var dataViewExists = typeof DataView !== 'undefined';
  9597. var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
  9598. var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
  9599. var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
  9600. var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
  9601. var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
  9602. var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
  9603. var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
  9604. var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
  9605. var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
  9606. var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
  9607. var toStringLeftSliceLength = 8;
  9608. var toStringRightSliceLength = -1;
  9609. /**
  9610. * ### typeOf (obj)
  9611. *
  9612. * Uses `Object.prototype.toString` to determine the type of an object,
  9613. * normalising behaviour across engine versions & well optimised.
  9614. *
  9615. * @param {Mixed} object
  9616. * @return {String} object type
  9617. * @api public
  9618. */
  9619. function typeDetect(obj) {
  9620. /* ! Speed optimisation
  9621. * Pre:
  9622. * string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
  9623. * boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
  9624. * number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
  9625. * undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
  9626. * function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
  9627. * Post:
  9628. * string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
  9629. * boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
  9630. * number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
  9631. * undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
  9632. * function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
  9633. */
  9634. var typeofObj = typeof obj;
  9635. if (typeofObj !== 'object') {
  9636. return typeofObj;
  9637. }
  9638. /* ! Speed optimisation
  9639. * Pre:
  9640. * null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
  9641. * Post:
  9642. * null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
  9643. */
  9644. if (obj === null) {
  9645. return 'null';
  9646. }
  9647. /* ! Spec Conformance
  9648. * Test: `Object.prototype.toString.call(window)``
  9649. * - Node === "[object global]"
  9650. * - Chrome === "[object global]"
  9651. * - Firefox === "[object Window]"
  9652. * - PhantomJS === "[object Window]"
  9653. * - Safari === "[object Window]"
  9654. * - IE 11 === "[object Window]"
  9655. * - IE Edge === "[object Window]"
  9656. * Test: `Object.prototype.toString.call(this)``
  9657. * - Chrome Worker === "[object global]"
  9658. * - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
  9659. * - Safari Worker === "[object DedicatedWorkerGlobalScope]"
  9660. * - IE 11 Worker === "[object WorkerGlobalScope]"
  9661. * - IE Edge Worker === "[object WorkerGlobalScope]"
  9662. */
  9663. if (obj === globalObject) {
  9664. return 'global';
  9665. }
  9666. /* ! Speed optimisation
  9667. * Pre:
  9668. * array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
  9669. * Post:
  9670. * array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
  9671. */
  9672. if (
  9673. Array.isArray(obj) &&
  9674. (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
  9675. ) {
  9676. return 'Array';
  9677. }
  9678. // Not caching existence of `window` and related properties due to potential
  9679. // for `window` to be unset before tests in quasi-browser environments.
  9680. if (typeof window === 'object' && window !== null) {
  9681. /* ! Spec Conformance
  9682. * (https://html.spec.whatwg.org/multipage/browsers.html#location)
  9683. * WhatWG HTML$7.7.3 - The `Location` interface
  9684. * Test: `Object.prototype.toString.call(window.location)``
  9685. * - IE <=11 === "[object Object]"
  9686. * - IE Edge <=13 === "[object Object]"
  9687. */
  9688. if (typeof window.location === 'object' && obj === window.location) {
  9689. return 'Location';
  9690. }
  9691. /* ! Spec Conformance
  9692. * (https://html.spec.whatwg.org/#document)
  9693. * WhatWG HTML$3.1.1 - The `Document` object
  9694. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  9695. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
  9696. * which suggests that browsers should use HTMLTableCellElement for
  9697. * both TD and TH elements. WhatWG separates these.
  9698. * WhatWG HTML states:
  9699. * > For historical reasons, Window objects must also have a
  9700. * > writable, configurable, non-enumerable property named
  9701. * > HTMLDocument whose value is the Document interface object.
  9702. * Test: `Object.prototype.toString.call(document)``
  9703. * - Chrome === "[object HTMLDocument]"
  9704. * - Firefox === "[object HTMLDocument]"
  9705. * - Safari === "[object HTMLDocument]"
  9706. * - IE <=10 === "[object Document]"
  9707. * - IE 11 === "[object HTMLDocument]"
  9708. * - IE Edge <=13 === "[object HTMLDocument]"
  9709. */
  9710. if (typeof window.document === 'object' && obj === window.document) {
  9711. return 'Document';
  9712. }
  9713. if (typeof window.navigator === 'object') {
  9714. /* ! Spec Conformance
  9715. * (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
  9716. * WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
  9717. * Test: `Object.prototype.toString.call(navigator.mimeTypes)``
  9718. * - IE <=10 === "[object MSMimeTypesCollection]"
  9719. */
  9720. if (typeof window.navigator.mimeTypes === 'object' &&
  9721. obj === window.navigator.mimeTypes) {
  9722. return 'MimeTypeArray';
  9723. }
  9724. /* ! Spec Conformance
  9725. * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
  9726. * WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
  9727. * Test: `Object.prototype.toString.call(navigator.plugins)``
  9728. * - IE <=10 === "[object MSPluginsCollection]"
  9729. */
  9730. if (typeof window.navigator.plugins === 'object' &&
  9731. obj === window.navigator.plugins) {
  9732. return 'PluginArray';
  9733. }
  9734. }
  9735. if ((typeof window.HTMLElement === 'function' ||
  9736. typeof window.HTMLElement === 'object') &&
  9737. obj instanceof window.HTMLElement) {
  9738. /* ! Spec Conformance
  9739. * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
  9740. * WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
  9741. * Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
  9742. * - IE <=10 === "[object HTMLBlockElement]"
  9743. */
  9744. if (obj.tagName === 'BLOCKQUOTE') {
  9745. return 'HTMLQuoteElement';
  9746. }
  9747. /* ! Spec Conformance
  9748. * (https://html.spec.whatwg.org/#htmltabledatacellelement)
  9749. * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
  9750. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  9751. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
  9752. * which suggests that browsers should use HTMLTableCellElement for
  9753. * both TD and TH elements. WhatWG separates these.
  9754. * Test: Object.prototype.toString.call(document.createElement('td'))
  9755. * - Chrome === "[object HTMLTableCellElement]"
  9756. * - Firefox === "[object HTMLTableCellElement]"
  9757. * - Safari === "[object HTMLTableCellElement]"
  9758. */
  9759. if (obj.tagName === 'TD') {
  9760. return 'HTMLTableDataCellElement';
  9761. }
  9762. /* ! Spec Conformance
  9763. * (https://html.spec.whatwg.org/#htmltableheadercellelement)
  9764. * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
  9765. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  9766. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
  9767. * which suggests that browsers should use HTMLTableCellElement for
  9768. * both TD and TH elements. WhatWG separates these.
  9769. * Test: Object.prototype.toString.call(document.createElement('th'))
  9770. * - Chrome === "[object HTMLTableCellElement]"
  9771. * - Firefox === "[object HTMLTableCellElement]"
  9772. * - Safari === "[object HTMLTableCellElement]"
  9773. */
  9774. if (obj.tagName === 'TH') {
  9775. return 'HTMLTableHeaderCellElement';
  9776. }
  9777. }
  9778. }
  9779. /* ! Speed optimisation
  9780. * Pre:
  9781. * Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
  9782. * Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
  9783. * Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
  9784. * Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
  9785. * Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
  9786. * Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
  9787. * Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
  9788. * Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
  9789. * Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
  9790. * Post:
  9791. * Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
  9792. * Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
  9793. * Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
  9794. * Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
  9795. * Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
  9796. * Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
  9797. * Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
  9798. * Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
  9799. * Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
  9800. */
  9801. var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
  9802. if (typeof stringTag === 'string') {
  9803. return stringTag;
  9804. }
  9805. var objPrototype = Object.getPrototypeOf(obj);
  9806. /* ! Speed optimisation
  9807. * Pre:
  9808. * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
  9809. * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
  9810. * Post:
  9811. * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
  9812. * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
  9813. */
  9814. if (objPrototype === RegExp.prototype) {
  9815. return 'RegExp';
  9816. }
  9817. /* ! Speed optimisation
  9818. * Pre:
  9819. * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
  9820. * Post:
  9821. * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
  9822. */
  9823. if (objPrototype === Date.prototype) {
  9824. return 'Date';
  9825. }
  9826. /* ! Spec Conformance
  9827. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
  9828. * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
  9829. * Test: `Object.prototype.toString.call(Promise.resolve())``
  9830. * - Chrome <=47 === "[object Object]"
  9831. * - Edge <=20 === "[object Object]"
  9832. * - Firefox 29-Latest === "[object Promise]"
  9833. * - Safari 7.1-Latest === "[object Promise]"
  9834. */
  9835. if (promiseExists && objPrototype === Promise.prototype) {
  9836. return 'Promise';
  9837. }
  9838. /* ! Speed optimisation
  9839. * Pre:
  9840. * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
  9841. * Post:
  9842. * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
  9843. */
  9844. if (setExists && objPrototype === Set.prototype) {
  9845. return 'Set';
  9846. }
  9847. /* ! Speed optimisation
  9848. * Pre:
  9849. * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
  9850. * Post:
  9851. * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
  9852. */
  9853. if (mapExists && objPrototype === Map.prototype) {
  9854. return 'Map';
  9855. }
  9856. /* ! Speed optimisation
  9857. * Pre:
  9858. * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
  9859. * Post:
  9860. * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
  9861. */
  9862. if (weakSetExists && objPrototype === WeakSet.prototype) {
  9863. return 'WeakSet';
  9864. }
  9865. /* ! Speed optimisation
  9866. * Pre:
  9867. * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
  9868. * Post:
  9869. * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
  9870. */
  9871. if (weakMapExists && objPrototype === WeakMap.prototype) {
  9872. return 'WeakMap';
  9873. }
  9874. /* ! Spec Conformance
  9875. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
  9876. * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
  9877. * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
  9878. * - Edge <=13 === "[object Object]"
  9879. */
  9880. if (dataViewExists && objPrototype === DataView.prototype) {
  9881. return 'DataView';
  9882. }
  9883. /* ! Spec Conformance
  9884. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
  9885. * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
  9886. * Test: `Object.prototype.toString.call(new Map().entries())``
  9887. * - Edge <=13 === "[object Object]"
  9888. */
  9889. if (mapExists && objPrototype === mapIteratorPrototype) {
  9890. return 'Map Iterator';
  9891. }
  9892. /* ! Spec Conformance
  9893. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
  9894. * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
  9895. * Test: `Object.prototype.toString.call(new Set().entries())``
  9896. * - Edge <=13 === "[object Object]"
  9897. */
  9898. if (setExists && objPrototype === setIteratorPrototype) {
  9899. return 'Set Iterator';
  9900. }
  9901. /* ! Spec Conformance
  9902. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
  9903. * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
  9904. * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
  9905. * - Edge <=13 === "[object Object]"
  9906. */
  9907. if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
  9908. return 'Array Iterator';
  9909. }
  9910. /* ! Spec Conformance
  9911. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
  9912. * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
  9913. * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
  9914. * - Edge <=13 === "[object Object]"
  9915. */
  9916. if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
  9917. return 'String Iterator';
  9918. }
  9919. /* ! Speed optimisation
  9920. * Pre:
  9921. * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
  9922. * Post:
  9923. * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
  9924. */
  9925. if (objPrototype === null) {
  9926. return 'Object';
  9927. }
  9928. return Object
  9929. .prototype
  9930. .toString
  9931. .call(obj)
  9932. .slice(toStringLeftSliceLength, toStringRightSliceLength);
  9933. }
  9934. return typeDetect;
  9935. })));
  9936. },{}]},{},[1])(1)
  9937. });