chai.js 361 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549
  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.8';
  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":22,"assertion-error":33}],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. * - `eql`: This flag contains the deepEqual function to be used by the assertion.
  122. *
  123. * @param {Mixed} obj target of the assertion
  124. * @param {String} msg (optional) custom error message
  125. * @param {Function} ssfi (optional) starting point for removing stack frames
  126. * @param {Boolean} lockSsfi (optional) whether or not the ssfi flag is locked
  127. * @api private
  128. */
  129. function Assertion (obj, msg, ssfi, lockSsfi) {
  130. flag(this, 'ssfi', ssfi || Assertion);
  131. flag(this, 'lockSsfi', lockSsfi);
  132. flag(this, 'object', obj);
  133. flag(this, 'message', msg);
  134. flag(this, 'eql', config.deepEqual || util.eql);
  135. return util.proxify(this);
  136. }
  137. Object.defineProperty(Assertion, 'includeStack', {
  138. get: function() {
  139. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  140. return config.includeStack;
  141. },
  142. set: function(value) {
  143. console.warn('Assertion.includeStack is deprecated, use chai.config.includeStack instead.');
  144. config.includeStack = value;
  145. }
  146. });
  147. Object.defineProperty(Assertion, 'showDiff', {
  148. get: function() {
  149. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  150. return config.showDiff;
  151. },
  152. set: function(value) {
  153. console.warn('Assertion.showDiff is deprecated, use chai.config.showDiff instead.');
  154. config.showDiff = value;
  155. }
  156. });
  157. Assertion.addProperty = function (name, fn) {
  158. util.addProperty(this.prototype, name, fn);
  159. };
  160. Assertion.addMethod = function (name, fn) {
  161. util.addMethod(this.prototype, name, fn);
  162. };
  163. Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
  164. util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
  165. };
  166. Assertion.overwriteProperty = function (name, fn) {
  167. util.overwriteProperty(this.prototype, name, fn);
  168. };
  169. Assertion.overwriteMethod = function (name, fn) {
  170. util.overwriteMethod(this.prototype, name, fn);
  171. };
  172. Assertion.overwriteChainableMethod = function (name, fn, chainingBehavior) {
  173. util.overwriteChainableMethod(this.prototype, name, fn, chainingBehavior);
  174. };
  175. /**
  176. * ### .assert(expression, message, negateMessage, expected, actual, showDiff)
  177. *
  178. * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
  179. *
  180. * @name assert
  181. * @param {Philosophical} expression to be tested
  182. * @param {String|Function} message or function that returns message to display if expression fails
  183. * @param {String|Function} negatedMessage or function that returns negatedMessage to display if negated expression fails
  184. * @param {Mixed} expected value (remember to check for negation)
  185. * @param {Mixed} actual (optional) will default to `this.obj`
  186. * @param {Boolean} showDiff (optional) when set to `true`, assert will display a diff in addition to the message if expression fails
  187. * @api private
  188. */
  189. Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
  190. var ok = util.test(this, arguments);
  191. if (false !== showDiff) showDiff = true;
  192. if (undefined === expected && undefined === _actual) showDiff = false;
  193. if (true !== config.showDiff) showDiff = false;
  194. if (!ok) {
  195. msg = util.getMessage(this, arguments);
  196. var actual = util.getActual(this, arguments);
  197. var assertionErrorObjectProperties = {
  198. actual: actual
  199. , expected: expected
  200. , showDiff: showDiff
  201. };
  202. var operator = util.getOperator(this, arguments);
  203. if (operator) {
  204. assertionErrorObjectProperties.operator = operator;
  205. }
  206. throw new AssertionError(
  207. msg,
  208. assertionErrorObjectProperties,
  209. (config.includeStack) ? this.assert : flag(this, 'ssfi'));
  210. }
  211. };
  212. /*!
  213. * ### ._obj
  214. *
  215. * Quick reference to stored `actual` value for plugin developers.
  216. *
  217. * @api private
  218. */
  219. Object.defineProperty(Assertion.prototype, '_obj',
  220. { get: function () {
  221. return flag(this, 'object');
  222. }
  223. , set: function (val) {
  224. flag(this, 'object', val);
  225. }
  226. });
  227. };
  228. },{"./config":4}],4:[function(require,module,exports){
  229. module.exports = {
  230. /**
  231. * ### config.includeStack
  232. *
  233. * User configurable property, influences whether stack trace
  234. * is included in Assertion error message. Default of false
  235. * suppresses stack trace in the error message.
  236. *
  237. * chai.config.includeStack = true; // enable stack on error
  238. *
  239. * @param {Boolean}
  240. * @api public
  241. */
  242. includeStack: false,
  243. /**
  244. * ### config.showDiff
  245. *
  246. * User configurable property, influences whether or not
  247. * the `showDiff` flag should be included in the thrown
  248. * AssertionErrors. `false` will always be `false`; `true`
  249. * will be true when the assertion has requested a diff
  250. * be shown.
  251. *
  252. * @param {Boolean}
  253. * @api public
  254. */
  255. showDiff: true,
  256. /**
  257. * ### config.truncateThreshold
  258. *
  259. * User configurable property, sets length threshold for actual and
  260. * expected values in assertion errors. If this threshold is exceeded, for
  261. * example for large data structures, the value is replaced with something
  262. * like `[ Array(3) ]` or `{ Object (prop1, prop2) }`.
  263. *
  264. * Set it to zero if you want to disable truncating altogether.
  265. *
  266. * This is especially userful when doing assertions on arrays: having this
  267. * set to a reasonable large value makes the failure messages readily
  268. * inspectable.
  269. *
  270. * chai.config.truncateThreshold = 0; // disable truncating
  271. *
  272. * @param {Number}
  273. * @api public
  274. */
  275. truncateThreshold: 40,
  276. /**
  277. * ### config.useProxy
  278. *
  279. * User configurable property, defines if chai will use a Proxy to throw
  280. * an error when a non-existent property is read, which protects users
  281. * from typos when using property-based assertions.
  282. *
  283. * Set it to false if you want to disable this feature.
  284. *
  285. * chai.config.useProxy = false; // disable use of Proxy
  286. *
  287. * This feature is automatically disabled regardless of this config value
  288. * in environments that don't support proxies.
  289. *
  290. * @param {Boolean}
  291. * @api public
  292. */
  293. useProxy: true,
  294. /**
  295. * ### config.proxyExcludedKeys
  296. *
  297. * User configurable property, defines which properties should be ignored
  298. * instead of throwing an error if they do not exist on the assertion.
  299. * This is only applied if the environment Chai is running in supports proxies and
  300. * if the `useProxy` configuration setting is enabled.
  301. * By default, `then` and `inspect` will not throw an error if they do not exist on the
  302. * assertion object because the `.inspect` property is read by `util.inspect` (for example, when
  303. * using `console.log` on the assertion object) and `.then` is necessary for promise type-checking.
  304. *
  305. * // By default these keys will not throw an error if they do not exist on the assertion object
  306. * chai.config.proxyExcludedKeys = ['then', 'inspect'];
  307. *
  308. * @param {Array}
  309. * @api public
  310. */
  311. proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON'],
  312. /**
  313. * ### config.deepEqual
  314. *
  315. * User configurable property, defines which a custom function to use for deepEqual
  316. * comparisons.
  317. * By default, the function used is the one from the `deep-eql` package without custom comparator.
  318. *
  319. * // use a custom comparator
  320. * chai.config.deepEqual = (expected, actual) => {
  321. * return chai.util.eql(expected, actual, {
  322. * comparator: (expected, actual) => {
  323. * // for non number comparison, use the default behavior
  324. * if(typeof expected !== 'number') return null;
  325. * // allow a difference of 10 between compared numbers
  326. * return typeof actual === 'number' && Math.abs(actual - expected) < 10
  327. * }
  328. * })
  329. * };
  330. *
  331. * @param {Function}
  332. * @api public
  333. */
  334. deepEqual: null
  335. };
  336. },{}],5:[function(require,module,exports){
  337. /*!
  338. * chai
  339. * http://chaijs.com
  340. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  341. * MIT Licensed
  342. */
  343. module.exports = function (chai, _) {
  344. var Assertion = chai.Assertion
  345. , AssertionError = chai.AssertionError
  346. , flag = _.flag;
  347. /**
  348. * ### Language Chains
  349. *
  350. * The following are provided as chainable getters to improve the readability
  351. * of your assertions.
  352. *
  353. * **Chains**
  354. *
  355. * - to
  356. * - be
  357. * - been
  358. * - is
  359. * - that
  360. * - which
  361. * - and
  362. * - has
  363. * - have
  364. * - with
  365. * - at
  366. * - of
  367. * - same
  368. * - but
  369. * - does
  370. * - still
  371. * - also
  372. *
  373. * @name language chains
  374. * @namespace BDD
  375. * @api public
  376. */
  377. [ 'to', 'be', 'been', 'is'
  378. , 'and', 'has', 'have', 'with'
  379. , 'that', 'which', 'at', 'of'
  380. , 'same', 'but', 'does', 'still', "also" ].forEach(function (chain) {
  381. Assertion.addProperty(chain);
  382. });
  383. /**
  384. * ### .not
  385. *
  386. * Negates all assertions that follow in the chain.
  387. *
  388. * expect(function () {}).to.not.throw();
  389. * expect({a: 1}).to.not.have.property('b');
  390. * expect([1, 2]).to.be.an('array').that.does.not.include(3);
  391. *
  392. * Just because you can negate any assertion with `.not` doesn't mean you
  393. * should. With great power comes great responsibility. It's often best to
  394. * assert that the one expected output was produced, rather than asserting
  395. * that one of countless unexpected outputs wasn't produced. See individual
  396. * assertions for specific guidance.
  397. *
  398. * expect(2).to.equal(2); // Recommended
  399. * expect(2).to.not.equal(1); // Not recommended
  400. *
  401. * @name not
  402. * @namespace BDD
  403. * @api public
  404. */
  405. Assertion.addProperty('not', function () {
  406. flag(this, 'negate', true);
  407. });
  408. /**
  409. * ### .deep
  410. *
  411. * Causes all `.equal`, `.include`, `.members`, `.keys`, and `.property`
  412. * assertions that follow in the chain to use deep equality instead of strict
  413. * (`===`) equality. See the `deep-eql` project page for info on the deep
  414. * equality algorithm: https://github.com/chaijs/deep-eql.
  415. *
  416. * // Target object deeply (but not strictly) equals `{a: 1}`
  417. * expect({a: 1}).to.deep.equal({a: 1});
  418. * expect({a: 1}).to.not.equal({a: 1});
  419. *
  420. * // Target array deeply (but not strictly) includes `{a: 1}`
  421. * expect([{a: 1}]).to.deep.include({a: 1});
  422. * expect([{a: 1}]).to.not.include({a: 1});
  423. *
  424. * // Target object deeply (but not strictly) includes `x: {a: 1}`
  425. * expect({x: {a: 1}}).to.deep.include({x: {a: 1}});
  426. * expect({x: {a: 1}}).to.not.include({x: {a: 1}});
  427. *
  428. * // Target array deeply (but not strictly) has member `{a: 1}`
  429. * expect([{a: 1}]).to.have.deep.members([{a: 1}]);
  430. * expect([{a: 1}]).to.not.have.members([{a: 1}]);
  431. *
  432. * // Target set deeply (but not strictly) has key `{a: 1}`
  433. * expect(new Set([{a: 1}])).to.have.deep.keys([{a: 1}]);
  434. * expect(new Set([{a: 1}])).to.not.have.keys([{a: 1}]);
  435. *
  436. * // Target object deeply (but not strictly) has property `x: {a: 1}`
  437. * expect({x: {a: 1}}).to.have.deep.property('x', {a: 1});
  438. * expect({x: {a: 1}}).to.not.have.property('x', {a: 1});
  439. *
  440. * @name deep
  441. * @namespace BDD
  442. * @api public
  443. */
  444. Assertion.addProperty('deep', function () {
  445. flag(this, 'deep', true);
  446. });
  447. /**
  448. * ### .nested
  449. *
  450. * Enables dot- and bracket-notation in all `.property` and `.include`
  451. * assertions that follow in the chain.
  452. *
  453. * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]');
  454. * expect({a: {b: ['x', 'y']}}).to.nested.include({'a.b[1]': 'y'});
  455. *
  456. * If `.` or `[]` are part of an actual property name, they can be escaped by
  457. * adding two backslashes before them.
  458. *
  459. * expect({'.a': {'[b]': 'x'}}).to.have.nested.property('\\.a.\\[b\\]');
  460. * expect({'.a': {'[b]': 'x'}}).to.nested.include({'\\.a.\\[b\\]': 'x'});
  461. *
  462. * `.nested` cannot be combined with `.own`.
  463. *
  464. * @name nested
  465. * @namespace BDD
  466. * @api public
  467. */
  468. Assertion.addProperty('nested', function () {
  469. flag(this, 'nested', true);
  470. });
  471. /**
  472. * ### .own
  473. *
  474. * Causes all `.property` and `.include` assertions that follow in the chain
  475. * to ignore inherited properties.
  476. *
  477. * Object.prototype.b = 2;
  478. *
  479. * expect({a: 1}).to.have.own.property('a');
  480. * expect({a: 1}).to.have.property('b');
  481. * expect({a: 1}).to.not.have.own.property('b');
  482. *
  483. * expect({a: 1}).to.own.include({a: 1});
  484. * expect({a: 1}).to.include({b: 2}).but.not.own.include({b: 2});
  485. *
  486. * `.own` cannot be combined with `.nested`.
  487. *
  488. * @name own
  489. * @namespace BDD
  490. * @api public
  491. */
  492. Assertion.addProperty('own', function () {
  493. flag(this, 'own', true);
  494. });
  495. /**
  496. * ### .ordered
  497. *
  498. * Causes all `.members` assertions that follow in the chain to require that
  499. * members be in the same order.
  500. *
  501. * expect([1, 2]).to.have.ordered.members([1, 2])
  502. * .but.not.have.ordered.members([2, 1]);
  503. *
  504. * When `.include` and `.ordered` are combined, the ordering begins at the
  505. * start of both arrays.
  506. *
  507. * expect([1, 2, 3]).to.include.ordered.members([1, 2])
  508. * .but.not.include.ordered.members([2, 3]);
  509. *
  510. * @name ordered
  511. * @namespace BDD
  512. * @api public
  513. */
  514. Assertion.addProperty('ordered', function () {
  515. flag(this, 'ordered', true);
  516. });
  517. /**
  518. * ### .any
  519. *
  520. * Causes all `.keys` assertions that follow in the chain to only require that
  521. * the target have at least one of the given keys. This is the opposite of
  522. * `.all`, which requires that the target have all of the given keys.
  523. *
  524. * expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');
  525. *
  526. * See the `.keys` doc for guidance on when to use `.any` or `.all`.
  527. *
  528. * @name any
  529. * @namespace BDD
  530. * @api public
  531. */
  532. Assertion.addProperty('any', function () {
  533. flag(this, 'any', true);
  534. flag(this, 'all', false);
  535. });
  536. /**
  537. * ### .all
  538. *
  539. * Causes all `.keys` assertions that follow in the chain to require that the
  540. * target have all of the given keys. This is the opposite of `.any`, which
  541. * only requires that the target have at least one of the given keys.
  542. *
  543. * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
  544. *
  545. * Note that `.all` is used by default when neither `.all` nor `.any` are
  546. * added earlier in the chain. However, it's often best to add `.all` anyway
  547. * because it improves readability.
  548. *
  549. * See the `.keys` doc for guidance on when to use `.any` or `.all`.
  550. *
  551. * @name all
  552. * @namespace BDD
  553. * @api public
  554. */
  555. Assertion.addProperty('all', function () {
  556. flag(this, 'all', true);
  557. flag(this, 'any', false);
  558. });
  559. /**
  560. * ### .a(type[, msg])
  561. *
  562. * Asserts that the target's type is equal to the given string `type`. Types
  563. * are case insensitive. See the `type-detect` project page for info on the
  564. * type detection algorithm: https://github.com/chaijs/type-detect.
  565. *
  566. * expect('foo').to.be.a('string');
  567. * expect({a: 1}).to.be.an('object');
  568. * expect(null).to.be.a('null');
  569. * expect(undefined).to.be.an('undefined');
  570. * expect(new Error).to.be.an('error');
  571. * expect(Promise.resolve()).to.be.a('promise');
  572. * expect(new Float32Array).to.be.a('float32array');
  573. * expect(Symbol()).to.be.a('symbol');
  574. *
  575. * `.a` supports objects that have a custom type set via `Symbol.toStringTag`.
  576. *
  577. * var myObj = {
  578. * [Symbol.toStringTag]: 'myCustomType'
  579. * };
  580. *
  581. * expect(myObj).to.be.a('myCustomType').but.not.an('object');
  582. *
  583. * It's often best to use `.a` to check a target's type before making more
  584. * assertions on the same target. That way, you avoid unexpected behavior from
  585. * any assertion that does different things based on the target's type.
  586. *
  587. * expect([1, 2, 3]).to.be.an('array').that.includes(2);
  588. * expect([]).to.be.an('array').that.is.empty;
  589. *
  590. * Add `.not` earlier in the chain to negate `.a`. However, it's often best to
  591. * assert that the target is the expected type, rather than asserting that it
  592. * isn't one of many unexpected types.
  593. *
  594. * expect('foo').to.be.a('string'); // Recommended
  595. * expect('foo').to.not.be.an('array'); // Not recommended
  596. *
  597. * `.a` accepts an optional `msg` argument which is a custom error message to
  598. * show when the assertion fails. The message can also be given as the second
  599. * argument to `expect`.
  600. *
  601. * expect(1).to.be.a('string', 'nooo why fail??');
  602. * expect(1, 'nooo why fail??').to.be.a('string');
  603. *
  604. * `.a` can also be used as a language chain to improve the readability of
  605. * your assertions.
  606. *
  607. * expect({b: 2}).to.have.a.property('b');
  608. *
  609. * The alias `.an` can be used interchangeably with `.a`.
  610. *
  611. * @name a
  612. * @alias an
  613. * @param {String} type
  614. * @param {String} msg _optional_
  615. * @namespace BDD
  616. * @api public
  617. */
  618. function an (type, msg) {
  619. if (msg) flag(this, 'message', msg);
  620. type = type.toLowerCase();
  621. var obj = flag(this, 'object')
  622. , article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
  623. this.assert(
  624. type === _.type(obj).toLowerCase()
  625. , 'expected #{this} to be ' + article + type
  626. , 'expected #{this} not to be ' + article + type
  627. );
  628. }
  629. Assertion.addChainableMethod('an', an);
  630. Assertion.addChainableMethod('a', an);
  631. /**
  632. * ### .include(val[, msg])
  633. *
  634. * When the target is a string, `.include` asserts that the given string `val`
  635. * is a substring of the target.
  636. *
  637. * expect('foobar').to.include('foo');
  638. *
  639. * When the target is an array, `.include` asserts that the given `val` is a
  640. * member of the target.
  641. *
  642. * expect([1, 2, 3]).to.include(2);
  643. *
  644. * When the target is an object, `.include` asserts that the given object
  645. * `val`'s properties are a subset of the target's properties.
  646. *
  647. * expect({a: 1, b: 2, c: 3}).to.include({a: 1, b: 2});
  648. *
  649. * When the target is a Set or WeakSet, `.include` asserts that the given `val` is a
  650. * member of the target. SameValueZero equality algorithm is used.
  651. *
  652. * expect(new Set([1, 2])).to.include(2);
  653. *
  654. * When the target is a Map, `.include` asserts that the given `val` is one of
  655. * the values of the target. SameValueZero equality algorithm is used.
  656. *
  657. * expect(new Map([['a', 1], ['b', 2]])).to.include(2);
  658. *
  659. * Because `.include` does different things based on the target's type, it's
  660. * important to check the target's type before using `.include`. See the `.a`
  661. * doc for info on testing a target's type.
  662. *
  663. * expect([1, 2, 3]).to.be.an('array').that.includes(2);
  664. *
  665. * By default, strict (`===`) equality is used to compare array members and
  666. * object properties. Add `.deep` earlier in the chain to use deep equality
  667. * instead (WeakSet targets are not supported). See the `deep-eql` project
  668. * page for info on the deep equality algorithm: https://github.com/chaijs/deep-eql.
  669. *
  670. * // Target array deeply (but not strictly) includes `{a: 1}`
  671. * expect([{a: 1}]).to.deep.include({a: 1});
  672. * expect([{a: 1}]).to.not.include({a: 1});
  673. *
  674. * // Target object deeply (but not strictly) includes `x: {a: 1}`
  675. * expect({x: {a: 1}}).to.deep.include({x: {a: 1}});
  676. * expect({x: {a: 1}}).to.not.include({x: {a: 1}});
  677. *
  678. * By default, all of the target's properties are searched when working with
  679. * objects. This includes properties that are inherited and/or non-enumerable.
  680. * Add `.own` earlier in the chain to exclude the target's inherited
  681. * properties from the search.
  682. *
  683. * Object.prototype.b = 2;
  684. *
  685. * expect({a: 1}).to.own.include({a: 1});
  686. * expect({a: 1}).to.include({b: 2}).but.not.own.include({b: 2});
  687. *
  688. * Note that a target object is always only searched for `val`'s own
  689. * enumerable properties.
  690. *
  691. * `.deep` and `.own` can be combined.
  692. *
  693. * expect({a: {b: 2}}).to.deep.own.include({a: {b: 2}});
  694. *
  695. * Add `.nested` earlier in the chain to enable dot- and bracket-notation when
  696. * referencing nested properties.
  697. *
  698. * expect({a: {b: ['x', 'y']}}).to.nested.include({'a.b[1]': 'y'});
  699. *
  700. * If `.` or `[]` are part of an actual property name, they can be escaped by
  701. * adding two backslashes before them.
  702. *
  703. * expect({'.a': {'[b]': 2}}).to.nested.include({'\\.a.\\[b\\]': 2});
  704. *
  705. * `.deep` and `.nested` can be combined.
  706. *
  707. * expect({a: {b: [{c: 3}]}}).to.deep.nested.include({'a.b[0]': {c: 3}});
  708. *
  709. * `.own` and `.nested` cannot be combined.
  710. *
  711. * Add `.not` earlier in the chain to negate `.include`.
  712. *
  713. * expect('foobar').to.not.include('taco');
  714. * expect([1, 2, 3]).to.not.include(4);
  715. *
  716. * However, it's dangerous to negate `.include` when the target is an object.
  717. * The problem is that it creates uncertain expectations by asserting that the
  718. * target object doesn't have all of `val`'s key/value pairs but may or may
  719. * not have some of them. It's often best to identify the exact output that's
  720. * expected, and then write an assertion that only accepts that exact output.
  721. *
  722. * When the target object isn't even expected to have `val`'s keys, it's
  723. * often best to assert exactly that.
  724. *
  725. * expect({c: 3}).to.not.have.any.keys('a', 'b'); // Recommended
  726. * expect({c: 3}).to.not.include({a: 1, b: 2}); // Not recommended
  727. *
  728. * When the target object is expected to have `val`'s keys, it's often best to
  729. * assert that each of the properties has its expected value, rather than
  730. * asserting that each property doesn't have one of many unexpected values.
  731. *
  732. * expect({a: 3, b: 4}).to.include({a: 3, b: 4}); // Recommended
  733. * expect({a: 3, b: 4}).to.not.include({a: 1, b: 2}); // Not recommended
  734. *
  735. * `.include` accepts an optional `msg` argument which is a custom error
  736. * message to show when the assertion fails. The message can also be given as
  737. * the second argument to `expect`.
  738. *
  739. * expect([1, 2, 3]).to.include(4, 'nooo why fail??');
  740. * expect([1, 2, 3], 'nooo why fail??').to.include(4);
  741. *
  742. * `.include` can also be used as a language chain, causing all `.members` and
  743. * `.keys` assertions that follow in the chain to require the target to be a
  744. * superset of the expected set, rather than an identical set. Note that
  745. * `.members` ignores duplicates in the subset when `.include` is added.
  746. *
  747. * // Target object's keys are a superset of ['a', 'b'] but not identical
  748. * expect({a: 1, b: 2, c: 3}).to.include.all.keys('a', 'b');
  749. * expect({a: 1, b: 2, c: 3}).to.not.have.all.keys('a', 'b');
  750. *
  751. * // Target array is a superset of [1, 2] but not identical
  752. * expect([1, 2, 3]).to.include.members([1, 2]);
  753. * expect([1, 2, 3]).to.not.have.members([1, 2]);
  754. *
  755. * // Duplicates in the subset are ignored
  756. * expect([1, 2, 3]).to.include.members([1, 2, 2, 2]);
  757. *
  758. * Note that adding `.any` earlier in the chain causes the `.keys` assertion
  759. * to ignore `.include`.
  760. *
  761. * // Both assertions are identical
  762. * expect({a: 1}).to.include.any.keys('a', 'b');
  763. * expect({a: 1}).to.have.any.keys('a', 'b');
  764. *
  765. * The aliases `.includes`, `.contain`, and `.contains` can be used
  766. * interchangeably with `.include`.
  767. *
  768. * @name include
  769. * @alias contain
  770. * @alias includes
  771. * @alias contains
  772. * @param {Mixed} val
  773. * @param {String} msg _optional_
  774. * @namespace BDD
  775. * @api public
  776. */
  777. function SameValueZero(a, b) {
  778. return (_.isNaN(a) && _.isNaN(b)) || a === b;
  779. }
  780. function includeChainingBehavior () {
  781. flag(this, 'contains', true);
  782. }
  783. function include (val, msg) {
  784. if (msg) flag(this, 'message', msg);
  785. var obj = flag(this, 'object')
  786. , objType = _.type(obj).toLowerCase()
  787. , flagMsg = flag(this, 'message')
  788. , negate = flag(this, 'negate')
  789. , ssfi = flag(this, 'ssfi')
  790. , isDeep = flag(this, 'deep')
  791. , descriptor = isDeep ? 'deep ' : ''
  792. , isEql = isDeep ? flag(this, 'eql') : SameValueZero;
  793. flagMsg = flagMsg ? flagMsg + ': ' : '';
  794. var included = false;
  795. switch (objType) {
  796. case 'string':
  797. included = obj.indexOf(val) !== -1;
  798. break;
  799. case 'weakset':
  800. if (isDeep) {
  801. throw new AssertionError(
  802. flagMsg + 'unable to use .deep.include with WeakSet',
  803. undefined,
  804. ssfi
  805. );
  806. }
  807. included = obj.has(val);
  808. break;
  809. case 'map':
  810. obj.forEach(function (item) {
  811. included = included || isEql(item, val);
  812. });
  813. break;
  814. case 'set':
  815. if (isDeep) {
  816. obj.forEach(function (item) {
  817. included = included || isEql(item, val);
  818. });
  819. } else {
  820. included = obj.has(val);
  821. }
  822. break;
  823. case 'array':
  824. if (isDeep) {
  825. included = obj.some(function (item) {
  826. return isEql(item, val);
  827. })
  828. } else {
  829. included = obj.indexOf(val) !== -1;
  830. }
  831. break;
  832. default:
  833. // This block is for asserting a subset of properties in an object.
  834. // `_.expectTypes` isn't used here because `.include` should work with
  835. // objects with a custom `@@toStringTag`.
  836. if (val !== Object(val)) {
  837. throw new AssertionError(
  838. flagMsg + 'the given combination of arguments ('
  839. + objType + ' and '
  840. + _.type(val).toLowerCase() + ')'
  841. + ' is invalid for this assertion. '
  842. + 'You can use an array, a map, an object, a set, a string, '
  843. + 'or a weakset instead of a '
  844. + _.type(val).toLowerCase(),
  845. undefined,
  846. ssfi
  847. );
  848. }
  849. var props = Object.keys(val)
  850. , firstErr = null
  851. , numErrs = 0;
  852. props.forEach(function (prop) {
  853. var propAssertion = new Assertion(obj);
  854. _.transferFlags(this, propAssertion, true);
  855. flag(propAssertion, 'lockSsfi', true);
  856. if (!negate || props.length === 1) {
  857. propAssertion.property(prop, val[prop]);
  858. return;
  859. }
  860. try {
  861. propAssertion.property(prop, val[prop]);
  862. } catch (err) {
  863. if (!_.checkError.compatibleConstructor(err, AssertionError)) {
  864. throw err;
  865. }
  866. if (firstErr === null) firstErr = err;
  867. numErrs++;
  868. }
  869. }, this);
  870. // When validating .not.include with multiple properties, we only want
  871. // to throw an assertion error if all of the properties are included,
  872. // in which case we throw the first property assertion error that we
  873. // encountered.
  874. if (negate && props.length > 1 && numErrs === props.length) {
  875. throw firstErr;
  876. }
  877. return;
  878. }
  879. // Assert inclusion in collection or substring in a string.
  880. this.assert(
  881. included
  882. , 'expected #{this} to ' + descriptor + 'include ' + _.inspect(val)
  883. , 'expected #{this} to not ' + descriptor + 'include ' + _.inspect(val));
  884. }
  885. Assertion.addChainableMethod('include', include, includeChainingBehavior);
  886. Assertion.addChainableMethod('contain', include, includeChainingBehavior);
  887. Assertion.addChainableMethod('contains', include, includeChainingBehavior);
  888. Assertion.addChainableMethod('includes', include, includeChainingBehavior);
  889. /**
  890. * ### .ok
  891. *
  892. * Asserts that the target is a truthy value (considered `true` in boolean context).
  893. * However, it's often best to assert that the target is strictly (`===`) or
  894. * deeply equal to its expected value.
  895. *
  896. * expect(1).to.equal(1); // Recommended
  897. * expect(1).to.be.ok; // Not recommended
  898. *
  899. * expect(true).to.be.true; // Recommended
  900. * expect(true).to.be.ok; // Not recommended
  901. *
  902. * Add `.not` earlier in the chain to negate `.ok`.
  903. *
  904. * expect(0).to.equal(0); // Recommended
  905. * expect(0).to.not.be.ok; // Not recommended
  906. *
  907. * expect(false).to.be.false; // Recommended
  908. * expect(false).to.not.be.ok; // Not recommended
  909. *
  910. * expect(null).to.be.null; // Recommended
  911. * expect(null).to.not.be.ok; // Not recommended
  912. *
  913. * expect(undefined).to.be.undefined; // Recommended
  914. * expect(undefined).to.not.be.ok; // Not recommended
  915. *
  916. * A custom error message can be given as the second argument to `expect`.
  917. *
  918. * expect(false, 'nooo why fail??').to.be.ok;
  919. *
  920. * @name ok
  921. * @namespace BDD
  922. * @api public
  923. */
  924. Assertion.addProperty('ok', function () {
  925. this.assert(
  926. flag(this, 'object')
  927. , 'expected #{this} to be truthy'
  928. , 'expected #{this} to be falsy');
  929. });
  930. /**
  931. * ### .true
  932. *
  933. * Asserts that the target is strictly (`===`) equal to `true`.
  934. *
  935. * expect(true).to.be.true;
  936. *
  937. * Add `.not` earlier in the chain to negate `.true`. However, it's often best
  938. * to assert that the target is equal to its expected value, rather than not
  939. * equal to `true`.
  940. *
  941. * expect(false).to.be.false; // Recommended
  942. * expect(false).to.not.be.true; // Not recommended
  943. *
  944. * expect(1).to.equal(1); // Recommended
  945. * expect(1).to.not.be.true; // Not recommended
  946. *
  947. * A custom error message can be given as the second argument to `expect`.
  948. *
  949. * expect(false, 'nooo why fail??').to.be.true;
  950. *
  951. * @name true
  952. * @namespace BDD
  953. * @api public
  954. */
  955. Assertion.addProperty('true', function () {
  956. this.assert(
  957. true === flag(this, 'object')
  958. , 'expected #{this} to be true'
  959. , 'expected #{this} to be false'
  960. , flag(this, 'negate') ? false : true
  961. );
  962. });
  963. /**
  964. * ### .false
  965. *
  966. * Asserts that the target is strictly (`===`) equal to `false`.
  967. *
  968. * expect(false).to.be.false;
  969. *
  970. * Add `.not` earlier in the chain to negate `.false`. However, it's often
  971. * best to assert that the target is equal to its expected value, rather than
  972. * not equal to `false`.
  973. *
  974. * expect(true).to.be.true; // Recommended
  975. * expect(true).to.not.be.false; // Not recommended
  976. *
  977. * expect(1).to.equal(1); // Recommended
  978. * expect(1).to.not.be.false; // Not recommended
  979. *
  980. * A custom error message can be given as the second argument to `expect`.
  981. *
  982. * expect(true, 'nooo why fail??').to.be.false;
  983. *
  984. * @name false
  985. * @namespace BDD
  986. * @api public
  987. */
  988. Assertion.addProperty('false', function () {
  989. this.assert(
  990. false === flag(this, 'object')
  991. , 'expected #{this} to be false'
  992. , 'expected #{this} to be true'
  993. , flag(this, 'negate') ? true : false
  994. );
  995. });
  996. /**
  997. * ### .null
  998. *
  999. * Asserts that the target is strictly (`===`) equal to `null`.
  1000. *
  1001. * expect(null).to.be.null;
  1002. *
  1003. * Add `.not` earlier in the chain to negate `.null`. However, it's often best
  1004. * to assert that the target is equal to its expected value, rather than not
  1005. * equal to `null`.
  1006. *
  1007. * expect(1).to.equal(1); // Recommended
  1008. * expect(1).to.not.be.null; // Not recommended
  1009. *
  1010. * A custom error message can be given as the second argument to `expect`.
  1011. *
  1012. * expect(42, 'nooo why fail??').to.be.null;
  1013. *
  1014. * @name null
  1015. * @namespace BDD
  1016. * @api public
  1017. */
  1018. Assertion.addProperty('null', function () {
  1019. this.assert(
  1020. null === flag(this, 'object')
  1021. , 'expected #{this} to be null'
  1022. , 'expected #{this} not to be null'
  1023. );
  1024. });
  1025. /**
  1026. * ### .undefined
  1027. *
  1028. * Asserts that the target is strictly (`===`) equal to `undefined`.
  1029. *
  1030. * expect(undefined).to.be.undefined;
  1031. *
  1032. * Add `.not` earlier in the chain to negate `.undefined`. However, it's often
  1033. * best to assert that the target is equal to its expected value, rather than
  1034. * not equal to `undefined`.
  1035. *
  1036. * expect(1).to.equal(1); // Recommended
  1037. * expect(1).to.not.be.undefined; // Not recommended
  1038. *
  1039. * A custom error message can be given as the second argument to `expect`.
  1040. *
  1041. * expect(42, 'nooo why fail??').to.be.undefined;
  1042. *
  1043. * @name undefined
  1044. * @namespace BDD
  1045. * @api public
  1046. */
  1047. Assertion.addProperty('undefined', function () {
  1048. this.assert(
  1049. undefined === flag(this, 'object')
  1050. , 'expected #{this} to be undefined'
  1051. , 'expected #{this} not to be undefined'
  1052. );
  1053. });
  1054. /**
  1055. * ### .NaN
  1056. *
  1057. * Asserts that the target is exactly `NaN`.
  1058. *
  1059. * expect(NaN).to.be.NaN;
  1060. *
  1061. * Add `.not` earlier in the chain to negate `.NaN`. However, it's often best
  1062. * to assert that the target is equal to its expected value, rather than not
  1063. * equal to `NaN`.
  1064. *
  1065. * expect('foo').to.equal('foo'); // Recommended
  1066. * expect('foo').to.not.be.NaN; // Not recommended
  1067. *
  1068. * A custom error message can be given as the second argument to `expect`.
  1069. *
  1070. * expect(42, 'nooo why fail??').to.be.NaN;
  1071. *
  1072. * @name NaN
  1073. * @namespace BDD
  1074. * @api public
  1075. */
  1076. Assertion.addProperty('NaN', function () {
  1077. this.assert(
  1078. _.isNaN(flag(this, 'object'))
  1079. , 'expected #{this} to be NaN'
  1080. , 'expected #{this} not to be NaN'
  1081. );
  1082. });
  1083. /**
  1084. * ### .exist
  1085. *
  1086. * Asserts that the target is not strictly (`===`) equal to either `null` or
  1087. * `undefined`. However, it's often best to assert that the target is equal to
  1088. * its expected value.
  1089. *
  1090. * expect(1).to.equal(1); // Recommended
  1091. * expect(1).to.exist; // Not recommended
  1092. *
  1093. * expect(0).to.equal(0); // Recommended
  1094. * expect(0).to.exist; // Not recommended
  1095. *
  1096. * Add `.not` earlier in the chain to negate `.exist`.
  1097. *
  1098. * expect(null).to.be.null; // Recommended
  1099. * expect(null).to.not.exist; // Not recommended
  1100. *
  1101. * expect(undefined).to.be.undefined; // Recommended
  1102. * expect(undefined).to.not.exist; // Not recommended
  1103. *
  1104. * A custom error message can be given as the second argument to `expect`.
  1105. *
  1106. * expect(null, 'nooo why fail??').to.exist;
  1107. *
  1108. * The alias `.exists` can be used interchangeably with `.exist`.
  1109. *
  1110. * @name exist
  1111. * @alias exists
  1112. * @namespace BDD
  1113. * @api public
  1114. */
  1115. function assertExist () {
  1116. var val = flag(this, 'object');
  1117. this.assert(
  1118. val !== null && val !== undefined
  1119. , 'expected #{this} to exist'
  1120. , 'expected #{this} to not exist'
  1121. );
  1122. }
  1123. Assertion.addProperty('exist', assertExist);
  1124. Assertion.addProperty('exists', assertExist);
  1125. /**
  1126. * ### .empty
  1127. *
  1128. * When the target is a string or array, `.empty` asserts that the target's
  1129. * `length` property is strictly (`===`) equal to `0`.
  1130. *
  1131. * expect([]).to.be.empty;
  1132. * expect('').to.be.empty;
  1133. *
  1134. * When the target is a map or set, `.empty` asserts that the target's `size`
  1135. * property is strictly equal to `0`.
  1136. *
  1137. * expect(new Set()).to.be.empty;
  1138. * expect(new Map()).to.be.empty;
  1139. *
  1140. * When the target is a non-function object, `.empty` asserts that the target
  1141. * doesn't have any own enumerable properties. Properties with Symbol-based
  1142. * keys are excluded from the count.
  1143. *
  1144. * expect({}).to.be.empty;
  1145. *
  1146. * Because `.empty` does different things based on the target's type, it's
  1147. * important to check the target's type before using `.empty`. See the `.a`
  1148. * doc for info on testing a target's type.
  1149. *
  1150. * expect([]).to.be.an('array').that.is.empty;
  1151. *
  1152. * Add `.not` earlier in the chain to negate `.empty`. However, it's often
  1153. * best to assert that the target contains its expected number of values,
  1154. * rather than asserting that it's not empty.
  1155. *
  1156. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1157. * expect([1, 2, 3]).to.not.be.empty; // Not recommended
  1158. *
  1159. * expect(new Set([1, 2, 3])).to.have.property('size', 3); // Recommended
  1160. * expect(new Set([1, 2, 3])).to.not.be.empty; // Not recommended
  1161. *
  1162. * expect(Object.keys({a: 1})).to.have.lengthOf(1); // Recommended
  1163. * expect({a: 1}).to.not.be.empty; // Not recommended
  1164. *
  1165. * A custom error message can be given as the second argument to `expect`.
  1166. *
  1167. * expect([1, 2, 3], 'nooo why fail??').to.be.empty;
  1168. *
  1169. * @name empty
  1170. * @namespace BDD
  1171. * @api public
  1172. */
  1173. Assertion.addProperty('empty', function () {
  1174. var val = flag(this, 'object')
  1175. , ssfi = flag(this, 'ssfi')
  1176. , flagMsg = flag(this, 'message')
  1177. , itemsCount;
  1178. flagMsg = flagMsg ? flagMsg + ': ' : '';
  1179. switch (_.type(val).toLowerCase()) {
  1180. case 'array':
  1181. case 'string':
  1182. itemsCount = val.length;
  1183. break;
  1184. case 'map':
  1185. case 'set':
  1186. itemsCount = val.size;
  1187. break;
  1188. case 'weakmap':
  1189. case 'weakset':
  1190. throw new AssertionError(
  1191. flagMsg + '.empty was passed a weak collection',
  1192. undefined,
  1193. ssfi
  1194. );
  1195. case 'function':
  1196. var msg = flagMsg + '.empty was passed a function ' + _.getName(val);
  1197. throw new AssertionError(msg.trim(), undefined, ssfi);
  1198. default:
  1199. if (val !== Object(val)) {
  1200. throw new AssertionError(
  1201. flagMsg + '.empty was passed non-string primitive ' + _.inspect(val),
  1202. undefined,
  1203. ssfi
  1204. );
  1205. }
  1206. itemsCount = Object.keys(val).length;
  1207. }
  1208. this.assert(
  1209. 0 === itemsCount
  1210. , 'expected #{this} to be empty'
  1211. , 'expected #{this} not to be empty'
  1212. );
  1213. });
  1214. /**
  1215. * ### .arguments
  1216. *
  1217. * Asserts that the target is an `arguments` object.
  1218. *
  1219. * function test () {
  1220. * expect(arguments).to.be.arguments;
  1221. * }
  1222. *
  1223. * test();
  1224. *
  1225. * Add `.not` earlier in the chain to negate `.arguments`. However, it's often
  1226. * best to assert which type the target is expected to be, rather than
  1227. * asserting that it’s not an `arguments` object.
  1228. *
  1229. * expect('foo').to.be.a('string'); // Recommended
  1230. * expect('foo').to.not.be.arguments; // Not recommended
  1231. *
  1232. * A custom error message can be given as the second argument to `expect`.
  1233. *
  1234. * expect({}, 'nooo why fail??').to.be.arguments;
  1235. *
  1236. * The alias `.Arguments` can be used interchangeably with `.arguments`.
  1237. *
  1238. * @name arguments
  1239. * @alias Arguments
  1240. * @namespace BDD
  1241. * @api public
  1242. */
  1243. function checkArguments () {
  1244. var obj = flag(this, 'object')
  1245. , type = _.type(obj);
  1246. this.assert(
  1247. 'Arguments' === type
  1248. , 'expected #{this} to be arguments but got ' + type
  1249. , 'expected #{this} to not be arguments'
  1250. );
  1251. }
  1252. Assertion.addProperty('arguments', checkArguments);
  1253. Assertion.addProperty('Arguments', checkArguments);
  1254. /**
  1255. * ### .equal(val[, msg])
  1256. *
  1257. * Asserts that the target is strictly (`===`) equal to the given `val`.
  1258. *
  1259. * expect(1).to.equal(1);
  1260. * expect('foo').to.equal('foo');
  1261. *
  1262. * Add `.deep` earlier in the chain to use deep equality instead. See the
  1263. * `deep-eql` project page for info on the deep equality algorithm:
  1264. * https://github.com/chaijs/deep-eql.
  1265. *
  1266. * // Target object deeply (but not strictly) equals `{a: 1}`
  1267. * expect({a: 1}).to.deep.equal({a: 1});
  1268. * expect({a: 1}).to.not.equal({a: 1});
  1269. *
  1270. * // Target array deeply (but not strictly) equals `[1, 2]`
  1271. * expect([1, 2]).to.deep.equal([1, 2]);
  1272. * expect([1, 2]).to.not.equal([1, 2]);
  1273. *
  1274. * Add `.not` earlier in the chain to negate `.equal`. However, it's often
  1275. * best to assert that the target is equal to its expected value, rather than
  1276. * not equal to one of countless unexpected values.
  1277. *
  1278. * expect(1).to.equal(1); // Recommended
  1279. * expect(1).to.not.equal(2); // Not recommended
  1280. *
  1281. * `.equal` accepts an optional `msg` argument which is a custom error message
  1282. * to show when the assertion fails. The message can also be given as the
  1283. * second argument to `expect`.
  1284. *
  1285. * expect(1).to.equal(2, 'nooo why fail??');
  1286. * expect(1, 'nooo why fail??').to.equal(2);
  1287. *
  1288. * The aliases `.equals` and `eq` can be used interchangeably with `.equal`.
  1289. *
  1290. * @name equal
  1291. * @alias equals
  1292. * @alias eq
  1293. * @param {Mixed} val
  1294. * @param {String} msg _optional_
  1295. * @namespace BDD
  1296. * @api public
  1297. */
  1298. function assertEqual (val, msg) {
  1299. if (msg) flag(this, 'message', msg);
  1300. var obj = flag(this, 'object');
  1301. if (flag(this, 'deep')) {
  1302. var prevLockSsfi = flag(this, 'lockSsfi');
  1303. flag(this, 'lockSsfi', true);
  1304. this.eql(val);
  1305. flag(this, 'lockSsfi', prevLockSsfi);
  1306. } else {
  1307. this.assert(
  1308. val === obj
  1309. , 'expected #{this} to equal #{exp}'
  1310. , 'expected #{this} to not equal #{exp}'
  1311. , val
  1312. , this._obj
  1313. , true
  1314. );
  1315. }
  1316. }
  1317. Assertion.addMethod('equal', assertEqual);
  1318. Assertion.addMethod('equals', assertEqual);
  1319. Assertion.addMethod('eq', assertEqual);
  1320. /**
  1321. * ### .eql(obj[, msg])
  1322. *
  1323. * Asserts that the target is deeply equal to the given `obj`. See the
  1324. * `deep-eql` project page for info on the deep equality algorithm:
  1325. * https://github.com/chaijs/deep-eql.
  1326. *
  1327. * // Target object is deeply (but not strictly) equal to {a: 1}
  1328. * expect({a: 1}).to.eql({a: 1}).but.not.equal({a: 1});
  1329. *
  1330. * // Target array is deeply (but not strictly) equal to [1, 2]
  1331. * expect([1, 2]).to.eql([1, 2]).but.not.equal([1, 2]);
  1332. *
  1333. * Add `.not` earlier in the chain to negate `.eql`. However, it's often best
  1334. * to assert that the target is deeply equal to its expected value, rather
  1335. * than not deeply equal to one of countless unexpected values.
  1336. *
  1337. * expect({a: 1}).to.eql({a: 1}); // Recommended
  1338. * expect({a: 1}).to.not.eql({b: 2}); // Not recommended
  1339. *
  1340. * `.eql` accepts an optional `msg` argument which is a custom error message
  1341. * to show when the assertion fails. The message can also be given as the
  1342. * second argument to `expect`.
  1343. *
  1344. * expect({a: 1}).to.eql({b: 2}, 'nooo why fail??');
  1345. * expect({a: 1}, 'nooo why fail??').to.eql({b: 2});
  1346. *
  1347. * The alias `.eqls` can be used interchangeably with `.eql`.
  1348. *
  1349. * The `.deep.equal` assertion is almost identical to `.eql` but with one
  1350. * difference: `.deep.equal` causes deep equality comparisons to also be used
  1351. * for any other assertions that follow in the chain.
  1352. *
  1353. * @name eql
  1354. * @alias eqls
  1355. * @param {Mixed} obj
  1356. * @param {String} msg _optional_
  1357. * @namespace BDD
  1358. * @api public
  1359. */
  1360. function assertEql(obj, msg) {
  1361. if (msg) flag(this, 'message', msg);
  1362. var eql = flag(this, 'eql');
  1363. this.assert(
  1364. eql(obj, flag(this, 'object'))
  1365. , 'expected #{this} to deeply equal #{exp}'
  1366. , 'expected #{this} to not deeply equal #{exp}'
  1367. , obj
  1368. , this._obj
  1369. , true
  1370. );
  1371. }
  1372. Assertion.addMethod('eql', assertEql);
  1373. Assertion.addMethod('eqls', assertEql);
  1374. /**
  1375. * ### .above(n[, msg])
  1376. *
  1377. * Asserts that the target is a number or a date greater than the given number or date `n` respectively.
  1378. * However, it's often best to assert that the target is equal to its expected
  1379. * value.
  1380. *
  1381. * expect(2).to.equal(2); // Recommended
  1382. * expect(2).to.be.above(1); // Not recommended
  1383. *
  1384. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1385. * or `size` is greater than the given number `n`.
  1386. *
  1387. * expect('foo').to.have.lengthOf(3); // Recommended
  1388. * expect('foo').to.have.lengthOf.above(2); // Not recommended
  1389. *
  1390. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1391. * expect([1, 2, 3]).to.have.lengthOf.above(2); // Not recommended
  1392. *
  1393. * Add `.not` earlier in the chain to negate `.above`.
  1394. *
  1395. * expect(2).to.equal(2); // Recommended
  1396. * expect(1).to.not.be.above(2); // Not recommended
  1397. *
  1398. * `.above` accepts an optional `msg` argument which is a custom error message
  1399. * to show when the assertion fails. The message can also be given as the
  1400. * second argument to `expect`.
  1401. *
  1402. * expect(1).to.be.above(2, 'nooo why fail??');
  1403. * expect(1, 'nooo why fail??').to.be.above(2);
  1404. *
  1405. * The aliases `.gt` and `.greaterThan` can be used interchangeably with
  1406. * `.above`.
  1407. *
  1408. * @name above
  1409. * @alias gt
  1410. * @alias greaterThan
  1411. * @param {Number} n
  1412. * @param {String} msg _optional_
  1413. * @namespace BDD
  1414. * @api public
  1415. */
  1416. function assertAbove (n, msg) {
  1417. if (msg) flag(this, 'message', msg);
  1418. var obj = flag(this, 'object')
  1419. , doLength = flag(this, 'doLength')
  1420. , flagMsg = flag(this, 'message')
  1421. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1422. , ssfi = flag(this, 'ssfi')
  1423. , objType = _.type(obj).toLowerCase()
  1424. , nType = _.type(n).toLowerCase()
  1425. , errorMessage
  1426. , shouldThrow = true;
  1427. if (doLength && objType !== 'map' && objType !== 'set') {
  1428. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1429. }
  1430. if (!doLength && (objType === 'date' && nType !== 'date')) {
  1431. errorMessage = msgPrefix + 'the argument to above must be a date';
  1432. } else if (nType !== 'number' && (doLength || objType === 'number')) {
  1433. errorMessage = msgPrefix + 'the argument to above must be a number';
  1434. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1435. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1436. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1437. } else {
  1438. shouldThrow = false;
  1439. }
  1440. if (shouldThrow) {
  1441. throw new AssertionError(errorMessage, undefined, ssfi);
  1442. }
  1443. if (doLength) {
  1444. var descriptor = 'length'
  1445. , itemsCount;
  1446. if (objType === 'map' || objType === 'set') {
  1447. descriptor = 'size';
  1448. itemsCount = obj.size;
  1449. } else {
  1450. itemsCount = obj.length;
  1451. }
  1452. this.assert(
  1453. itemsCount > n
  1454. , 'expected #{this} to have a ' + descriptor + ' above #{exp} but got #{act}'
  1455. , 'expected #{this} to not have a ' + descriptor + ' above #{exp}'
  1456. , n
  1457. , itemsCount
  1458. );
  1459. } else {
  1460. this.assert(
  1461. obj > n
  1462. , 'expected #{this} to be above #{exp}'
  1463. , 'expected #{this} to be at most #{exp}'
  1464. , n
  1465. );
  1466. }
  1467. }
  1468. Assertion.addMethod('above', assertAbove);
  1469. Assertion.addMethod('gt', assertAbove);
  1470. Assertion.addMethod('greaterThan', assertAbove);
  1471. /**
  1472. * ### .least(n[, msg])
  1473. *
  1474. * Asserts that the target is a number or a date greater than or equal to the given
  1475. * number or date `n` respectively. However, it's often best to assert that the target is equal to
  1476. * its expected value.
  1477. *
  1478. * expect(2).to.equal(2); // Recommended
  1479. * expect(2).to.be.at.least(1); // Not recommended
  1480. * expect(2).to.be.at.least(2); // Not recommended
  1481. *
  1482. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1483. * or `size` is greater than or equal to the given number `n`.
  1484. *
  1485. * expect('foo').to.have.lengthOf(3); // Recommended
  1486. * expect('foo').to.have.lengthOf.at.least(2); // Not recommended
  1487. *
  1488. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1489. * expect([1, 2, 3]).to.have.lengthOf.at.least(2); // Not recommended
  1490. *
  1491. * Add `.not` earlier in the chain to negate `.least`.
  1492. *
  1493. * expect(1).to.equal(1); // Recommended
  1494. * expect(1).to.not.be.at.least(2); // Not recommended
  1495. *
  1496. * `.least` accepts an optional `msg` argument which is a custom error message
  1497. * to show when the assertion fails. The message can also be given as the
  1498. * second argument to `expect`.
  1499. *
  1500. * expect(1).to.be.at.least(2, 'nooo why fail??');
  1501. * expect(1, 'nooo why fail??').to.be.at.least(2);
  1502. *
  1503. * The aliases `.gte` and `.greaterThanOrEqual` can be used interchangeably with
  1504. * `.least`.
  1505. *
  1506. * @name least
  1507. * @alias gte
  1508. * @alias greaterThanOrEqual
  1509. * @param {Number} n
  1510. * @param {String} msg _optional_
  1511. * @namespace BDD
  1512. * @api public
  1513. */
  1514. function assertLeast (n, msg) {
  1515. if (msg) flag(this, 'message', msg);
  1516. var obj = flag(this, 'object')
  1517. , doLength = flag(this, 'doLength')
  1518. , flagMsg = flag(this, 'message')
  1519. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1520. , ssfi = flag(this, 'ssfi')
  1521. , objType = _.type(obj).toLowerCase()
  1522. , nType = _.type(n).toLowerCase()
  1523. , errorMessage
  1524. , shouldThrow = true;
  1525. if (doLength && objType !== 'map' && objType !== 'set') {
  1526. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1527. }
  1528. if (!doLength && (objType === 'date' && nType !== 'date')) {
  1529. errorMessage = msgPrefix + 'the argument to least must be a date';
  1530. } else if (nType !== 'number' && (doLength || objType === 'number')) {
  1531. errorMessage = msgPrefix + 'the argument to least must be a number';
  1532. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1533. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1534. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1535. } else {
  1536. shouldThrow = false;
  1537. }
  1538. if (shouldThrow) {
  1539. throw new AssertionError(errorMessage, undefined, ssfi);
  1540. }
  1541. if (doLength) {
  1542. var descriptor = 'length'
  1543. , itemsCount;
  1544. if (objType === 'map' || objType === 'set') {
  1545. descriptor = 'size';
  1546. itemsCount = obj.size;
  1547. } else {
  1548. itemsCount = obj.length;
  1549. }
  1550. this.assert(
  1551. itemsCount >= n
  1552. , 'expected #{this} to have a ' + descriptor + ' at least #{exp} but got #{act}'
  1553. , 'expected #{this} to have a ' + descriptor + ' below #{exp}'
  1554. , n
  1555. , itemsCount
  1556. );
  1557. } else {
  1558. this.assert(
  1559. obj >= n
  1560. , 'expected #{this} to be at least #{exp}'
  1561. , 'expected #{this} to be below #{exp}'
  1562. , n
  1563. );
  1564. }
  1565. }
  1566. Assertion.addMethod('least', assertLeast);
  1567. Assertion.addMethod('gte', assertLeast);
  1568. Assertion.addMethod('greaterThanOrEqual', assertLeast);
  1569. /**
  1570. * ### .below(n[, msg])
  1571. *
  1572. * Asserts that the target is a number or a date less than the given number or date `n` respectively.
  1573. * However, it's often best to assert that the target is equal to its expected
  1574. * value.
  1575. *
  1576. * expect(1).to.equal(1); // Recommended
  1577. * expect(1).to.be.below(2); // Not recommended
  1578. *
  1579. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1580. * or `size` is less than the given number `n`.
  1581. *
  1582. * expect('foo').to.have.lengthOf(3); // Recommended
  1583. * expect('foo').to.have.lengthOf.below(4); // Not recommended
  1584. *
  1585. * expect([1, 2, 3]).to.have.length(3); // Recommended
  1586. * expect([1, 2, 3]).to.have.lengthOf.below(4); // Not recommended
  1587. *
  1588. * Add `.not` earlier in the chain to negate `.below`.
  1589. *
  1590. * expect(2).to.equal(2); // Recommended
  1591. * expect(2).to.not.be.below(1); // Not recommended
  1592. *
  1593. * `.below` accepts an optional `msg` argument which is a custom error message
  1594. * to show when the assertion fails. The message can also be given as the
  1595. * second argument to `expect`.
  1596. *
  1597. * expect(2).to.be.below(1, 'nooo why fail??');
  1598. * expect(2, 'nooo why fail??').to.be.below(1);
  1599. *
  1600. * The aliases `.lt` and `.lessThan` can be used interchangeably with
  1601. * `.below`.
  1602. *
  1603. * @name below
  1604. * @alias lt
  1605. * @alias lessThan
  1606. * @param {Number} n
  1607. * @param {String} msg _optional_
  1608. * @namespace BDD
  1609. * @api public
  1610. */
  1611. function assertBelow (n, msg) {
  1612. if (msg) flag(this, 'message', msg);
  1613. var obj = flag(this, 'object')
  1614. , doLength = flag(this, 'doLength')
  1615. , flagMsg = flag(this, 'message')
  1616. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1617. , ssfi = flag(this, 'ssfi')
  1618. , objType = _.type(obj).toLowerCase()
  1619. , nType = _.type(n).toLowerCase()
  1620. , errorMessage
  1621. , shouldThrow = true;
  1622. if (doLength && objType !== 'map' && objType !== 'set') {
  1623. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1624. }
  1625. if (!doLength && (objType === 'date' && nType !== 'date')) {
  1626. errorMessage = msgPrefix + 'the argument to below must be a date';
  1627. } else if (nType !== 'number' && (doLength || objType === 'number')) {
  1628. errorMessage = msgPrefix + 'the argument to below must be a number';
  1629. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1630. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1631. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1632. } else {
  1633. shouldThrow = false;
  1634. }
  1635. if (shouldThrow) {
  1636. throw new AssertionError(errorMessage, undefined, ssfi);
  1637. }
  1638. if (doLength) {
  1639. var descriptor = 'length'
  1640. , itemsCount;
  1641. if (objType === 'map' || objType === 'set') {
  1642. descriptor = 'size';
  1643. itemsCount = obj.size;
  1644. } else {
  1645. itemsCount = obj.length;
  1646. }
  1647. this.assert(
  1648. itemsCount < n
  1649. , 'expected #{this} to have a ' + descriptor + ' below #{exp} but got #{act}'
  1650. , 'expected #{this} to not have a ' + descriptor + ' below #{exp}'
  1651. , n
  1652. , itemsCount
  1653. );
  1654. } else {
  1655. this.assert(
  1656. obj < n
  1657. , 'expected #{this} to be below #{exp}'
  1658. , 'expected #{this} to be at least #{exp}'
  1659. , n
  1660. );
  1661. }
  1662. }
  1663. Assertion.addMethod('below', assertBelow);
  1664. Assertion.addMethod('lt', assertBelow);
  1665. Assertion.addMethod('lessThan', assertBelow);
  1666. /**
  1667. * ### .most(n[, msg])
  1668. *
  1669. * Asserts that the target is a number or a date less than or equal to the given number
  1670. * or date `n` respectively. However, it's often best to assert that the target is equal to its
  1671. * expected value.
  1672. *
  1673. * expect(1).to.equal(1); // Recommended
  1674. * expect(1).to.be.at.most(2); // Not recommended
  1675. * expect(1).to.be.at.most(1); // Not recommended
  1676. *
  1677. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1678. * or `size` is less than or equal to the given number `n`.
  1679. *
  1680. * expect('foo').to.have.lengthOf(3); // Recommended
  1681. * expect('foo').to.have.lengthOf.at.most(4); // Not recommended
  1682. *
  1683. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1684. * expect([1, 2, 3]).to.have.lengthOf.at.most(4); // Not recommended
  1685. *
  1686. * Add `.not` earlier in the chain to negate `.most`.
  1687. *
  1688. * expect(2).to.equal(2); // Recommended
  1689. * expect(2).to.not.be.at.most(1); // Not recommended
  1690. *
  1691. * `.most` accepts an optional `msg` argument which is a custom error message
  1692. * to show when the assertion fails. The message can also be given as the
  1693. * second argument to `expect`.
  1694. *
  1695. * expect(2).to.be.at.most(1, 'nooo why fail??');
  1696. * expect(2, 'nooo why fail??').to.be.at.most(1);
  1697. *
  1698. * The aliases `.lte` and `.lessThanOrEqual` can be used interchangeably with
  1699. * `.most`.
  1700. *
  1701. * @name most
  1702. * @alias lte
  1703. * @alias lessThanOrEqual
  1704. * @param {Number} n
  1705. * @param {String} msg _optional_
  1706. * @namespace BDD
  1707. * @api public
  1708. */
  1709. function assertMost (n, msg) {
  1710. if (msg) flag(this, 'message', msg);
  1711. var obj = flag(this, 'object')
  1712. , doLength = flag(this, 'doLength')
  1713. , flagMsg = flag(this, 'message')
  1714. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1715. , ssfi = flag(this, 'ssfi')
  1716. , objType = _.type(obj).toLowerCase()
  1717. , nType = _.type(n).toLowerCase()
  1718. , errorMessage
  1719. , shouldThrow = true;
  1720. if (doLength && objType !== 'map' && objType !== 'set') {
  1721. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1722. }
  1723. if (!doLength && (objType === 'date' && nType !== 'date')) {
  1724. errorMessage = msgPrefix + 'the argument to most must be a date';
  1725. } else if (nType !== 'number' && (doLength || objType === 'number')) {
  1726. errorMessage = msgPrefix + 'the argument to most must be a number';
  1727. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1728. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1729. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1730. } else {
  1731. shouldThrow = false;
  1732. }
  1733. if (shouldThrow) {
  1734. throw new AssertionError(errorMessage, undefined, ssfi);
  1735. }
  1736. if (doLength) {
  1737. var descriptor = 'length'
  1738. , itemsCount;
  1739. if (objType === 'map' || objType === 'set') {
  1740. descriptor = 'size';
  1741. itemsCount = obj.size;
  1742. } else {
  1743. itemsCount = obj.length;
  1744. }
  1745. this.assert(
  1746. itemsCount <= n
  1747. , 'expected #{this} to have a ' + descriptor + ' at most #{exp} but got #{act}'
  1748. , 'expected #{this} to have a ' + descriptor + ' above #{exp}'
  1749. , n
  1750. , itemsCount
  1751. );
  1752. } else {
  1753. this.assert(
  1754. obj <= n
  1755. , 'expected #{this} to be at most #{exp}'
  1756. , 'expected #{this} to be above #{exp}'
  1757. , n
  1758. );
  1759. }
  1760. }
  1761. Assertion.addMethod('most', assertMost);
  1762. Assertion.addMethod('lte', assertMost);
  1763. Assertion.addMethod('lessThanOrEqual', assertMost);
  1764. /**
  1765. * ### .within(start, finish[, msg])
  1766. *
  1767. * Asserts that the target is a number or a date greater than or equal to the given
  1768. * number or date `start`, and less than or equal to the given number or date `finish` respectively.
  1769. * However, it's often best to assert that the target is equal to its expected
  1770. * value.
  1771. *
  1772. * expect(2).to.equal(2); // Recommended
  1773. * expect(2).to.be.within(1, 3); // Not recommended
  1774. * expect(2).to.be.within(2, 3); // Not recommended
  1775. * expect(2).to.be.within(1, 2); // Not recommended
  1776. *
  1777. * Add `.lengthOf` earlier in the chain to assert that the target's `length`
  1778. * or `size` is greater than or equal to the given number `start`, and less
  1779. * than or equal to the given number `finish`.
  1780. *
  1781. * expect('foo').to.have.lengthOf(3); // Recommended
  1782. * expect('foo').to.have.lengthOf.within(2, 4); // Not recommended
  1783. *
  1784. * expect([1, 2, 3]).to.have.lengthOf(3); // Recommended
  1785. * expect([1, 2, 3]).to.have.lengthOf.within(2, 4); // Not recommended
  1786. *
  1787. * Add `.not` earlier in the chain to negate `.within`.
  1788. *
  1789. * expect(1).to.equal(1); // Recommended
  1790. * expect(1).to.not.be.within(2, 4); // Not recommended
  1791. *
  1792. * `.within` accepts an optional `msg` argument which is a custom error
  1793. * message to show when the assertion fails. The message can also be given as
  1794. * the second argument to `expect`.
  1795. *
  1796. * expect(4).to.be.within(1, 3, 'nooo why fail??');
  1797. * expect(4, 'nooo why fail??').to.be.within(1, 3);
  1798. *
  1799. * @name within
  1800. * @param {Number} start lower bound inclusive
  1801. * @param {Number} finish upper bound inclusive
  1802. * @param {String} msg _optional_
  1803. * @namespace BDD
  1804. * @api public
  1805. */
  1806. Assertion.addMethod('within', function (start, finish, msg) {
  1807. if (msg) flag(this, 'message', msg);
  1808. var obj = flag(this, 'object')
  1809. , doLength = flag(this, 'doLength')
  1810. , flagMsg = flag(this, 'message')
  1811. , msgPrefix = ((flagMsg) ? flagMsg + ': ' : '')
  1812. , ssfi = flag(this, 'ssfi')
  1813. , objType = _.type(obj).toLowerCase()
  1814. , startType = _.type(start).toLowerCase()
  1815. , finishType = _.type(finish).toLowerCase()
  1816. , errorMessage
  1817. , shouldThrow = true
  1818. , range = (startType === 'date' && finishType === 'date')
  1819. ? start.toISOString() + '..' + finish.toISOString()
  1820. : start + '..' + finish;
  1821. if (doLength && objType !== 'map' && objType !== 'set') {
  1822. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  1823. }
  1824. if (!doLength && (objType === 'date' && (startType !== 'date' || finishType !== 'date'))) {
  1825. errorMessage = msgPrefix + 'the arguments to within must be dates';
  1826. } else if ((startType !== 'number' || finishType !== 'number') && (doLength || objType === 'number')) {
  1827. errorMessage = msgPrefix + 'the arguments to within must be numbers';
  1828. } else if (!doLength && (objType !== 'date' && objType !== 'number')) {
  1829. var printObj = (objType === 'string') ? "'" + obj + "'" : obj;
  1830. errorMessage = msgPrefix + 'expected ' + printObj + ' to be a number or a date';
  1831. } else {
  1832. shouldThrow = false;
  1833. }
  1834. if (shouldThrow) {
  1835. throw new AssertionError(errorMessage, undefined, ssfi);
  1836. }
  1837. if (doLength) {
  1838. var descriptor = 'length'
  1839. , itemsCount;
  1840. if (objType === 'map' || objType === 'set') {
  1841. descriptor = 'size';
  1842. itemsCount = obj.size;
  1843. } else {
  1844. itemsCount = obj.length;
  1845. }
  1846. this.assert(
  1847. itemsCount >= start && itemsCount <= finish
  1848. , 'expected #{this} to have a ' + descriptor + ' within ' + range
  1849. , 'expected #{this} to not have a ' + descriptor + ' within ' + range
  1850. );
  1851. } else {
  1852. this.assert(
  1853. obj >= start && obj <= finish
  1854. , 'expected #{this} to be within ' + range
  1855. , 'expected #{this} to not be within ' + range
  1856. );
  1857. }
  1858. });
  1859. /**
  1860. * ### .instanceof(constructor[, msg])
  1861. *
  1862. * Asserts that the target is an instance of the given `constructor`.
  1863. *
  1864. * function Cat () { }
  1865. *
  1866. * expect(new Cat()).to.be.an.instanceof(Cat);
  1867. * expect([1, 2]).to.be.an.instanceof(Array);
  1868. *
  1869. * Add `.not` earlier in the chain to negate `.instanceof`.
  1870. *
  1871. * expect({a: 1}).to.not.be.an.instanceof(Array);
  1872. *
  1873. * `.instanceof` accepts an optional `msg` argument which is a custom error
  1874. * message to show when the assertion fails. The message can also be given as
  1875. * the second argument to `expect`.
  1876. *
  1877. * expect(1).to.be.an.instanceof(Array, 'nooo why fail??');
  1878. * expect(1, 'nooo why fail??').to.be.an.instanceof(Array);
  1879. *
  1880. * Due to limitations in ES5, `.instanceof` may not always work as expected
  1881. * when using a transpiler such as Babel or TypeScript. In particular, it may
  1882. * produce unexpected results when subclassing built-in object such as
  1883. * `Array`, `Error`, and `Map`. See your transpiler's docs for details:
  1884. *
  1885. * - ([Babel](https://babeljs.io/docs/usage/caveats/#classes))
  1886. * - ([TypeScript](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work))
  1887. *
  1888. * The alias `.instanceOf` can be used interchangeably with `.instanceof`.
  1889. *
  1890. * @name instanceof
  1891. * @param {Constructor} constructor
  1892. * @param {String} msg _optional_
  1893. * @alias instanceOf
  1894. * @namespace BDD
  1895. * @api public
  1896. */
  1897. function assertInstanceOf (constructor, msg) {
  1898. if (msg) flag(this, 'message', msg);
  1899. var target = flag(this, 'object')
  1900. var ssfi = flag(this, 'ssfi');
  1901. var flagMsg = flag(this, 'message');
  1902. try {
  1903. var isInstanceOf = target instanceof constructor;
  1904. } catch (err) {
  1905. if (err instanceof TypeError) {
  1906. flagMsg = flagMsg ? flagMsg + ': ' : '';
  1907. throw new AssertionError(
  1908. flagMsg + 'The instanceof assertion needs a constructor but '
  1909. + _.type(constructor) + ' was given.',
  1910. undefined,
  1911. ssfi
  1912. );
  1913. }
  1914. throw err;
  1915. }
  1916. var name = _.getName(constructor);
  1917. if (name === null) {
  1918. name = 'an unnamed constructor';
  1919. }
  1920. this.assert(
  1921. isInstanceOf
  1922. , 'expected #{this} to be an instance of ' + name
  1923. , 'expected #{this} to not be an instance of ' + name
  1924. );
  1925. };
  1926. Assertion.addMethod('instanceof', assertInstanceOf);
  1927. Assertion.addMethod('instanceOf', assertInstanceOf);
  1928. /**
  1929. * ### .property(name[, val[, msg]])
  1930. *
  1931. * Asserts that the target has a property with the given key `name`.
  1932. *
  1933. * expect({a: 1}).to.have.property('a');
  1934. *
  1935. * When `val` is provided, `.property` also asserts that the property's value
  1936. * is equal to the given `val`.
  1937. *
  1938. * expect({a: 1}).to.have.property('a', 1);
  1939. *
  1940. * By default, strict (`===`) equality is used. Add `.deep` earlier in the
  1941. * chain to use deep equality instead. See the `deep-eql` project page for
  1942. * info on the deep equality algorithm: https://github.com/chaijs/deep-eql.
  1943. *
  1944. * // Target object deeply (but not strictly) has property `x: {a: 1}`
  1945. * expect({x: {a: 1}}).to.have.deep.property('x', {a: 1});
  1946. * expect({x: {a: 1}}).to.not.have.property('x', {a: 1});
  1947. *
  1948. * The target's enumerable and non-enumerable properties are always included
  1949. * in the search. By default, both own and inherited properties are included.
  1950. * Add `.own` earlier in the chain to exclude inherited properties from the
  1951. * search.
  1952. *
  1953. * Object.prototype.b = 2;
  1954. *
  1955. * expect({a: 1}).to.have.own.property('a');
  1956. * expect({a: 1}).to.have.own.property('a', 1);
  1957. * expect({a: 1}).to.have.property('b');
  1958. * expect({a: 1}).to.not.have.own.property('b');
  1959. *
  1960. * `.deep` and `.own` can be combined.
  1961. *
  1962. * expect({x: {a: 1}}).to.have.deep.own.property('x', {a: 1});
  1963. *
  1964. * Add `.nested` earlier in the chain to enable dot- and bracket-notation when
  1965. * referencing nested properties.
  1966. *
  1967. * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]');
  1968. * expect({a: {b: ['x', 'y']}}).to.have.nested.property('a.b[1]', 'y');
  1969. *
  1970. * If `.` or `[]` are part of an actual property name, they can be escaped by
  1971. * adding two backslashes before them.
  1972. *
  1973. * expect({'.a': {'[b]': 'x'}}).to.have.nested.property('\\.a.\\[b\\]');
  1974. *
  1975. * `.deep` and `.nested` can be combined.
  1976. *
  1977. * expect({a: {b: [{c: 3}]}})
  1978. * .to.have.deep.nested.property('a.b[0]', {c: 3});
  1979. *
  1980. * `.own` and `.nested` cannot be combined.
  1981. *
  1982. * Add `.not` earlier in the chain to negate `.property`.
  1983. *
  1984. * expect({a: 1}).to.not.have.property('b');
  1985. *
  1986. * However, it's dangerous to negate `.property` when providing `val`. The
  1987. * problem is that it creates uncertain expectations by asserting that the
  1988. * target either doesn't have a property with the given key `name`, or that it
  1989. * does have a property with the given key `name` but its value isn't equal to
  1990. * the given `val`. It's often best to identify the exact output that's
  1991. * expected, and then write an assertion that only accepts that exact output.
  1992. *
  1993. * When the target isn't expected to have a property with the given key
  1994. * `name`, it's often best to assert exactly that.
  1995. *
  1996. * expect({b: 2}).to.not.have.property('a'); // Recommended
  1997. * expect({b: 2}).to.not.have.property('a', 1); // Not recommended
  1998. *
  1999. * When the target is expected to have a property with the given key `name`,
  2000. * it's often best to assert that the property has its expected value, rather
  2001. * than asserting that it doesn't have one of many unexpected values.
  2002. *
  2003. * expect({a: 3}).to.have.property('a', 3); // Recommended
  2004. * expect({a: 3}).to.not.have.property('a', 1); // Not recommended
  2005. *
  2006. * `.property` changes the target of any assertions that follow in the chain
  2007. * to be the value of the property from the original target object.
  2008. *
  2009. * expect({a: 1}).to.have.property('a').that.is.a('number');
  2010. *
  2011. * `.property` accepts an optional `msg` argument which is a custom error
  2012. * message to show when the assertion fails. The message can also be given as
  2013. * the second argument to `expect`. When not providing `val`, only use the
  2014. * second form.
  2015. *
  2016. * // Recommended
  2017. * expect({a: 1}).to.have.property('a', 2, 'nooo why fail??');
  2018. * expect({a: 1}, 'nooo why fail??').to.have.property('a', 2);
  2019. * expect({a: 1}, 'nooo why fail??').to.have.property('b');
  2020. *
  2021. * // Not recommended
  2022. * expect({a: 1}).to.have.property('b', undefined, 'nooo why fail??');
  2023. *
  2024. * The above assertion isn't the same thing as not providing `val`. Instead,
  2025. * it's asserting that the target object has a `b` property that's equal to
  2026. * `undefined`.
  2027. *
  2028. * The assertions `.ownProperty` and `.haveOwnProperty` can be used
  2029. * interchangeably with `.own.property`.
  2030. *
  2031. * @name property
  2032. * @param {String} name
  2033. * @param {Mixed} val (optional)
  2034. * @param {String} msg _optional_
  2035. * @returns value of property for chaining
  2036. * @namespace BDD
  2037. * @api public
  2038. */
  2039. function assertProperty (name, val, msg) {
  2040. if (msg) flag(this, 'message', msg);
  2041. var isNested = flag(this, 'nested')
  2042. , isOwn = flag(this, 'own')
  2043. , flagMsg = flag(this, 'message')
  2044. , obj = flag(this, 'object')
  2045. , ssfi = flag(this, 'ssfi')
  2046. , nameType = typeof name;
  2047. flagMsg = flagMsg ? flagMsg + ': ' : '';
  2048. if (isNested) {
  2049. if (nameType !== 'string') {
  2050. throw new AssertionError(
  2051. flagMsg + 'the argument to property must be a string when using nested syntax',
  2052. undefined,
  2053. ssfi
  2054. );
  2055. }
  2056. } else {
  2057. if (nameType !== 'string' && nameType !== 'number' && nameType !== 'symbol') {
  2058. throw new AssertionError(
  2059. flagMsg + 'the argument to property must be a string, number, or symbol',
  2060. undefined,
  2061. ssfi
  2062. );
  2063. }
  2064. }
  2065. if (isNested && isOwn) {
  2066. throw new AssertionError(
  2067. flagMsg + 'The "nested" and "own" flags cannot be combined.',
  2068. undefined,
  2069. ssfi
  2070. );
  2071. }
  2072. if (obj === null || obj === undefined) {
  2073. throw new AssertionError(
  2074. flagMsg + 'Target cannot be null or undefined.',
  2075. undefined,
  2076. ssfi
  2077. );
  2078. }
  2079. var isDeep = flag(this, 'deep')
  2080. , negate = flag(this, 'negate')
  2081. , pathInfo = isNested ? _.getPathInfo(obj, name) : null
  2082. , value = isNested ? pathInfo.value : obj[name]
  2083. , isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2;;
  2084. var descriptor = '';
  2085. if (isDeep) descriptor += 'deep ';
  2086. if (isOwn) descriptor += 'own ';
  2087. if (isNested) descriptor += 'nested ';
  2088. descriptor += 'property ';
  2089. var hasProperty;
  2090. if (isOwn) hasProperty = Object.prototype.hasOwnProperty.call(obj, name);
  2091. else if (isNested) hasProperty = pathInfo.exists;
  2092. else hasProperty = _.hasProperty(obj, name);
  2093. // When performing a negated assertion for both name and val, merely having
  2094. // a property with the given name isn't enough to cause the assertion to
  2095. // fail. It must both have a property with the given name, and the value of
  2096. // that property must equal the given val. Therefore, skip this assertion in
  2097. // favor of the next.
  2098. if (!negate || arguments.length === 1) {
  2099. this.assert(
  2100. hasProperty
  2101. , 'expected #{this} to have ' + descriptor + _.inspect(name)
  2102. , 'expected #{this} to not have ' + descriptor + _.inspect(name));
  2103. }
  2104. if (arguments.length > 1) {
  2105. this.assert(
  2106. hasProperty && isEql(val, value)
  2107. , 'expected #{this} to have ' + descriptor + _.inspect(name) + ' of #{exp}, but got #{act}'
  2108. , 'expected #{this} to not have ' + descriptor + _.inspect(name) + ' of #{act}'
  2109. , val
  2110. , value
  2111. );
  2112. }
  2113. flag(this, 'object', value);
  2114. }
  2115. Assertion.addMethod('property', assertProperty);
  2116. function assertOwnProperty (name, value, msg) {
  2117. flag(this, 'own', true);
  2118. assertProperty.apply(this, arguments);
  2119. }
  2120. Assertion.addMethod('ownProperty', assertOwnProperty);
  2121. Assertion.addMethod('haveOwnProperty', assertOwnProperty);
  2122. /**
  2123. * ### .ownPropertyDescriptor(name[, descriptor[, msg]])
  2124. *
  2125. * Asserts that the target has its own property descriptor with the given key
  2126. * `name`. Enumerable and non-enumerable properties are included in the
  2127. * search.
  2128. *
  2129. * expect({a: 1}).to.have.ownPropertyDescriptor('a');
  2130. *
  2131. * When `descriptor` is provided, `.ownPropertyDescriptor` also asserts that
  2132. * the property's descriptor is deeply equal to the given `descriptor`. See
  2133. * the `deep-eql` project page for info on the deep equality algorithm:
  2134. * https://github.com/chaijs/deep-eql.
  2135. *
  2136. * expect({a: 1}).to.have.ownPropertyDescriptor('a', {
  2137. * configurable: true,
  2138. * enumerable: true,
  2139. * writable: true,
  2140. * value: 1,
  2141. * });
  2142. *
  2143. * Add `.not` earlier in the chain to negate `.ownPropertyDescriptor`.
  2144. *
  2145. * expect({a: 1}).to.not.have.ownPropertyDescriptor('b');
  2146. *
  2147. * However, it's dangerous to negate `.ownPropertyDescriptor` when providing
  2148. * a `descriptor`. The problem is that it creates uncertain expectations by
  2149. * asserting that the target either doesn't have a property descriptor with
  2150. * the given key `name`, or that it does have a property descriptor with the
  2151. * given key `name` but it’s not deeply equal to the given `descriptor`. It's
  2152. * often best to identify the exact output that's expected, and then write an
  2153. * assertion that only accepts that exact output.
  2154. *
  2155. * When the target isn't expected to have a property descriptor with the given
  2156. * key `name`, it's often best to assert exactly that.
  2157. *
  2158. * // Recommended
  2159. * expect({b: 2}).to.not.have.ownPropertyDescriptor('a');
  2160. *
  2161. * // Not recommended
  2162. * expect({b: 2}).to.not.have.ownPropertyDescriptor('a', {
  2163. * configurable: true,
  2164. * enumerable: true,
  2165. * writable: true,
  2166. * value: 1,
  2167. * });
  2168. *
  2169. * When the target is expected to have a property descriptor with the given
  2170. * key `name`, it's often best to assert that the property has its expected
  2171. * descriptor, rather than asserting that it doesn't have one of many
  2172. * unexpected descriptors.
  2173. *
  2174. * // Recommended
  2175. * expect({a: 3}).to.have.ownPropertyDescriptor('a', {
  2176. * configurable: true,
  2177. * enumerable: true,
  2178. * writable: true,
  2179. * value: 3,
  2180. * });
  2181. *
  2182. * // Not recommended
  2183. * expect({a: 3}).to.not.have.ownPropertyDescriptor('a', {
  2184. * configurable: true,
  2185. * enumerable: true,
  2186. * writable: true,
  2187. * value: 1,
  2188. * });
  2189. *
  2190. * `.ownPropertyDescriptor` changes the target of any assertions that follow
  2191. * in the chain to be the value of the property descriptor from the original
  2192. * target object.
  2193. *
  2194. * expect({a: 1}).to.have.ownPropertyDescriptor('a')
  2195. * .that.has.property('enumerable', true);
  2196. *
  2197. * `.ownPropertyDescriptor` accepts an optional `msg` argument which is a
  2198. * custom error message to show when the assertion fails. The message can also
  2199. * be given as the second argument to `expect`. When not providing
  2200. * `descriptor`, only use the second form.
  2201. *
  2202. * // Recommended
  2203. * expect({a: 1}).to.have.ownPropertyDescriptor('a', {
  2204. * configurable: true,
  2205. * enumerable: true,
  2206. * writable: true,
  2207. * value: 2,
  2208. * }, 'nooo why fail??');
  2209. *
  2210. * // Recommended
  2211. * expect({a: 1}, 'nooo why fail??').to.have.ownPropertyDescriptor('a', {
  2212. * configurable: true,
  2213. * enumerable: true,
  2214. * writable: true,
  2215. * value: 2,
  2216. * });
  2217. *
  2218. * // Recommended
  2219. * expect({a: 1}, 'nooo why fail??').to.have.ownPropertyDescriptor('b');
  2220. *
  2221. * // Not recommended
  2222. * expect({a: 1})
  2223. * .to.have.ownPropertyDescriptor('b', undefined, 'nooo why fail??');
  2224. *
  2225. * The above assertion isn't the same thing as not providing `descriptor`.
  2226. * Instead, it's asserting that the target object has a `b` property
  2227. * descriptor that's deeply equal to `undefined`.
  2228. *
  2229. * The alias `.haveOwnPropertyDescriptor` can be used interchangeably with
  2230. * `.ownPropertyDescriptor`.
  2231. *
  2232. * @name ownPropertyDescriptor
  2233. * @alias haveOwnPropertyDescriptor
  2234. * @param {String} name
  2235. * @param {Object} descriptor _optional_
  2236. * @param {String} msg _optional_
  2237. * @namespace BDD
  2238. * @api public
  2239. */
  2240. function assertOwnPropertyDescriptor (name, descriptor, msg) {
  2241. if (typeof descriptor === 'string') {
  2242. msg = descriptor;
  2243. descriptor = null;
  2244. }
  2245. if (msg) flag(this, 'message', msg);
  2246. var obj = flag(this, 'object');
  2247. var actualDescriptor = Object.getOwnPropertyDescriptor(Object(obj), name);
  2248. var eql = flag(this, 'eql');
  2249. if (actualDescriptor && descriptor) {
  2250. this.assert(
  2251. eql(descriptor, actualDescriptor)
  2252. , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to match ' + _.inspect(descriptor) + ', got ' + _.inspect(actualDescriptor)
  2253. , 'expected the own property descriptor for ' + _.inspect(name) + ' on #{this} to not match ' + _.inspect(descriptor)
  2254. , descriptor
  2255. , actualDescriptor
  2256. , true
  2257. );
  2258. } else {
  2259. this.assert(
  2260. actualDescriptor
  2261. , 'expected #{this} to have an own property descriptor for ' + _.inspect(name)
  2262. , 'expected #{this} to not have an own property descriptor for ' + _.inspect(name)
  2263. );
  2264. }
  2265. flag(this, 'object', actualDescriptor);
  2266. }
  2267. Assertion.addMethod('ownPropertyDescriptor', assertOwnPropertyDescriptor);
  2268. Assertion.addMethod('haveOwnPropertyDescriptor', assertOwnPropertyDescriptor);
  2269. /**
  2270. * ### .lengthOf(n[, msg])
  2271. *
  2272. * Asserts that the target's `length` or `size` is equal to the given number
  2273. * `n`.
  2274. *
  2275. * expect([1, 2, 3]).to.have.lengthOf(3);
  2276. * expect('foo').to.have.lengthOf(3);
  2277. * expect(new Set([1, 2, 3])).to.have.lengthOf(3);
  2278. * expect(new Map([['a', 1], ['b', 2], ['c', 3]])).to.have.lengthOf(3);
  2279. *
  2280. * Add `.not` earlier in the chain to negate `.lengthOf`. However, it's often
  2281. * best to assert that the target's `length` property is equal to its expected
  2282. * value, rather than not equal to one of many unexpected values.
  2283. *
  2284. * expect('foo').to.have.lengthOf(3); // Recommended
  2285. * expect('foo').to.not.have.lengthOf(4); // Not recommended
  2286. *
  2287. * `.lengthOf` accepts an optional `msg` argument which is a custom error
  2288. * message to show when the assertion fails. The message can also be given as
  2289. * the second argument to `expect`.
  2290. *
  2291. * expect([1, 2, 3]).to.have.lengthOf(2, 'nooo why fail??');
  2292. * expect([1, 2, 3], 'nooo why fail??').to.have.lengthOf(2);
  2293. *
  2294. * `.lengthOf` can also be used as a language chain, causing all `.above`,
  2295. * `.below`, `.least`, `.most`, and `.within` assertions that follow in the
  2296. * chain to use the target's `length` property as the target. However, it's
  2297. * often best to assert that the target's `length` property is equal to its
  2298. * expected length, rather than asserting that its `length` property falls
  2299. * within some range of values.
  2300. *
  2301. * // Recommended
  2302. * expect([1, 2, 3]).to.have.lengthOf(3);
  2303. *
  2304. * // Not recommended
  2305. * expect([1, 2, 3]).to.have.lengthOf.above(2);
  2306. * expect([1, 2, 3]).to.have.lengthOf.below(4);
  2307. * expect([1, 2, 3]).to.have.lengthOf.at.least(3);
  2308. * expect([1, 2, 3]).to.have.lengthOf.at.most(3);
  2309. * expect([1, 2, 3]).to.have.lengthOf.within(2,4);
  2310. *
  2311. * Due to a compatibility issue, the alias `.length` can't be chained directly
  2312. * off of an uninvoked method such as `.a`. Therefore, `.length` can't be used
  2313. * interchangeably with `.lengthOf` in every situation. It's recommended to
  2314. * always use `.lengthOf` instead of `.length`.
  2315. *
  2316. * expect([1, 2, 3]).to.have.a.length(3); // incompatible; throws error
  2317. * expect([1, 2, 3]).to.have.a.lengthOf(3); // passes as expected
  2318. *
  2319. * @name lengthOf
  2320. * @alias length
  2321. * @param {Number} n
  2322. * @param {String} msg _optional_
  2323. * @namespace BDD
  2324. * @api public
  2325. */
  2326. function assertLengthChain () {
  2327. flag(this, 'doLength', true);
  2328. }
  2329. function assertLength (n, msg) {
  2330. if (msg) flag(this, 'message', msg);
  2331. var obj = flag(this, 'object')
  2332. , objType = _.type(obj).toLowerCase()
  2333. , flagMsg = flag(this, 'message')
  2334. , ssfi = flag(this, 'ssfi')
  2335. , descriptor = 'length'
  2336. , itemsCount;
  2337. switch (objType) {
  2338. case 'map':
  2339. case 'set':
  2340. descriptor = 'size';
  2341. itemsCount = obj.size;
  2342. break;
  2343. default:
  2344. new Assertion(obj, flagMsg, ssfi, true).to.have.property('length');
  2345. itemsCount = obj.length;
  2346. }
  2347. this.assert(
  2348. itemsCount == n
  2349. , 'expected #{this} to have a ' + descriptor + ' of #{exp} but got #{act}'
  2350. , 'expected #{this} to not have a ' + descriptor + ' of #{act}'
  2351. , n
  2352. , itemsCount
  2353. );
  2354. }
  2355. Assertion.addChainableMethod('length', assertLength, assertLengthChain);
  2356. Assertion.addChainableMethod('lengthOf', assertLength, assertLengthChain);
  2357. /**
  2358. * ### .match(re[, msg])
  2359. *
  2360. * Asserts that the target matches the given regular expression `re`.
  2361. *
  2362. * expect('foobar').to.match(/^foo/);
  2363. *
  2364. * Add `.not` earlier in the chain to negate `.match`.
  2365. *
  2366. * expect('foobar').to.not.match(/taco/);
  2367. *
  2368. * `.match` accepts an optional `msg` argument which is a custom error message
  2369. * to show when the assertion fails. The message can also be given as the
  2370. * second argument to `expect`.
  2371. *
  2372. * expect('foobar').to.match(/taco/, 'nooo why fail??');
  2373. * expect('foobar', 'nooo why fail??').to.match(/taco/);
  2374. *
  2375. * The alias `.matches` can be used interchangeably with `.match`.
  2376. *
  2377. * @name match
  2378. * @alias matches
  2379. * @param {RegExp} re
  2380. * @param {String} msg _optional_
  2381. * @namespace BDD
  2382. * @api public
  2383. */
  2384. function assertMatch(re, msg) {
  2385. if (msg) flag(this, 'message', msg);
  2386. var obj = flag(this, 'object');
  2387. this.assert(
  2388. re.exec(obj)
  2389. , 'expected #{this} to match ' + re
  2390. , 'expected #{this} not to match ' + re
  2391. );
  2392. }
  2393. Assertion.addMethod('match', assertMatch);
  2394. Assertion.addMethod('matches', assertMatch);
  2395. /**
  2396. * ### .string(str[, msg])
  2397. *
  2398. * Asserts that the target string contains the given substring `str`.
  2399. *
  2400. * expect('foobar').to.have.string('bar');
  2401. *
  2402. * Add `.not` earlier in the chain to negate `.string`.
  2403. *
  2404. * expect('foobar').to.not.have.string('taco');
  2405. *
  2406. * `.string` accepts an optional `msg` argument which is a custom error
  2407. * message to show when the assertion fails. The message can also be given as
  2408. * the second argument to `expect`.
  2409. *
  2410. * expect('foobar').to.have.string('taco', 'nooo why fail??');
  2411. * expect('foobar', 'nooo why fail??').to.have.string('taco');
  2412. *
  2413. * @name string
  2414. * @param {String} str
  2415. * @param {String} msg _optional_
  2416. * @namespace BDD
  2417. * @api public
  2418. */
  2419. Assertion.addMethod('string', function (str, msg) {
  2420. if (msg) flag(this, 'message', msg);
  2421. var obj = flag(this, 'object')
  2422. , flagMsg = flag(this, 'message')
  2423. , ssfi = flag(this, 'ssfi');
  2424. new Assertion(obj, flagMsg, ssfi, true).is.a('string');
  2425. this.assert(
  2426. ~obj.indexOf(str)
  2427. , 'expected #{this} to contain ' + _.inspect(str)
  2428. , 'expected #{this} to not contain ' + _.inspect(str)
  2429. );
  2430. });
  2431. /**
  2432. * ### .keys(key1[, key2[, ...]])
  2433. *
  2434. * Asserts that the target object, array, map, or set has the given keys. Only
  2435. * the target's own inherited properties are included in the search.
  2436. *
  2437. * When the target is an object or array, keys can be provided as one or more
  2438. * string arguments, a single array argument, or a single object argument. In
  2439. * the latter case, only the keys in the given object matter; the values are
  2440. * ignored.
  2441. *
  2442. * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
  2443. * expect(['x', 'y']).to.have.all.keys(0, 1);
  2444. *
  2445. * expect({a: 1, b: 2}).to.have.all.keys(['a', 'b']);
  2446. * expect(['x', 'y']).to.have.all.keys([0, 1]);
  2447. *
  2448. * expect({a: 1, b: 2}).to.have.all.keys({a: 4, b: 5}); // ignore 4 and 5
  2449. * expect(['x', 'y']).to.have.all.keys({0: 4, 1: 5}); // ignore 4 and 5
  2450. *
  2451. * When the target is a map or set, each key must be provided as a separate
  2452. * argument.
  2453. *
  2454. * expect(new Map([['a', 1], ['b', 2]])).to.have.all.keys('a', 'b');
  2455. * expect(new Set(['a', 'b'])).to.have.all.keys('a', 'b');
  2456. *
  2457. * Because `.keys` does different things based on the target's type, it's
  2458. * important to check the target's type before using `.keys`. See the `.a` doc
  2459. * for info on testing a target's type.
  2460. *
  2461. * expect({a: 1, b: 2}).to.be.an('object').that.has.all.keys('a', 'b');
  2462. *
  2463. * By default, strict (`===`) equality is used to compare keys of maps and
  2464. * sets. Add `.deep` earlier in the chain to use deep equality instead. See
  2465. * the `deep-eql` project page for info on the deep equality algorithm:
  2466. * https://github.com/chaijs/deep-eql.
  2467. *
  2468. * // Target set deeply (but not strictly) has key `{a: 1}`
  2469. * expect(new Set([{a: 1}])).to.have.all.deep.keys([{a: 1}]);
  2470. * expect(new Set([{a: 1}])).to.not.have.all.keys([{a: 1}]);
  2471. *
  2472. * By default, the target must have all of the given keys and no more. Add
  2473. * `.any` earlier in the chain to only require that the target have at least
  2474. * one of the given keys. Also, add `.not` earlier in the chain to negate
  2475. * `.keys`. It's often best to add `.any` when negating `.keys`, and to use
  2476. * `.all` when asserting `.keys` without negation.
  2477. *
  2478. * When negating `.keys`, `.any` is preferred because `.not.any.keys` asserts
  2479. * exactly what's expected of the output, whereas `.not.all.keys` creates
  2480. * uncertain expectations.
  2481. *
  2482. * // Recommended; asserts that target doesn't have any of the given keys
  2483. * expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');
  2484. *
  2485. * // Not recommended; asserts that target doesn't have all of the given
  2486. * // keys but may or may not have some of them
  2487. * expect({a: 1, b: 2}).to.not.have.all.keys('c', 'd');
  2488. *
  2489. * When asserting `.keys` without negation, `.all` is preferred because
  2490. * `.all.keys` asserts exactly what's expected of the output, whereas
  2491. * `.any.keys` creates uncertain expectations.
  2492. *
  2493. * // Recommended; asserts that target has all the given keys
  2494. * expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
  2495. *
  2496. * // Not recommended; asserts that target has at least one of the given
  2497. * // keys but may or may not have more of them
  2498. * expect({a: 1, b: 2}).to.have.any.keys('a', 'b');
  2499. *
  2500. * Note that `.all` is used by default when neither `.all` nor `.any` appear
  2501. * earlier in the chain. However, it's often best to add `.all` anyway because
  2502. * it improves readability.
  2503. *
  2504. * // Both assertions are identical
  2505. * expect({a: 1, b: 2}).to.have.all.keys('a', 'b'); // Recommended
  2506. * expect({a: 1, b: 2}).to.have.keys('a', 'b'); // Not recommended
  2507. *
  2508. * Add `.include` earlier in the chain to require that the target's keys be a
  2509. * superset of the expected keys, rather than identical sets.
  2510. *
  2511. * // Target object's keys are a superset of ['a', 'b'] but not identical
  2512. * expect({a: 1, b: 2, c: 3}).to.include.all.keys('a', 'b');
  2513. * expect({a: 1, b: 2, c: 3}).to.not.have.all.keys('a', 'b');
  2514. *
  2515. * However, if `.any` and `.include` are combined, only the `.any` takes
  2516. * effect. The `.include` is ignored in this case.
  2517. *
  2518. * // Both assertions are identical
  2519. * expect({a: 1}).to.have.any.keys('a', 'b');
  2520. * expect({a: 1}).to.include.any.keys('a', 'b');
  2521. *
  2522. * A custom error message can be given as the second argument to `expect`.
  2523. *
  2524. * expect({a: 1}, 'nooo why fail??').to.have.key('b');
  2525. *
  2526. * The alias `.key` can be used interchangeably with `.keys`.
  2527. *
  2528. * @name keys
  2529. * @alias key
  2530. * @param {...String|Array|Object} keys
  2531. * @namespace BDD
  2532. * @api public
  2533. */
  2534. function assertKeys (keys) {
  2535. var obj = flag(this, 'object')
  2536. , objType = _.type(obj)
  2537. , keysType = _.type(keys)
  2538. , ssfi = flag(this, 'ssfi')
  2539. , isDeep = flag(this, 'deep')
  2540. , str
  2541. , deepStr = ''
  2542. , actual
  2543. , ok = true
  2544. , flagMsg = flag(this, 'message');
  2545. flagMsg = flagMsg ? flagMsg + ': ' : '';
  2546. 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';
  2547. if (objType === 'Map' || objType === 'Set') {
  2548. deepStr = isDeep ? 'deeply ' : '';
  2549. actual = [];
  2550. // Map and Set '.keys' aren't supported in IE 11. Therefore, use .forEach.
  2551. obj.forEach(function (val, key) { actual.push(key) });
  2552. if (keysType !== 'Array') {
  2553. keys = Array.prototype.slice.call(arguments);
  2554. }
  2555. } else {
  2556. actual = _.getOwnEnumerableProperties(obj);
  2557. switch (keysType) {
  2558. case 'Array':
  2559. if (arguments.length > 1) {
  2560. throw new AssertionError(mixedArgsMsg, undefined, ssfi);
  2561. }
  2562. break;
  2563. case 'Object':
  2564. if (arguments.length > 1) {
  2565. throw new AssertionError(mixedArgsMsg, undefined, ssfi);
  2566. }
  2567. keys = Object.keys(keys);
  2568. break;
  2569. default:
  2570. keys = Array.prototype.slice.call(arguments);
  2571. }
  2572. // Only stringify non-Symbols because Symbols would become "Symbol()"
  2573. keys = keys.map(function (val) {
  2574. return typeof val === 'symbol' ? val : String(val);
  2575. });
  2576. }
  2577. if (!keys.length) {
  2578. throw new AssertionError(flagMsg + 'keys required', undefined, ssfi);
  2579. }
  2580. var len = keys.length
  2581. , any = flag(this, 'any')
  2582. , all = flag(this, 'all')
  2583. , expected = keys
  2584. , isEql = isDeep ? flag(this, 'eql') : (val1, val2) => val1 === val2;
  2585. if (!any && !all) {
  2586. all = true;
  2587. }
  2588. // Has any
  2589. if (any) {
  2590. ok = expected.some(function(expectedKey) {
  2591. return actual.some(function(actualKey) {
  2592. return isEql(expectedKey, actualKey);
  2593. });
  2594. });
  2595. }
  2596. // Has all
  2597. if (all) {
  2598. ok = expected.every(function(expectedKey) {
  2599. return actual.some(function(actualKey) {
  2600. return isEql(expectedKey, actualKey);
  2601. });
  2602. });
  2603. if (!flag(this, 'contains')) {
  2604. ok = ok && keys.length == actual.length;
  2605. }
  2606. }
  2607. // Key string
  2608. if (len > 1) {
  2609. keys = keys.map(function(key) {
  2610. return _.inspect(key);
  2611. });
  2612. var last = keys.pop();
  2613. if (all) {
  2614. str = keys.join(', ') + ', and ' + last;
  2615. }
  2616. if (any) {
  2617. str = keys.join(', ') + ', or ' + last;
  2618. }
  2619. } else {
  2620. str = _.inspect(keys[0]);
  2621. }
  2622. // Form
  2623. str = (len > 1 ? 'keys ' : 'key ') + str;
  2624. // Have / include
  2625. str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
  2626. // Assertion
  2627. this.assert(
  2628. ok
  2629. , 'expected #{this} to ' + deepStr + str
  2630. , 'expected #{this} to not ' + deepStr + str
  2631. , expected.slice(0).sort(_.compareByInspect)
  2632. , actual.sort(_.compareByInspect)
  2633. , true
  2634. );
  2635. }
  2636. Assertion.addMethod('keys', assertKeys);
  2637. Assertion.addMethod('key', assertKeys);
  2638. /**
  2639. * ### .throw([errorLike], [errMsgMatcher], [msg])
  2640. *
  2641. * When no arguments are provided, `.throw` invokes the target function and
  2642. * asserts that an error is thrown.
  2643. *
  2644. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2645. *
  2646. * expect(badFn).to.throw();
  2647. *
  2648. * When one argument is provided, and it's an error constructor, `.throw`
  2649. * invokes the target function and asserts that an error is thrown that's an
  2650. * instance of that error constructor.
  2651. *
  2652. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2653. *
  2654. * expect(badFn).to.throw(TypeError);
  2655. *
  2656. * When one argument is provided, and it's an error instance, `.throw` invokes
  2657. * the target function and asserts that an error is thrown that's strictly
  2658. * (`===`) equal to that error instance.
  2659. *
  2660. * var err = new TypeError('Illegal salmon!');
  2661. * var badFn = function () { throw err; };
  2662. *
  2663. * expect(badFn).to.throw(err);
  2664. *
  2665. * When one argument is provided, and it's a string, `.throw` invokes the
  2666. * target function and asserts that an error is thrown with a message that
  2667. * contains that string.
  2668. *
  2669. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2670. *
  2671. * expect(badFn).to.throw('salmon');
  2672. *
  2673. * When one argument is provided, and it's a regular expression, `.throw`
  2674. * invokes the target function and asserts that an error is thrown with a
  2675. * message that matches that regular expression.
  2676. *
  2677. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2678. *
  2679. * expect(badFn).to.throw(/salmon/);
  2680. *
  2681. * When two arguments are provided, and the first is an error instance or
  2682. * constructor, and the second is a string or regular expression, `.throw`
  2683. * invokes the function and asserts that an error is thrown that fulfills both
  2684. * conditions as described above.
  2685. *
  2686. * var err = new TypeError('Illegal salmon!');
  2687. * var badFn = function () { throw err; };
  2688. *
  2689. * expect(badFn).to.throw(TypeError, 'salmon');
  2690. * expect(badFn).to.throw(TypeError, /salmon/);
  2691. * expect(badFn).to.throw(err, 'salmon');
  2692. * expect(badFn).to.throw(err, /salmon/);
  2693. *
  2694. * Add `.not` earlier in the chain to negate `.throw`.
  2695. *
  2696. * var goodFn = function () {};
  2697. *
  2698. * expect(goodFn).to.not.throw();
  2699. *
  2700. * However, it's dangerous to negate `.throw` when providing any arguments.
  2701. * The problem is that it creates uncertain expectations by asserting that the
  2702. * target either doesn't throw an error, or that it throws an error but of a
  2703. * different type than the given type, or that it throws an error of the given
  2704. * type but with a message that doesn't include the given string. It's often
  2705. * best to identify the exact output that's expected, and then write an
  2706. * assertion that only accepts that exact output.
  2707. *
  2708. * When the target isn't expected to throw an error, it's often best to assert
  2709. * exactly that.
  2710. *
  2711. * var goodFn = function () {};
  2712. *
  2713. * expect(goodFn).to.not.throw(); // Recommended
  2714. * expect(goodFn).to.not.throw(ReferenceError, 'x'); // Not recommended
  2715. *
  2716. * When the target is expected to throw an error, it's often best to assert
  2717. * that the error is of its expected type, and has a message that includes an
  2718. * expected string, rather than asserting that it doesn't have one of many
  2719. * unexpected types, and doesn't have a message that includes some string.
  2720. *
  2721. * var badFn = function () { throw new TypeError('Illegal salmon!'); };
  2722. *
  2723. * expect(badFn).to.throw(TypeError, 'salmon'); // Recommended
  2724. * expect(badFn).to.not.throw(ReferenceError, 'x'); // Not recommended
  2725. *
  2726. * `.throw` changes the target of any assertions that follow in the chain to
  2727. * be the error object that's thrown.
  2728. *
  2729. * var err = new TypeError('Illegal salmon!');
  2730. * err.code = 42;
  2731. * var badFn = function () { throw err; };
  2732. *
  2733. * expect(badFn).to.throw(TypeError).with.property('code', 42);
  2734. *
  2735. * `.throw` accepts an optional `msg` argument which is a custom error message
  2736. * to show when the assertion fails. The message can also be given as the
  2737. * second argument to `expect`. When not providing two arguments, always use
  2738. * the second form.
  2739. *
  2740. * var goodFn = function () {};
  2741. *
  2742. * expect(goodFn).to.throw(TypeError, 'x', 'nooo why fail??');
  2743. * expect(goodFn, 'nooo why fail??').to.throw();
  2744. *
  2745. * Due to limitations in ES5, `.throw` may not always work as expected when
  2746. * using a transpiler such as Babel or TypeScript. In particular, it may
  2747. * produce unexpected results when subclassing the built-in `Error` object and
  2748. * then passing the subclassed constructor to `.throw`. See your transpiler's
  2749. * docs for details:
  2750. *
  2751. * - ([Babel](https://babeljs.io/docs/usage/caveats/#classes))
  2752. * - ([TypeScript](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work))
  2753. *
  2754. * Beware of some common mistakes when using the `throw` assertion. One common
  2755. * mistake is to accidentally invoke the function yourself instead of letting
  2756. * the `throw` assertion invoke the function for you. For example, when
  2757. * testing if a function named `fn` throws, provide `fn` instead of `fn()` as
  2758. * the target for the assertion.
  2759. *
  2760. * expect(fn).to.throw(); // Good! Tests `fn` as desired
  2761. * expect(fn()).to.throw(); // Bad! Tests result of `fn()`, not `fn`
  2762. *
  2763. * If you need to assert that your function `fn` throws when passed certain
  2764. * arguments, then wrap a call to `fn` inside of another function.
  2765. *
  2766. * expect(function () { fn(42); }).to.throw(); // Function expression
  2767. * expect(() => fn(42)).to.throw(); // ES6 arrow function
  2768. *
  2769. * Another common mistake is to provide an object method (or any stand-alone
  2770. * function that relies on `this`) as the target of the assertion. Doing so is
  2771. * problematic because the `this` context will be lost when the function is
  2772. * invoked by `.throw`; there's no way for it to know what `this` is supposed
  2773. * to be. There are two ways around this problem. One solution is to wrap the
  2774. * method or function call inside of another function. Another solution is to
  2775. * use `bind`.
  2776. *
  2777. * expect(function () { cat.meow(); }).to.throw(); // Function expression
  2778. * expect(() => cat.meow()).to.throw(); // ES6 arrow function
  2779. * expect(cat.meow.bind(cat)).to.throw(); // Bind
  2780. *
  2781. * Finally, it's worth mentioning that it's a best practice in JavaScript to
  2782. * only throw `Error` and derivatives of `Error` such as `ReferenceError`,
  2783. * `TypeError`, and user-defined objects that extend `Error`. No other type of
  2784. * value will generate a stack trace when initialized. With that said, the
  2785. * `throw` assertion does technically support any type of value being thrown,
  2786. * not just `Error` and its derivatives.
  2787. *
  2788. * The aliases `.throws` and `.Throw` can be used interchangeably with
  2789. * `.throw`.
  2790. *
  2791. * @name throw
  2792. * @alias throws
  2793. * @alias Throw
  2794. * @param {Error|ErrorConstructor} errorLike
  2795. * @param {String|RegExp} errMsgMatcher error message
  2796. * @param {String} msg _optional_
  2797. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  2798. * @returns error for chaining (null if no error)
  2799. * @namespace BDD
  2800. * @api public
  2801. */
  2802. function assertThrows (errorLike, errMsgMatcher, msg) {
  2803. if (msg) flag(this, 'message', msg);
  2804. var obj = flag(this, 'object')
  2805. , ssfi = flag(this, 'ssfi')
  2806. , flagMsg = flag(this, 'message')
  2807. , negate = flag(this, 'negate') || false;
  2808. new Assertion(obj, flagMsg, ssfi, true).is.a('function');
  2809. if (errorLike instanceof RegExp || typeof errorLike === 'string') {
  2810. errMsgMatcher = errorLike;
  2811. errorLike = null;
  2812. }
  2813. var caughtErr;
  2814. try {
  2815. obj();
  2816. } catch (err) {
  2817. caughtErr = err;
  2818. }
  2819. // If we have the negate flag enabled and at least one valid argument it means we do expect an error
  2820. // but we want it to match a given set of criteria
  2821. var everyArgIsUndefined = errorLike === undefined && errMsgMatcher === undefined;
  2822. // If we've got the negate flag enabled and both args, we should only fail if both aren't compatible
  2823. // See Issue #551 and PR #683@GitHub
  2824. var everyArgIsDefined = Boolean(errorLike && errMsgMatcher);
  2825. var errorLikeFail = false;
  2826. var errMsgMatcherFail = false;
  2827. // Checking if error was thrown
  2828. if (everyArgIsUndefined || !everyArgIsUndefined && !negate) {
  2829. // We need this to display results correctly according to their types
  2830. var errorLikeString = 'an error';
  2831. if (errorLike instanceof Error) {
  2832. errorLikeString = '#{exp}';
  2833. } else if (errorLike) {
  2834. errorLikeString = _.checkError.getConstructorName(errorLike);
  2835. }
  2836. this.assert(
  2837. caughtErr
  2838. , 'expected #{this} to throw ' + errorLikeString
  2839. , 'expected #{this} to not throw an error but #{act} was thrown'
  2840. , errorLike && errorLike.toString()
  2841. , (caughtErr instanceof Error ?
  2842. caughtErr.toString() : (typeof caughtErr === 'string' ? caughtErr : caughtErr &&
  2843. _.checkError.getConstructorName(caughtErr)))
  2844. );
  2845. }
  2846. if (errorLike && caughtErr) {
  2847. // We should compare instances only if `errorLike` is an instance of `Error`
  2848. if (errorLike instanceof Error) {
  2849. var isCompatibleInstance = _.checkError.compatibleInstance(caughtErr, errorLike);
  2850. if (isCompatibleInstance === negate) {
  2851. // These checks were created to ensure we won't fail too soon when we've got both args and a negate
  2852. // See Issue #551 and PR #683@GitHub
  2853. if (everyArgIsDefined && negate) {
  2854. errorLikeFail = true;
  2855. } else {
  2856. this.assert(
  2857. negate
  2858. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  2859. , 'expected #{this} to not throw #{exp}' + (caughtErr && !negate ? ' but #{act} was thrown' : '')
  2860. , errorLike.toString()
  2861. , caughtErr.toString()
  2862. );
  2863. }
  2864. }
  2865. }
  2866. var isCompatibleConstructor = _.checkError.compatibleConstructor(caughtErr, errorLike);
  2867. if (isCompatibleConstructor === negate) {
  2868. if (everyArgIsDefined && negate) {
  2869. errorLikeFail = true;
  2870. } else {
  2871. this.assert(
  2872. negate
  2873. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  2874. , 'expected #{this} to not throw #{exp}' + (caughtErr ? ' but #{act} was thrown' : '')
  2875. , (errorLike instanceof Error ? errorLike.toString() : errorLike && _.checkError.getConstructorName(errorLike))
  2876. , (caughtErr instanceof Error ? caughtErr.toString() : caughtErr && _.checkError.getConstructorName(caughtErr))
  2877. );
  2878. }
  2879. }
  2880. }
  2881. if (caughtErr && errMsgMatcher !== undefined && errMsgMatcher !== null) {
  2882. // Here we check compatible messages
  2883. var placeholder = 'including';
  2884. if (errMsgMatcher instanceof RegExp) {
  2885. placeholder = 'matching'
  2886. }
  2887. var isCompatibleMessage = _.checkError.compatibleMessage(caughtErr, errMsgMatcher);
  2888. if (isCompatibleMessage === negate) {
  2889. if (everyArgIsDefined && negate) {
  2890. errMsgMatcherFail = true;
  2891. } else {
  2892. this.assert(
  2893. negate
  2894. , 'expected #{this} to throw error ' + placeholder + ' #{exp} but got #{act}'
  2895. , 'expected #{this} to throw error not ' + placeholder + ' #{exp}'
  2896. , errMsgMatcher
  2897. , _.checkError.getMessage(caughtErr)
  2898. );
  2899. }
  2900. }
  2901. }
  2902. // If both assertions failed and both should've matched we throw an error
  2903. if (errorLikeFail && errMsgMatcherFail) {
  2904. this.assert(
  2905. negate
  2906. , 'expected #{this} to throw #{exp} but #{act} was thrown'
  2907. , 'expected #{this} to not throw #{exp}' + (caughtErr ? ' but #{act} was thrown' : '')
  2908. , (errorLike instanceof Error ? errorLike.toString() : errorLike && _.checkError.getConstructorName(errorLike))
  2909. , (caughtErr instanceof Error ? caughtErr.toString() : caughtErr && _.checkError.getConstructorName(caughtErr))
  2910. );
  2911. }
  2912. flag(this, 'object', caughtErr);
  2913. };
  2914. Assertion.addMethod('throw', assertThrows);
  2915. Assertion.addMethod('throws', assertThrows);
  2916. Assertion.addMethod('Throw', assertThrows);
  2917. /**
  2918. * ### .respondTo(method[, msg])
  2919. *
  2920. * When the target is a non-function object, `.respondTo` asserts that the
  2921. * target has a method with the given name `method`. The method can be own or
  2922. * inherited, and it can be enumerable or non-enumerable.
  2923. *
  2924. * function Cat () {}
  2925. * Cat.prototype.meow = function () {};
  2926. *
  2927. * expect(new Cat()).to.respondTo('meow');
  2928. *
  2929. * When the target is a function, `.respondTo` asserts that the target's
  2930. * `prototype` property has a method with the given name `method`. Again, the
  2931. * method can be own or inherited, and it can be enumerable or non-enumerable.
  2932. *
  2933. * function Cat () {}
  2934. * Cat.prototype.meow = function () {};
  2935. *
  2936. * expect(Cat).to.respondTo('meow');
  2937. *
  2938. * Add `.itself` earlier in the chain to force `.respondTo` to treat the
  2939. * target as a non-function object, even if it's a function. Thus, it asserts
  2940. * that the target has a method with the given name `method`, rather than
  2941. * asserting that the target's `prototype` property has a method with the
  2942. * given name `method`.
  2943. *
  2944. * function Cat () {}
  2945. * Cat.prototype.meow = function () {};
  2946. * Cat.hiss = function () {};
  2947. *
  2948. * expect(Cat).itself.to.respondTo('hiss').but.not.respondTo('meow');
  2949. *
  2950. * When not adding `.itself`, it's important to check the target's type before
  2951. * using `.respondTo`. See the `.a` doc for info on checking a target's type.
  2952. *
  2953. * function Cat () {}
  2954. * Cat.prototype.meow = function () {};
  2955. *
  2956. * expect(new Cat()).to.be.an('object').that.respondsTo('meow');
  2957. *
  2958. * Add `.not` earlier in the chain to negate `.respondTo`.
  2959. *
  2960. * function Dog () {}
  2961. * Dog.prototype.bark = function () {};
  2962. *
  2963. * expect(new Dog()).to.not.respondTo('meow');
  2964. *
  2965. * `.respondTo` accepts an optional `msg` argument which is a custom error
  2966. * message to show when the assertion fails. The message can also be given as
  2967. * the second argument to `expect`.
  2968. *
  2969. * expect({}).to.respondTo('meow', 'nooo why fail??');
  2970. * expect({}, 'nooo why fail??').to.respondTo('meow');
  2971. *
  2972. * The alias `.respondsTo` can be used interchangeably with `.respondTo`.
  2973. *
  2974. * @name respondTo
  2975. * @alias respondsTo
  2976. * @param {String} method
  2977. * @param {String} msg _optional_
  2978. * @namespace BDD
  2979. * @api public
  2980. */
  2981. function respondTo (method, msg) {
  2982. if (msg) flag(this, 'message', msg);
  2983. var obj = flag(this, 'object')
  2984. , itself = flag(this, 'itself')
  2985. , context = ('function' === typeof obj && !itself)
  2986. ? obj.prototype[method]
  2987. : obj[method];
  2988. this.assert(
  2989. 'function' === typeof context
  2990. , 'expected #{this} to respond to ' + _.inspect(method)
  2991. , 'expected #{this} to not respond to ' + _.inspect(method)
  2992. );
  2993. }
  2994. Assertion.addMethod('respondTo', respondTo);
  2995. Assertion.addMethod('respondsTo', respondTo);
  2996. /**
  2997. * ### .itself
  2998. *
  2999. * Forces all `.respondTo` assertions that follow in the chain to behave as if
  3000. * the target is a non-function object, even if it's a function. Thus, it
  3001. * causes `.respondTo` to assert that the target has a method with the given
  3002. * name, rather than asserting that the target's `prototype` property has a
  3003. * method with the given name.
  3004. *
  3005. * function Cat () {}
  3006. * Cat.prototype.meow = function () {};
  3007. * Cat.hiss = function () {};
  3008. *
  3009. * expect(Cat).itself.to.respondTo('hiss').but.not.respondTo('meow');
  3010. *
  3011. * @name itself
  3012. * @namespace BDD
  3013. * @api public
  3014. */
  3015. Assertion.addProperty('itself', function () {
  3016. flag(this, 'itself', true);
  3017. });
  3018. /**
  3019. * ### .satisfy(matcher[, msg])
  3020. *
  3021. * Invokes the given `matcher` function with the target being passed as the
  3022. * first argument, and asserts that the value returned is truthy.
  3023. *
  3024. * expect(1).to.satisfy(function(num) {
  3025. * return num > 0;
  3026. * });
  3027. *
  3028. * Add `.not` earlier in the chain to negate `.satisfy`.
  3029. *
  3030. * expect(1).to.not.satisfy(function(num) {
  3031. * return num > 2;
  3032. * });
  3033. *
  3034. * `.satisfy` accepts an optional `msg` argument which is a custom error
  3035. * message to show when the assertion fails. The message can also be given as
  3036. * the second argument to `expect`.
  3037. *
  3038. * expect(1).to.satisfy(function(num) {
  3039. * return num > 2;
  3040. * }, 'nooo why fail??');
  3041. *
  3042. * expect(1, 'nooo why fail??').to.satisfy(function(num) {
  3043. * return num > 2;
  3044. * });
  3045. *
  3046. * The alias `.satisfies` can be used interchangeably with `.satisfy`.
  3047. *
  3048. * @name satisfy
  3049. * @alias satisfies
  3050. * @param {Function} matcher
  3051. * @param {String} msg _optional_
  3052. * @namespace BDD
  3053. * @api public
  3054. */
  3055. function satisfy (matcher, msg) {
  3056. if (msg) flag(this, 'message', msg);
  3057. var obj = flag(this, 'object');
  3058. var result = matcher(obj);
  3059. this.assert(
  3060. result
  3061. , 'expected #{this} to satisfy ' + _.objDisplay(matcher)
  3062. , 'expected #{this} to not satisfy' + _.objDisplay(matcher)
  3063. , flag(this, 'negate') ? false : true
  3064. , result
  3065. );
  3066. }
  3067. Assertion.addMethod('satisfy', satisfy);
  3068. Assertion.addMethod('satisfies', satisfy);
  3069. /**
  3070. * ### .closeTo(expected, delta[, msg])
  3071. *
  3072. * Asserts that the target is a number that's within a given +/- `delta` range
  3073. * of the given number `expected`. However, it's often best to assert that the
  3074. * target is equal to its expected value.
  3075. *
  3076. * // Recommended
  3077. * expect(1.5).to.equal(1.5);
  3078. *
  3079. * // Not recommended
  3080. * expect(1.5).to.be.closeTo(1, 0.5);
  3081. * expect(1.5).to.be.closeTo(2, 0.5);
  3082. * expect(1.5).to.be.closeTo(1, 1);
  3083. *
  3084. * Add `.not` earlier in the chain to negate `.closeTo`.
  3085. *
  3086. * expect(1.5).to.equal(1.5); // Recommended
  3087. * expect(1.5).to.not.be.closeTo(3, 1); // Not recommended
  3088. *
  3089. * `.closeTo` accepts an optional `msg` argument which is a custom error
  3090. * message to show when the assertion fails. The message can also be given as
  3091. * the second argument to `expect`.
  3092. *
  3093. * expect(1.5).to.be.closeTo(3, 1, 'nooo why fail??');
  3094. * expect(1.5, 'nooo why fail??').to.be.closeTo(3, 1);
  3095. *
  3096. * The alias `.approximately` can be used interchangeably with `.closeTo`.
  3097. *
  3098. * @name closeTo
  3099. * @alias approximately
  3100. * @param {Number} expected
  3101. * @param {Number} delta
  3102. * @param {String} msg _optional_
  3103. * @namespace BDD
  3104. * @api public
  3105. */
  3106. function closeTo(expected, delta, msg) {
  3107. if (msg) flag(this, 'message', msg);
  3108. var obj = flag(this, 'object')
  3109. , flagMsg = flag(this, 'message')
  3110. , ssfi = flag(this, 'ssfi');
  3111. new Assertion(obj, flagMsg, ssfi, true).is.a('number');
  3112. if (typeof expected !== 'number' || typeof delta !== 'number') {
  3113. flagMsg = flagMsg ? flagMsg + ': ' : '';
  3114. var deltaMessage = delta === undefined ? ", and a delta is required" : "";
  3115. throw new AssertionError(
  3116. flagMsg + 'the arguments to closeTo or approximately must be numbers' + deltaMessage,
  3117. undefined,
  3118. ssfi
  3119. );
  3120. }
  3121. this.assert(
  3122. Math.abs(obj - expected) <= delta
  3123. , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
  3124. , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta
  3125. );
  3126. }
  3127. Assertion.addMethod('closeTo', closeTo);
  3128. Assertion.addMethod('approximately', closeTo);
  3129. // Note: Duplicates are ignored if testing for inclusion instead of sameness.
  3130. function isSubsetOf(subset, superset, cmp, contains, ordered) {
  3131. if (!contains) {
  3132. if (subset.length !== superset.length) return false;
  3133. superset = superset.slice();
  3134. }
  3135. return subset.every(function(elem, idx) {
  3136. if (ordered) return cmp ? cmp(elem, superset[idx]) : elem === superset[idx];
  3137. if (!cmp) {
  3138. var matchIdx = superset.indexOf(elem);
  3139. if (matchIdx === -1) return false;
  3140. // Remove match from superset so not counted twice if duplicate in subset.
  3141. if (!contains) superset.splice(matchIdx, 1);
  3142. return true;
  3143. }
  3144. return superset.some(function(elem2, matchIdx) {
  3145. if (!cmp(elem, elem2)) return false;
  3146. // Remove match from superset so not counted twice if duplicate in subset.
  3147. if (!contains) superset.splice(matchIdx, 1);
  3148. return true;
  3149. });
  3150. });
  3151. }
  3152. /**
  3153. * ### .members(set[, msg])
  3154. *
  3155. * Asserts that the target array has the same members as the given array
  3156. * `set`.
  3157. *
  3158. * expect([1, 2, 3]).to.have.members([2, 1, 3]);
  3159. * expect([1, 2, 2]).to.have.members([2, 1, 2]);
  3160. *
  3161. * By default, members are compared using strict (`===`) equality. Add `.deep`
  3162. * earlier in the chain to use deep equality instead. See the `deep-eql`
  3163. * project page for info on the deep equality algorithm:
  3164. * https://github.com/chaijs/deep-eql.
  3165. *
  3166. * // Target array deeply (but not strictly) has member `{a: 1}`
  3167. * expect([{a: 1}]).to.have.deep.members([{a: 1}]);
  3168. * expect([{a: 1}]).to.not.have.members([{a: 1}]);
  3169. *
  3170. * By default, order doesn't matter. Add `.ordered` earlier in the chain to
  3171. * require that members appear in the same order.
  3172. *
  3173. * expect([1, 2, 3]).to.have.ordered.members([1, 2, 3]);
  3174. * expect([1, 2, 3]).to.have.members([2, 1, 3])
  3175. * .but.not.ordered.members([2, 1, 3]);
  3176. *
  3177. * By default, both arrays must be the same size. Add `.include` earlier in
  3178. * the chain to require that the target's members be a superset of the
  3179. * expected members. Note that duplicates are ignored in the subset when
  3180. * `.include` is added.
  3181. *
  3182. * // Target array is a superset of [1, 2] but not identical
  3183. * expect([1, 2, 3]).to.include.members([1, 2]);
  3184. * expect([1, 2, 3]).to.not.have.members([1, 2]);
  3185. *
  3186. * // Duplicates in the subset are ignored
  3187. * expect([1, 2, 3]).to.include.members([1, 2, 2, 2]);
  3188. *
  3189. * `.deep`, `.ordered`, and `.include` can all be combined. However, if
  3190. * `.include` and `.ordered` are combined, the ordering begins at the start of
  3191. * both arrays.
  3192. *
  3193. * expect([{a: 1}, {b: 2}, {c: 3}])
  3194. * .to.include.deep.ordered.members([{a: 1}, {b: 2}])
  3195. * .but.not.include.deep.ordered.members([{b: 2}, {c: 3}]);
  3196. *
  3197. * Add `.not` earlier in the chain to negate `.members`. However, it's
  3198. * dangerous to do so. The problem is that it creates uncertain expectations
  3199. * by asserting that the target array doesn't have all of the same members as
  3200. * the given array `set` but may or may not have some of them. It's often best
  3201. * to identify the exact output that's expected, and then write an assertion
  3202. * that only accepts that exact output.
  3203. *
  3204. * expect([1, 2]).to.not.include(3).and.not.include(4); // Recommended
  3205. * expect([1, 2]).to.not.have.members([3, 4]); // Not recommended
  3206. *
  3207. * `.members` accepts an optional `msg` argument which is a custom error
  3208. * message to show when the assertion fails. The message can also be given as
  3209. * the second argument to `expect`.
  3210. *
  3211. * expect([1, 2]).to.have.members([1, 2, 3], 'nooo why fail??');
  3212. * expect([1, 2], 'nooo why fail??').to.have.members([1, 2, 3]);
  3213. *
  3214. * @name members
  3215. * @param {Array} set
  3216. * @param {String} msg _optional_
  3217. * @namespace BDD
  3218. * @api public
  3219. */
  3220. Assertion.addMethod('members', function (subset, msg) {
  3221. if (msg) flag(this, 'message', msg);
  3222. var obj = flag(this, 'object')
  3223. , flagMsg = flag(this, 'message')
  3224. , ssfi = flag(this, 'ssfi');
  3225. new Assertion(obj, flagMsg, ssfi, true).to.be.an('array');
  3226. new Assertion(subset, flagMsg, ssfi, true).to.be.an('array');
  3227. var contains = flag(this, 'contains');
  3228. var ordered = flag(this, 'ordered');
  3229. var subject, failMsg, failNegateMsg;
  3230. if (contains) {
  3231. subject = ordered ? 'an ordered superset' : 'a superset';
  3232. failMsg = 'expected #{this} to be ' + subject + ' of #{exp}';
  3233. failNegateMsg = 'expected #{this} to not be ' + subject + ' of #{exp}';
  3234. } else {
  3235. subject = ordered ? 'ordered members' : 'members';
  3236. failMsg = 'expected #{this} to have the same ' + subject + ' as #{exp}';
  3237. failNegateMsg = 'expected #{this} to not have the same ' + subject + ' as #{exp}';
  3238. }
  3239. var cmp = flag(this, 'deep') ? flag(this, 'eql') : undefined;
  3240. this.assert(
  3241. isSubsetOf(subset, obj, cmp, contains, ordered)
  3242. , failMsg
  3243. , failNegateMsg
  3244. , subset
  3245. , obj
  3246. , true
  3247. );
  3248. });
  3249. /**
  3250. * ### .oneOf(list[, msg])
  3251. *
  3252. * Asserts that the target is a member of the given array `list`. However,
  3253. * it's often best to assert that the target is equal to its expected value.
  3254. *
  3255. * expect(1).to.equal(1); // Recommended
  3256. * expect(1).to.be.oneOf([1, 2, 3]); // Not recommended
  3257. *
  3258. * Comparisons are performed using strict (`===`) equality.
  3259. *
  3260. * Add `.not` earlier in the chain to negate `.oneOf`.
  3261. *
  3262. * expect(1).to.equal(1); // Recommended
  3263. * expect(1).to.not.be.oneOf([2, 3, 4]); // Not recommended
  3264. *
  3265. * It can also be chained with `.contain` or `.include`, which will work with
  3266. * both arrays and strings:
  3267. *
  3268. * expect('Today is sunny').to.contain.oneOf(['sunny', 'cloudy'])
  3269. * expect('Today is rainy').to.not.contain.oneOf(['sunny', 'cloudy'])
  3270. * expect([1,2,3]).to.contain.oneOf([3,4,5])
  3271. * expect([1,2,3]).to.not.contain.oneOf([4,5,6])
  3272. *
  3273. * `.oneOf` accepts an optional `msg` argument which is a custom error message
  3274. * to show when the assertion fails. The message can also be given as the
  3275. * second argument to `expect`.
  3276. *
  3277. * expect(1).to.be.oneOf([2, 3, 4], 'nooo why fail??');
  3278. * expect(1, 'nooo why fail??').to.be.oneOf([2, 3, 4]);
  3279. *
  3280. * @name oneOf
  3281. * @param {Array<*>} list
  3282. * @param {String} msg _optional_
  3283. * @namespace BDD
  3284. * @api public
  3285. */
  3286. function oneOf (list, msg) {
  3287. if (msg) flag(this, 'message', msg);
  3288. var expected = flag(this, 'object')
  3289. , flagMsg = flag(this, 'message')
  3290. , ssfi = flag(this, 'ssfi')
  3291. , contains = flag(this, 'contains')
  3292. , isDeep = flag(this, 'deep')
  3293. , eql = flag(this, 'eql');
  3294. new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
  3295. if (contains) {
  3296. this.assert(
  3297. list.some(function(possibility) { return expected.indexOf(possibility) > -1 })
  3298. , 'expected #{this} to contain one of #{exp}'
  3299. , 'expected #{this} to not contain one of #{exp}'
  3300. , list
  3301. , expected
  3302. );
  3303. } else {
  3304. if (isDeep) {
  3305. this.assert(
  3306. list.some(function(possibility) { return eql(expected, possibility) })
  3307. , 'expected #{this} to deeply equal one of #{exp}'
  3308. , 'expected #{this} to deeply equal one of #{exp}'
  3309. , list
  3310. , expected
  3311. );
  3312. } else {
  3313. this.assert(
  3314. list.indexOf(expected) > -1
  3315. , 'expected #{this} to be one of #{exp}'
  3316. , 'expected #{this} to not be one of #{exp}'
  3317. , list
  3318. , expected
  3319. );
  3320. }
  3321. }
  3322. }
  3323. Assertion.addMethod('oneOf', oneOf);
  3324. /**
  3325. * ### .change(subject[, prop[, msg]])
  3326. *
  3327. * When one argument is provided, `.change` asserts that the given function
  3328. * `subject` returns a different value when it's invoked before the target
  3329. * function compared to when it's invoked afterward. However, it's often best
  3330. * to assert that `subject` is equal to its expected value.
  3331. *
  3332. * var dots = ''
  3333. * , addDot = function () { dots += '.'; }
  3334. * , getDots = function () { return dots; };
  3335. *
  3336. * // Recommended
  3337. * expect(getDots()).to.equal('');
  3338. * addDot();
  3339. * expect(getDots()).to.equal('.');
  3340. *
  3341. * // Not recommended
  3342. * expect(addDot).to.change(getDots);
  3343. *
  3344. * When two arguments are provided, `.change` asserts that the value of the
  3345. * given object `subject`'s `prop` property is different before invoking the
  3346. * target function compared to afterward.
  3347. *
  3348. * var myObj = {dots: ''}
  3349. * , addDot = function () { myObj.dots += '.'; };
  3350. *
  3351. * // Recommended
  3352. * expect(myObj).to.have.property('dots', '');
  3353. * addDot();
  3354. * expect(myObj).to.have.property('dots', '.');
  3355. *
  3356. * // Not recommended
  3357. * expect(addDot).to.change(myObj, 'dots');
  3358. *
  3359. * Strict (`===`) equality is used to compare before and after values.
  3360. *
  3361. * Add `.not` earlier in the chain to negate `.change`.
  3362. *
  3363. * var dots = ''
  3364. * , noop = function () {}
  3365. * , getDots = function () { return dots; };
  3366. *
  3367. * expect(noop).to.not.change(getDots);
  3368. *
  3369. * var myObj = {dots: ''}
  3370. * , noop = function () {};
  3371. *
  3372. * expect(noop).to.not.change(myObj, 'dots');
  3373. *
  3374. * `.change` accepts an optional `msg` argument which is a custom error
  3375. * message to show when the assertion fails. The message can also be given as
  3376. * the second argument to `expect`. When not providing two arguments, always
  3377. * use the second form.
  3378. *
  3379. * var myObj = {dots: ''}
  3380. * , addDot = function () { myObj.dots += '.'; };
  3381. *
  3382. * expect(addDot).to.not.change(myObj, 'dots', 'nooo why fail??');
  3383. *
  3384. * var dots = ''
  3385. * , addDot = function () { dots += '.'; }
  3386. * , getDots = function () { return dots; };
  3387. *
  3388. * expect(addDot, 'nooo why fail??').to.not.change(getDots);
  3389. *
  3390. * `.change` also causes all `.by` assertions that follow in the chain to
  3391. * assert how much a numeric subject was increased or decreased by. However,
  3392. * it's dangerous to use `.change.by`. The problem is that it creates
  3393. * uncertain expectations by asserting that the subject either increases by
  3394. * the given delta, or that it decreases by the given delta. It's often best
  3395. * to identify the exact output that's expected, and then write an assertion
  3396. * that only accepts that exact output.
  3397. *
  3398. * var myObj = {val: 1}
  3399. * , addTwo = function () { myObj.val += 2; }
  3400. * , subtractTwo = function () { myObj.val -= 2; };
  3401. *
  3402. * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
  3403. * expect(addTwo).to.change(myObj, 'val').by(2); // Not recommended
  3404. *
  3405. * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
  3406. * expect(subtractTwo).to.change(myObj, 'val').by(2); // Not recommended
  3407. *
  3408. * The alias `.changes` can be used interchangeably with `.change`.
  3409. *
  3410. * @name change
  3411. * @alias changes
  3412. * @param {String} subject
  3413. * @param {String} prop name _optional_
  3414. * @param {String} msg _optional_
  3415. * @namespace BDD
  3416. * @api public
  3417. */
  3418. function assertChanges (subject, prop, msg) {
  3419. if (msg) flag(this, 'message', msg);
  3420. var fn = flag(this, 'object')
  3421. , flagMsg = flag(this, 'message')
  3422. , ssfi = flag(this, 'ssfi');
  3423. new Assertion(fn, flagMsg, ssfi, true).is.a('function');
  3424. var initial;
  3425. if (!prop) {
  3426. new Assertion(subject, flagMsg, ssfi, true).is.a('function');
  3427. initial = subject();
  3428. } else {
  3429. new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
  3430. initial = subject[prop];
  3431. }
  3432. fn();
  3433. var final = prop === undefined || prop === null ? subject() : subject[prop];
  3434. var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
  3435. // This gets flagged because of the .by(delta) assertion
  3436. flag(this, 'deltaMsgObj', msgObj);
  3437. flag(this, 'initialDeltaValue', initial);
  3438. flag(this, 'finalDeltaValue', final);
  3439. flag(this, 'deltaBehavior', 'change');
  3440. flag(this, 'realDelta', final !== initial);
  3441. this.assert(
  3442. initial !== final
  3443. , 'expected ' + msgObj + ' to change'
  3444. , 'expected ' + msgObj + ' to not change'
  3445. );
  3446. }
  3447. Assertion.addMethod('change', assertChanges);
  3448. Assertion.addMethod('changes', assertChanges);
  3449. /**
  3450. * ### .increase(subject[, prop[, msg]])
  3451. *
  3452. * When one argument is provided, `.increase` asserts that the given function
  3453. * `subject` returns a greater number when it's invoked after invoking the
  3454. * target function compared to when it's invoked beforehand. `.increase` also
  3455. * causes all `.by` assertions that follow in the chain to assert how much
  3456. * greater of a number is returned. It's often best to assert that the return
  3457. * value increased by the expected amount, rather than asserting it increased
  3458. * by any amount.
  3459. *
  3460. * var val = 1
  3461. * , addTwo = function () { val += 2; }
  3462. * , getVal = function () { return val; };
  3463. *
  3464. * expect(addTwo).to.increase(getVal).by(2); // Recommended
  3465. * expect(addTwo).to.increase(getVal); // Not recommended
  3466. *
  3467. * When two arguments are provided, `.increase` asserts that the value of the
  3468. * given object `subject`'s `prop` property is greater after invoking the
  3469. * target function compared to beforehand.
  3470. *
  3471. * var myObj = {val: 1}
  3472. * , addTwo = function () { myObj.val += 2; };
  3473. *
  3474. * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
  3475. * expect(addTwo).to.increase(myObj, 'val'); // Not recommended
  3476. *
  3477. * Add `.not` earlier in the chain to negate `.increase`. However, it's
  3478. * dangerous to do so. The problem is that it creates uncertain expectations
  3479. * by asserting that the subject either decreases, or that it stays the same.
  3480. * It's often best to identify the exact output that's expected, and then
  3481. * write an assertion that only accepts that exact output.
  3482. *
  3483. * When the subject is expected to decrease, it's often best to assert that it
  3484. * decreased by the expected amount.
  3485. *
  3486. * var myObj = {val: 1}
  3487. * , subtractTwo = function () { myObj.val -= 2; };
  3488. *
  3489. * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
  3490. * expect(subtractTwo).to.not.increase(myObj, 'val'); // Not recommended
  3491. *
  3492. * When the subject is expected to stay the same, it's often best to assert
  3493. * exactly that.
  3494. *
  3495. * var myObj = {val: 1}
  3496. * , noop = function () {};
  3497. *
  3498. * expect(noop).to.not.change(myObj, 'val'); // Recommended
  3499. * expect(noop).to.not.increase(myObj, 'val'); // Not recommended
  3500. *
  3501. * `.increase` accepts an optional `msg` argument which is a custom error
  3502. * message to show when the assertion fails. The message can also be given as
  3503. * the second argument to `expect`. When not providing two arguments, always
  3504. * use the second form.
  3505. *
  3506. * var myObj = {val: 1}
  3507. * , noop = function () {};
  3508. *
  3509. * expect(noop).to.increase(myObj, 'val', 'nooo why fail??');
  3510. *
  3511. * var val = 1
  3512. * , noop = function () {}
  3513. * , getVal = function () { return val; };
  3514. *
  3515. * expect(noop, 'nooo why fail??').to.increase(getVal);
  3516. *
  3517. * The alias `.increases` can be used interchangeably with `.increase`.
  3518. *
  3519. * @name increase
  3520. * @alias increases
  3521. * @param {String|Function} subject
  3522. * @param {String} prop name _optional_
  3523. * @param {String} msg _optional_
  3524. * @namespace BDD
  3525. * @api public
  3526. */
  3527. function assertIncreases (subject, prop, msg) {
  3528. if (msg) flag(this, 'message', msg);
  3529. var fn = flag(this, 'object')
  3530. , flagMsg = flag(this, 'message')
  3531. , ssfi = flag(this, 'ssfi');
  3532. new Assertion(fn, flagMsg, ssfi, true).is.a('function');
  3533. var initial;
  3534. if (!prop) {
  3535. new Assertion(subject, flagMsg, ssfi, true).is.a('function');
  3536. initial = subject();
  3537. } else {
  3538. new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
  3539. initial = subject[prop];
  3540. }
  3541. // Make sure that the target is a number
  3542. new Assertion(initial, flagMsg, ssfi, true).is.a('number');
  3543. fn();
  3544. var final = prop === undefined || prop === null ? subject() : subject[prop];
  3545. var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
  3546. flag(this, 'deltaMsgObj', msgObj);
  3547. flag(this, 'initialDeltaValue', initial);
  3548. flag(this, 'finalDeltaValue', final);
  3549. flag(this, 'deltaBehavior', 'increase');
  3550. flag(this, 'realDelta', final - initial);
  3551. this.assert(
  3552. final - initial > 0
  3553. , 'expected ' + msgObj + ' to increase'
  3554. , 'expected ' + msgObj + ' to not increase'
  3555. );
  3556. }
  3557. Assertion.addMethod('increase', assertIncreases);
  3558. Assertion.addMethod('increases', assertIncreases);
  3559. /**
  3560. * ### .decrease(subject[, prop[, msg]])
  3561. *
  3562. * When one argument is provided, `.decrease` asserts that the given function
  3563. * `subject` returns a lesser number when it's invoked after invoking the
  3564. * target function compared to when it's invoked beforehand. `.decrease` also
  3565. * causes all `.by` assertions that follow in the chain to assert how much
  3566. * lesser of a number is returned. It's often best to assert that the return
  3567. * value decreased by the expected amount, rather than asserting it decreased
  3568. * by any amount.
  3569. *
  3570. * var val = 1
  3571. * , subtractTwo = function () { val -= 2; }
  3572. * , getVal = function () { return val; };
  3573. *
  3574. * expect(subtractTwo).to.decrease(getVal).by(2); // Recommended
  3575. * expect(subtractTwo).to.decrease(getVal); // Not recommended
  3576. *
  3577. * When two arguments are provided, `.decrease` asserts that the value of the
  3578. * given object `subject`'s `prop` property is lesser after invoking the
  3579. * target function compared to beforehand.
  3580. *
  3581. * var myObj = {val: 1}
  3582. * , subtractTwo = function () { myObj.val -= 2; };
  3583. *
  3584. * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
  3585. * expect(subtractTwo).to.decrease(myObj, 'val'); // Not recommended
  3586. *
  3587. * Add `.not` earlier in the chain to negate `.decrease`. However, it's
  3588. * dangerous to do so. The problem is that it creates uncertain expectations
  3589. * by asserting that the subject either increases, or that it stays the same.
  3590. * It's often best to identify the exact output that's expected, and then
  3591. * write an assertion that only accepts that exact output.
  3592. *
  3593. * When the subject is expected to increase, it's often best to assert that it
  3594. * increased by the expected amount.
  3595. *
  3596. * var myObj = {val: 1}
  3597. * , addTwo = function () { myObj.val += 2; };
  3598. *
  3599. * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
  3600. * expect(addTwo).to.not.decrease(myObj, 'val'); // Not recommended
  3601. *
  3602. * When the subject is expected to stay the same, it's often best to assert
  3603. * exactly that.
  3604. *
  3605. * var myObj = {val: 1}
  3606. * , noop = function () {};
  3607. *
  3608. * expect(noop).to.not.change(myObj, 'val'); // Recommended
  3609. * expect(noop).to.not.decrease(myObj, 'val'); // Not recommended
  3610. *
  3611. * `.decrease` accepts an optional `msg` argument which is a custom error
  3612. * message to show when the assertion fails. The message can also be given as
  3613. * the second argument to `expect`. When not providing two arguments, always
  3614. * use the second form.
  3615. *
  3616. * var myObj = {val: 1}
  3617. * , noop = function () {};
  3618. *
  3619. * expect(noop).to.decrease(myObj, 'val', 'nooo why fail??');
  3620. *
  3621. * var val = 1
  3622. * , noop = function () {}
  3623. * , getVal = function () { return val; };
  3624. *
  3625. * expect(noop, 'nooo why fail??').to.decrease(getVal);
  3626. *
  3627. * The alias `.decreases` can be used interchangeably with `.decrease`.
  3628. *
  3629. * @name decrease
  3630. * @alias decreases
  3631. * @param {String|Function} subject
  3632. * @param {String} prop name _optional_
  3633. * @param {String} msg _optional_
  3634. * @namespace BDD
  3635. * @api public
  3636. */
  3637. function assertDecreases (subject, prop, msg) {
  3638. if (msg) flag(this, 'message', msg);
  3639. var fn = flag(this, 'object')
  3640. , flagMsg = flag(this, 'message')
  3641. , ssfi = flag(this, 'ssfi');
  3642. new Assertion(fn, flagMsg, ssfi, true).is.a('function');
  3643. var initial;
  3644. if (!prop) {
  3645. new Assertion(subject, flagMsg, ssfi, true).is.a('function');
  3646. initial = subject();
  3647. } else {
  3648. new Assertion(subject, flagMsg, ssfi, true).to.have.property(prop);
  3649. initial = subject[prop];
  3650. }
  3651. // Make sure that the target is a number
  3652. new Assertion(initial, flagMsg, ssfi, true).is.a('number');
  3653. fn();
  3654. var final = prop === undefined || prop === null ? subject() : subject[prop];
  3655. var msgObj = prop === undefined || prop === null ? initial : '.' + prop;
  3656. flag(this, 'deltaMsgObj', msgObj);
  3657. flag(this, 'initialDeltaValue', initial);
  3658. flag(this, 'finalDeltaValue', final);
  3659. flag(this, 'deltaBehavior', 'decrease');
  3660. flag(this, 'realDelta', initial - final);
  3661. this.assert(
  3662. final - initial < 0
  3663. , 'expected ' + msgObj + ' to decrease'
  3664. , 'expected ' + msgObj + ' to not decrease'
  3665. );
  3666. }
  3667. Assertion.addMethod('decrease', assertDecreases);
  3668. Assertion.addMethod('decreases', assertDecreases);
  3669. /**
  3670. * ### .by(delta[, msg])
  3671. *
  3672. * When following an `.increase` assertion in the chain, `.by` asserts that
  3673. * the subject of the `.increase` assertion increased by the given `delta`.
  3674. *
  3675. * var myObj = {val: 1}
  3676. * , addTwo = function () { myObj.val += 2; };
  3677. *
  3678. * expect(addTwo).to.increase(myObj, 'val').by(2);
  3679. *
  3680. * When following a `.decrease` assertion in the chain, `.by` asserts that the
  3681. * subject of the `.decrease` assertion decreased by the given `delta`.
  3682. *
  3683. * var myObj = {val: 1}
  3684. * , subtractTwo = function () { myObj.val -= 2; };
  3685. *
  3686. * expect(subtractTwo).to.decrease(myObj, 'val').by(2);
  3687. *
  3688. * When following a `.change` assertion in the chain, `.by` asserts that the
  3689. * subject of the `.change` assertion either increased or decreased by the
  3690. * given `delta`. However, it's dangerous to use `.change.by`. The problem is
  3691. * that it creates uncertain expectations. It's often best to identify the
  3692. * exact output that's expected, and then write an assertion that only accepts
  3693. * that exact output.
  3694. *
  3695. * var myObj = {val: 1}
  3696. * , addTwo = function () { myObj.val += 2; }
  3697. * , subtractTwo = function () { myObj.val -= 2; };
  3698. *
  3699. * expect(addTwo).to.increase(myObj, 'val').by(2); // Recommended
  3700. * expect(addTwo).to.change(myObj, 'val').by(2); // Not recommended
  3701. *
  3702. * expect(subtractTwo).to.decrease(myObj, 'val').by(2); // Recommended
  3703. * expect(subtractTwo).to.change(myObj, 'val').by(2); // Not recommended
  3704. *
  3705. * Add `.not` earlier in the chain to negate `.by`. However, it's often best
  3706. * to assert that the subject changed by its expected delta, rather than
  3707. * asserting that it didn't change by one of countless unexpected deltas.
  3708. *
  3709. * var myObj = {val: 1}
  3710. * , addTwo = function () { myObj.val += 2; };
  3711. *
  3712. * // Recommended
  3713. * expect(addTwo).to.increase(myObj, 'val').by(2);
  3714. *
  3715. * // Not recommended
  3716. * expect(addTwo).to.increase(myObj, 'val').but.not.by(3);
  3717. *
  3718. * `.by` accepts an optional `msg` argument which is a custom error message to
  3719. * show when the assertion fails. The message can also be given as the second
  3720. * argument to `expect`.
  3721. *
  3722. * var myObj = {val: 1}
  3723. * , addTwo = function () { myObj.val += 2; };
  3724. *
  3725. * expect(addTwo).to.increase(myObj, 'val').by(3, 'nooo why fail??');
  3726. * expect(addTwo, 'nooo why fail??').to.increase(myObj, 'val').by(3);
  3727. *
  3728. * @name by
  3729. * @param {Number} delta
  3730. * @param {String} msg _optional_
  3731. * @namespace BDD
  3732. * @api public
  3733. */
  3734. function assertDelta(delta, msg) {
  3735. if (msg) flag(this, 'message', msg);
  3736. var msgObj = flag(this, 'deltaMsgObj');
  3737. var initial = flag(this, 'initialDeltaValue');
  3738. var final = flag(this, 'finalDeltaValue');
  3739. var behavior = flag(this, 'deltaBehavior');
  3740. var realDelta = flag(this, 'realDelta');
  3741. var expression;
  3742. if (behavior === 'change') {
  3743. expression = Math.abs(final - initial) === Math.abs(delta);
  3744. } else {
  3745. expression = realDelta === Math.abs(delta);
  3746. }
  3747. this.assert(
  3748. expression
  3749. , 'expected ' + msgObj + ' to ' + behavior + ' by ' + delta
  3750. , 'expected ' + msgObj + ' to not ' + behavior + ' by ' + delta
  3751. );
  3752. }
  3753. Assertion.addMethod('by', assertDelta);
  3754. /**
  3755. * ### .extensible
  3756. *
  3757. * Asserts that the target is extensible, which means that new properties can
  3758. * be added to it. Primitives are never extensible.
  3759. *
  3760. * expect({a: 1}).to.be.extensible;
  3761. *
  3762. * Add `.not` earlier in the chain to negate `.extensible`.
  3763. *
  3764. * var nonExtensibleObject = Object.preventExtensions({})
  3765. * , sealedObject = Object.seal({})
  3766. * , frozenObject = Object.freeze({});
  3767. *
  3768. * expect(nonExtensibleObject).to.not.be.extensible;
  3769. * expect(sealedObject).to.not.be.extensible;
  3770. * expect(frozenObject).to.not.be.extensible;
  3771. * expect(1).to.not.be.extensible;
  3772. *
  3773. * A custom error message can be given as the second argument to `expect`.
  3774. *
  3775. * expect(1, 'nooo why fail??').to.be.extensible;
  3776. *
  3777. * @name extensible
  3778. * @namespace BDD
  3779. * @api public
  3780. */
  3781. Assertion.addProperty('extensible', function() {
  3782. var obj = flag(this, 'object');
  3783. // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
  3784. // In ES6, a non-object argument will be treated as if it was a non-extensible ordinary object, simply return false.
  3785. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isExtensible
  3786. // The following provides ES6 behavior for ES5 environments.
  3787. var isExtensible = obj === Object(obj) && Object.isExtensible(obj);
  3788. this.assert(
  3789. isExtensible
  3790. , 'expected #{this} to be extensible'
  3791. , 'expected #{this} to not be extensible'
  3792. );
  3793. });
  3794. /**
  3795. * ### .sealed
  3796. *
  3797. * Asserts that the target is sealed, which means that new properties can't be
  3798. * added to it, and its existing properties can't be reconfigured or deleted.
  3799. * However, it's possible that its existing properties can still be reassigned
  3800. * to different values. Primitives are always sealed.
  3801. *
  3802. * var sealedObject = Object.seal({});
  3803. * var frozenObject = Object.freeze({});
  3804. *
  3805. * expect(sealedObject).to.be.sealed;
  3806. * expect(frozenObject).to.be.sealed;
  3807. * expect(1).to.be.sealed;
  3808. *
  3809. * Add `.not` earlier in the chain to negate `.sealed`.
  3810. *
  3811. * expect({a: 1}).to.not.be.sealed;
  3812. *
  3813. * A custom error message can be given as the second argument to `expect`.
  3814. *
  3815. * expect({a: 1}, 'nooo why fail??').to.be.sealed;
  3816. *
  3817. * @name sealed
  3818. * @namespace BDD
  3819. * @api public
  3820. */
  3821. Assertion.addProperty('sealed', function() {
  3822. var obj = flag(this, 'object');
  3823. // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
  3824. // In ES6, a non-object argument will be treated as if it was a sealed ordinary object, simply return true.
  3825. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isSealed
  3826. // The following provides ES6 behavior for ES5 environments.
  3827. var isSealed = obj === Object(obj) ? Object.isSealed(obj) : true;
  3828. this.assert(
  3829. isSealed
  3830. , 'expected #{this} to be sealed'
  3831. , 'expected #{this} to not be sealed'
  3832. );
  3833. });
  3834. /**
  3835. * ### .frozen
  3836. *
  3837. * Asserts that the target is frozen, which means that new properties can't be
  3838. * added to it, and its existing properties can't be reassigned to different
  3839. * values, reconfigured, or deleted. Primitives are always frozen.
  3840. *
  3841. * var frozenObject = Object.freeze({});
  3842. *
  3843. * expect(frozenObject).to.be.frozen;
  3844. * expect(1).to.be.frozen;
  3845. *
  3846. * Add `.not` earlier in the chain to negate `.frozen`.
  3847. *
  3848. * expect({a: 1}).to.not.be.frozen;
  3849. *
  3850. * A custom error message can be given as the second argument to `expect`.
  3851. *
  3852. * expect({a: 1}, 'nooo why fail??').to.be.frozen;
  3853. *
  3854. * @name frozen
  3855. * @namespace BDD
  3856. * @api public
  3857. */
  3858. Assertion.addProperty('frozen', function() {
  3859. var obj = flag(this, 'object');
  3860. // In ES5, if the argument to this method is a primitive, then it will cause a TypeError.
  3861. // In ES6, a non-object argument will be treated as if it was a frozen ordinary object, simply return true.
  3862. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isFrozen
  3863. // The following provides ES6 behavior for ES5 environments.
  3864. var isFrozen = obj === Object(obj) ? Object.isFrozen(obj) : true;
  3865. this.assert(
  3866. isFrozen
  3867. , 'expected #{this} to be frozen'
  3868. , 'expected #{this} to not be frozen'
  3869. );
  3870. });
  3871. /**
  3872. * ### .finite
  3873. *
  3874. * Asserts that the target is a number, and isn't `NaN` or positive/negative
  3875. * `Infinity`.
  3876. *
  3877. * expect(1).to.be.finite;
  3878. *
  3879. * Add `.not` earlier in the chain to negate `.finite`. However, it's
  3880. * dangerous to do so. The problem is that it creates uncertain expectations
  3881. * by asserting that the subject either isn't a number, or that it's `NaN`, or
  3882. * that it's positive `Infinity`, or that it's negative `Infinity`. It's often
  3883. * best to identify the exact output that's expected, and then write an
  3884. * assertion that only accepts that exact output.
  3885. *
  3886. * When the target isn't expected to be a number, it's often best to assert
  3887. * that it's the expected type, rather than asserting that it isn't one of
  3888. * many unexpected types.
  3889. *
  3890. * expect('foo').to.be.a('string'); // Recommended
  3891. * expect('foo').to.not.be.finite; // Not recommended
  3892. *
  3893. * When the target is expected to be `NaN`, it's often best to assert exactly
  3894. * that.
  3895. *
  3896. * expect(NaN).to.be.NaN; // Recommended
  3897. * expect(NaN).to.not.be.finite; // Not recommended
  3898. *
  3899. * When the target is expected to be positive infinity, it's often best to
  3900. * assert exactly that.
  3901. *
  3902. * expect(Infinity).to.equal(Infinity); // Recommended
  3903. * expect(Infinity).to.not.be.finite; // Not recommended
  3904. *
  3905. * When the target is expected to be negative infinity, it's often best to
  3906. * assert exactly that.
  3907. *
  3908. * expect(-Infinity).to.equal(-Infinity); // Recommended
  3909. * expect(-Infinity).to.not.be.finite; // Not recommended
  3910. *
  3911. * A custom error message can be given as the second argument to `expect`.
  3912. *
  3913. * expect('foo', 'nooo why fail??').to.be.finite;
  3914. *
  3915. * @name finite
  3916. * @namespace BDD
  3917. * @api public
  3918. */
  3919. Assertion.addProperty('finite', function(msg) {
  3920. var obj = flag(this, 'object');
  3921. this.assert(
  3922. typeof obj === 'number' && isFinite(obj)
  3923. , 'expected #{this} to be a finite number'
  3924. , 'expected #{this} to not be a finite number'
  3925. );
  3926. });
  3927. };
  3928. },{}],6:[function(require,module,exports){
  3929. /*!
  3930. * chai
  3931. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  3932. * MIT Licensed
  3933. */
  3934. module.exports = function (chai, util) {
  3935. /*!
  3936. * Chai dependencies.
  3937. */
  3938. var Assertion = chai.Assertion
  3939. , flag = util.flag;
  3940. /*!
  3941. * Module export.
  3942. */
  3943. /**
  3944. * ### assert(expression, message)
  3945. *
  3946. * Write your own test expressions.
  3947. *
  3948. * assert('foo' !== 'bar', 'foo is not bar');
  3949. * assert(Array.isArray([]), 'empty arrays are arrays');
  3950. *
  3951. * @param {Mixed} expression to test for truthiness
  3952. * @param {String} message to display on error
  3953. * @name assert
  3954. * @namespace Assert
  3955. * @api public
  3956. */
  3957. var assert = chai.assert = function (express, errmsg) {
  3958. var test = new Assertion(null, null, chai.assert, true);
  3959. test.assert(
  3960. express
  3961. , errmsg
  3962. , '[ negation message unavailable ]'
  3963. );
  3964. };
  3965. /**
  3966. * ### .fail([message])
  3967. * ### .fail(actual, expected, [message], [operator])
  3968. *
  3969. * Throw a failure. Node.js `assert` module-compatible.
  3970. *
  3971. * assert.fail();
  3972. * assert.fail("custom error message");
  3973. * assert.fail(1, 2);
  3974. * assert.fail(1, 2, "custom error message");
  3975. * assert.fail(1, 2, "custom error message", ">");
  3976. * assert.fail(1, 2, undefined, ">");
  3977. *
  3978. * @name fail
  3979. * @param {Mixed} actual
  3980. * @param {Mixed} expected
  3981. * @param {String} message
  3982. * @param {String} operator
  3983. * @namespace Assert
  3984. * @api public
  3985. */
  3986. assert.fail = function (actual, expected, message, operator) {
  3987. if (arguments.length < 2) {
  3988. // Comply with Node's fail([message]) interface
  3989. message = actual;
  3990. actual = undefined;
  3991. }
  3992. message = message || 'assert.fail()';
  3993. throw new chai.AssertionError(message, {
  3994. actual: actual
  3995. , expected: expected
  3996. , operator: operator
  3997. }, assert.fail);
  3998. };
  3999. /**
  4000. * ### .isOk(object, [message])
  4001. *
  4002. * Asserts that `object` is truthy.
  4003. *
  4004. * assert.isOk('everything', 'everything is ok');
  4005. * assert.isOk(false, 'this will fail');
  4006. *
  4007. * @name isOk
  4008. * @alias ok
  4009. * @param {Mixed} object to test
  4010. * @param {String} message
  4011. * @namespace Assert
  4012. * @api public
  4013. */
  4014. assert.isOk = function (val, msg) {
  4015. new Assertion(val, msg, assert.isOk, true).is.ok;
  4016. };
  4017. /**
  4018. * ### .isNotOk(object, [message])
  4019. *
  4020. * Asserts that `object` is falsy.
  4021. *
  4022. * assert.isNotOk('everything', 'this will fail');
  4023. * assert.isNotOk(false, 'this will pass');
  4024. *
  4025. * @name isNotOk
  4026. * @alias notOk
  4027. * @param {Mixed} object to test
  4028. * @param {String} message
  4029. * @namespace Assert
  4030. * @api public
  4031. */
  4032. assert.isNotOk = function (val, msg) {
  4033. new Assertion(val, msg, assert.isNotOk, true).is.not.ok;
  4034. };
  4035. /**
  4036. * ### .equal(actual, expected, [message])
  4037. *
  4038. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  4039. *
  4040. * assert.equal(3, '3', '== coerces values to strings');
  4041. *
  4042. * @name equal
  4043. * @param {Mixed} actual
  4044. * @param {Mixed} expected
  4045. * @param {String} message
  4046. * @namespace Assert
  4047. * @api public
  4048. */
  4049. assert.equal = function (act, exp, msg) {
  4050. var test = new Assertion(act, msg, assert.equal, true);
  4051. test.assert(
  4052. exp == flag(test, 'object')
  4053. , 'expected #{this} to equal #{exp}'
  4054. , 'expected #{this} to not equal #{act}'
  4055. , exp
  4056. , act
  4057. , true
  4058. );
  4059. };
  4060. /**
  4061. * ### .notEqual(actual, expected, [message])
  4062. *
  4063. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  4064. *
  4065. * assert.notEqual(3, 4, 'these numbers are not equal');
  4066. *
  4067. * @name notEqual
  4068. * @param {Mixed} actual
  4069. * @param {Mixed} expected
  4070. * @param {String} message
  4071. * @namespace Assert
  4072. * @api public
  4073. */
  4074. assert.notEqual = function (act, exp, msg) {
  4075. var test = new Assertion(act, msg, assert.notEqual, true);
  4076. test.assert(
  4077. exp != flag(test, 'object')
  4078. , 'expected #{this} to not equal #{exp}'
  4079. , 'expected #{this} to equal #{act}'
  4080. , exp
  4081. , act
  4082. , true
  4083. );
  4084. };
  4085. /**
  4086. * ### .strictEqual(actual, expected, [message])
  4087. *
  4088. * Asserts strict equality (`===`) of `actual` and `expected`.
  4089. *
  4090. * assert.strictEqual(true, true, 'these booleans are strictly equal');
  4091. *
  4092. * @name strictEqual
  4093. * @param {Mixed} actual
  4094. * @param {Mixed} expected
  4095. * @param {String} message
  4096. * @namespace Assert
  4097. * @api public
  4098. */
  4099. assert.strictEqual = function (act, exp, msg) {
  4100. new Assertion(act, msg, assert.strictEqual, true).to.equal(exp);
  4101. };
  4102. /**
  4103. * ### .notStrictEqual(actual, expected, [message])
  4104. *
  4105. * Asserts strict inequality (`!==`) of `actual` and `expected`.
  4106. *
  4107. * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
  4108. *
  4109. * @name notStrictEqual
  4110. * @param {Mixed} actual
  4111. * @param {Mixed} expected
  4112. * @param {String} message
  4113. * @namespace Assert
  4114. * @api public
  4115. */
  4116. assert.notStrictEqual = function (act, exp, msg) {
  4117. new Assertion(act, msg, assert.notStrictEqual, true).to.not.equal(exp);
  4118. };
  4119. /**
  4120. * ### .deepEqual(actual, expected, [message])
  4121. *
  4122. * Asserts that `actual` is deeply equal to `expected`.
  4123. *
  4124. * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
  4125. *
  4126. * @name deepEqual
  4127. * @param {Mixed} actual
  4128. * @param {Mixed} expected
  4129. * @param {String} message
  4130. * @alias deepStrictEqual
  4131. * @namespace Assert
  4132. * @api public
  4133. */
  4134. assert.deepEqual = assert.deepStrictEqual = function (act, exp, msg) {
  4135. new Assertion(act, msg, assert.deepEqual, true).to.eql(exp);
  4136. };
  4137. /**
  4138. * ### .notDeepEqual(actual, expected, [message])
  4139. *
  4140. * Assert that `actual` is not deeply equal to `expected`.
  4141. *
  4142. * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
  4143. *
  4144. * @name notDeepEqual
  4145. * @param {Mixed} actual
  4146. * @param {Mixed} expected
  4147. * @param {String} message
  4148. * @namespace Assert
  4149. * @api public
  4150. */
  4151. assert.notDeepEqual = function (act, exp, msg) {
  4152. new Assertion(act, msg, assert.notDeepEqual, true).to.not.eql(exp);
  4153. };
  4154. /**
  4155. * ### .isAbove(valueToCheck, valueToBeAbove, [message])
  4156. *
  4157. * Asserts `valueToCheck` is strictly greater than (>) `valueToBeAbove`.
  4158. *
  4159. * assert.isAbove(5, 2, '5 is strictly greater than 2');
  4160. *
  4161. * @name isAbove
  4162. * @param {Mixed} valueToCheck
  4163. * @param {Mixed} valueToBeAbove
  4164. * @param {String} message
  4165. * @namespace Assert
  4166. * @api public
  4167. */
  4168. assert.isAbove = function (val, abv, msg) {
  4169. new Assertion(val, msg, assert.isAbove, true).to.be.above(abv);
  4170. };
  4171. /**
  4172. * ### .isAtLeast(valueToCheck, valueToBeAtLeast, [message])
  4173. *
  4174. * Asserts `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`.
  4175. *
  4176. * assert.isAtLeast(5, 2, '5 is greater or equal to 2');
  4177. * assert.isAtLeast(3, 3, '3 is greater or equal to 3');
  4178. *
  4179. * @name isAtLeast
  4180. * @param {Mixed} valueToCheck
  4181. * @param {Mixed} valueToBeAtLeast
  4182. * @param {String} message
  4183. * @namespace Assert
  4184. * @api public
  4185. */
  4186. assert.isAtLeast = function (val, atlst, msg) {
  4187. new Assertion(val, msg, assert.isAtLeast, true).to.be.least(atlst);
  4188. };
  4189. /**
  4190. * ### .isBelow(valueToCheck, valueToBeBelow, [message])
  4191. *
  4192. * Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`.
  4193. *
  4194. * assert.isBelow(3, 6, '3 is strictly less than 6');
  4195. *
  4196. * @name isBelow
  4197. * @param {Mixed} valueToCheck
  4198. * @param {Mixed} valueToBeBelow
  4199. * @param {String} message
  4200. * @namespace Assert
  4201. * @api public
  4202. */
  4203. assert.isBelow = function (val, blw, msg) {
  4204. new Assertion(val, msg, assert.isBelow, true).to.be.below(blw);
  4205. };
  4206. /**
  4207. * ### .isAtMost(valueToCheck, valueToBeAtMost, [message])
  4208. *
  4209. * Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`.
  4210. *
  4211. * assert.isAtMost(3, 6, '3 is less than or equal to 6');
  4212. * assert.isAtMost(4, 4, '4 is less than or equal to 4');
  4213. *
  4214. * @name isAtMost
  4215. * @param {Mixed} valueToCheck
  4216. * @param {Mixed} valueToBeAtMost
  4217. * @param {String} message
  4218. * @namespace Assert
  4219. * @api public
  4220. */
  4221. assert.isAtMost = function (val, atmst, msg) {
  4222. new Assertion(val, msg, assert.isAtMost, true).to.be.most(atmst);
  4223. };
  4224. /**
  4225. * ### .isTrue(value, [message])
  4226. *
  4227. * Asserts that `value` is true.
  4228. *
  4229. * var teaServed = true;
  4230. * assert.isTrue(teaServed, 'the tea has been served');
  4231. *
  4232. * @name isTrue
  4233. * @param {Mixed} value
  4234. * @param {String} message
  4235. * @namespace Assert
  4236. * @api public
  4237. */
  4238. assert.isTrue = function (val, msg) {
  4239. new Assertion(val, msg, assert.isTrue, true).is['true'];
  4240. };
  4241. /**
  4242. * ### .isNotTrue(value, [message])
  4243. *
  4244. * Asserts that `value` is not true.
  4245. *
  4246. * var tea = 'tasty chai';
  4247. * assert.isNotTrue(tea, 'great, time for tea!');
  4248. *
  4249. * @name isNotTrue
  4250. * @param {Mixed} value
  4251. * @param {String} message
  4252. * @namespace Assert
  4253. * @api public
  4254. */
  4255. assert.isNotTrue = function (val, msg) {
  4256. new Assertion(val, msg, assert.isNotTrue, true).to.not.equal(true);
  4257. };
  4258. /**
  4259. * ### .isFalse(value, [message])
  4260. *
  4261. * Asserts that `value` is false.
  4262. *
  4263. * var teaServed = false;
  4264. * assert.isFalse(teaServed, 'no tea yet? hmm...');
  4265. *
  4266. * @name isFalse
  4267. * @param {Mixed} value
  4268. * @param {String} message
  4269. * @namespace Assert
  4270. * @api public
  4271. */
  4272. assert.isFalse = function (val, msg) {
  4273. new Assertion(val, msg, assert.isFalse, true).is['false'];
  4274. };
  4275. /**
  4276. * ### .isNotFalse(value, [message])
  4277. *
  4278. * Asserts that `value` is not false.
  4279. *
  4280. * var tea = 'tasty chai';
  4281. * assert.isNotFalse(tea, 'great, time for tea!');
  4282. *
  4283. * @name isNotFalse
  4284. * @param {Mixed} value
  4285. * @param {String} message
  4286. * @namespace Assert
  4287. * @api public
  4288. */
  4289. assert.isNotFalse = function (val, msg) {
  4290. new Assertion(val, msg, assert.isNotFalse, true).to.not.equal(false);
  4291. };
  4292. /**
  4293. * ### .isNull(value, [message])
  4294. *
  4295. * Asserts that `value` is null.
  4296. *
  4297. * assert.isNull(err, 'there was no error');
  4298. *
  4299. * @name isNull
  4300. * @param {Mixed} value
  4301. * @param {String} message
  4302. * @namespace Assert
  4303. * @api public
  4304. */
  4305. assert.isNull = function (val, msg) {
  4306. new Assertion(val, msg, assert.isNull, true).to.equal(null);
  4307. };
  4308. /**
  4309. * ### .isNotNull(value, [message])
  4310. *
  4311. * Asserts that `value` is not null.
  4312. *
  4313. * var tea = 'tasty chai';
  4314. * assert.isNotNull(tea, 'great, time for tea!');
  4315. *
  4316. * @name isNotNull
  4317. * @param {Mixed} value
  4318. * @param {String} message
  4319. * @namespace Assert
  4320. * @api public
  4321. */
  4322. assert.isNotNull = function (val, msg) {
  4323. new Assertion(val, msg, assert.isNotNull, true).to.not.equal(null);
  4324. };
  4325. /**
  4326. * ### .isNaN
  4327. *
  4328. * Asserts that value is NaN.
  4329. *
  4330. * assert.isNaN(NaN, 'NaN is NaN');
  4331. *
  4332. * @name isNaN
  4333. * @param {Mixed} value
  4334. * @param {String} message
  4335. * @namespace Assert
  4336. * @api public
  4337. */
  4338. assert.isNaN = function (val, msg) {
  4339. new Assertion(val, msg, assert.isNaN, true).to.be.NaN;
  4340. };
  4341. /**
  4342. * ### .isNotNaN
  4343. *
  4344. * Asserts that value is not NaN.
  4345. *
  4346. * assert.isNotNaN(4, '4 is not NaN');
  4347. *
  4348. * @name isNotNaN
  4349. * @param {Mixed} value
  4350. * @param {String} message
  4351. * @namespace Assert
  4352. * @api public
  4353. */
  4354. assert.isNotNaN = function (val, msg) {
  4355. new Assertion(val, msg, assert.isNotNaN, true).not.to.be.NaN;
  4356. };
  4357. /**
  4358. * ### .exists
  4359. *
  4360. * Asserts that the target is neither `null` nor `undefined`.
  4361. *
  4362. * var foo = 'hi';
  4363. *
  4364. * assert.exists(foo, 'foo is neither `null` nor `undefined`');
  4365. *
  4366. * @name exists
  4367. * @param {Mixed} value
  4368. * @param {String} message
  4369. * @namespace Assert
  4370. * @api public
  4371. */
  4372. assert.exists = function (val, msg) {
  4373. new Assertion(val, msg, assert.exists, true).to.exist;
  4374. };
  4375. /**
  4376. * ### .notExists
  4377. *
  4378. * Asserts that the target is either `null` or `undefined`.
  4379. *
  4380. * var bar = null
  4381. * , baz;
  4382. *
  4383. * assert.notExists(bar);
  4384. * assert.notExists(baz, 'baz is either null or undefined');
  4385. *
  4386. * @name notExists
  4387. * @param {Mixed} value
  4388. * @param {String} message
  4389. * @namespace Assert
  4390. * @api public
  4391. */
  4392. assert.notExists = function (val, msg) {
  4393. new Assertion(val, msg, assert.notExists, true).to.not.exist;
  4394. };
  4395. /**
  4396. * ### .isUndefined(value, [message])
  4397. *
  4398. * Asserts that `value` is `undefined`.
  4399. *
  4400. * var tea;
  4401. * assert.isUndefined(tea, 'no tea defined');
  4402. *
  4403. * @name isUndefined
  4404. * @param {Mixed} value
  4405. * @param {String} message
  4406. * @namespace Assert
  4407. * @api public
  4408. */
  4409. assert.isUndefined = function (val, msg) {
  4410. new Assertion(val, msg, assert.isUndefined, true).to.equal(undefined);
  4411. };
  4412. /**
  4413. * ### .isDefined(value, [message])
  4414. *
  4415. * Asserts that `value` is not `undefined`.
  4416. *
  4417. * var tea = 'cup of chai';
  4418. * assert.isDefined(tea, 'tea has been defined');
  4419. *
  4420. * @name isDefined
  4421. * @param {Mixed} value
  4422. * @param {String} message
  4423. * @namespace Assert
  4424. * @api public
  4425. */
  4426. assert.isDefined = function (val, msg) {
  4427. new Assertion(val, msg, assert.isDefined, true).to.not.equal(undefined);
  4428. };
  4429. /**
  4430. * ### .isFunction(value, [message])
  4431. *
  4432. * Asserts that `value` is a function.
  4433. *
  4434. * function serveTea() { return 'cup of tea'; };
  4435. * assert.isFunction(serveTea, 'great, we can have tea now');
  4436. *
  4437. * @name isFunction
  4438. * @param {Mixed} value
  4439. * @param {String} message
  4440. * @namespace Assert
  4441. * @api public
  4442. */
  4443. assert.isFunction = function (val, msg) {
  4444. new Assertion(val, msg, assert.isFunction, true).to.be.a('function');
  4445. };
  4446. /**
  4447. * ### .isNotFunction(value, [message])
  4448. *
  4449. * Asserts that `value` is _not_ a function.
  4450. *
  4451. * var serveTea = [ 'heat', 'pour', 'sip' ];
  4452. * assert.isNotFunction(serveTea, 'great, we have listed the steps');
  4453. *
  4454. * @name isNotFunction
  4455. * @param {Mixed} value
  4456. * @param {String} message
  4457. * @namespace Assert
  4458. * @api public
  4459. */
  4460. assert.isNotFunction = function (val, msg) {
  4461. new Assertion(val, msg, assert.isNotFunction, true).to.not.be.a('function');
  4462. };
  4463. /**
  4464. * ### .isObject(value, [message])
  4465. *
  4466. * Asserts that `value` is an object of type 'Object' (as revealed by `Object.prototype.toString`).
  4467. * _The assertion does not match subclassed objects._
  4468. *
  4469. * var selection = { name: 'Chai', serve: 'with spices' };
  4470. * assert.isObject(selection, 'tea selection is an object');
  4471. *
  4472. * @name isObject
  4473. * @param {Mixed} value
  4474. * @param {String} message
  4475. * @namespace Assert
  4476. * @api public
  4477. */
  4478. assert.isObject = function (val, msg) {
  4479. new Assertion(val, msg, assert.isObject, true).to.be.a('object');
  4480. };
  4481. /**
  4482. * ### .isNotObject(value, [message])
  4483. *
  4484. * Asserts that `value` is _not_ an object of type 'Object' (as revealed by `Object.prototype.toString`).
  4485. *
  4486. * var selection = 'chai'
  4487. * assert.isNotObject(selection, 'tea selection is not an object');
  4488. * assert.isNotObject(null, 'null is not an object');
  4489. *
  4490. * @name isNotObject
  4491. * @param {Mixed} value
  4492. * @param {String} message
  4493. * @namespace Assert
  4494. * @api public
  4495. */
  4496. assert.isNotObject = function (val, msg) {
  4497. new Assertion(val, msg, assert.isNotObject, true).to.not.be.a('object');
  4498. };
  4499. /**
  4500. * ### .isArray(value, [message])
  4501. *
  4502. * Asserts that `value` is an array.
  4503. *
  4504. * var menu = [ 'green', 'chai', 'oolong' ];
  4505. * assert.isArray(menu, 'what kind of tea do we want?');
  4506. *
  4507. * @name isArray
  4508. * @param {Mixed} value
  4509. * @param {String} message
  4510. * @namespace Assert
  4511. * @api public
  4512. */
  4513. assert.isArray = function (val, msg) {
  4514. new Assertion(val, msg, assert.isArray, true).to.be.an('array');
  4515. };
  4516. /**
  4517. * ### .isNotArray(value, [message])
  4518. *
  4519. * Asserts that `value` is _not_ an array.
  4520. *
  4521. * var menu = 'green|chai|oolong';
  4522. * assert.isNotArray(menu, 'what kind of tea do we want?');
  4523. *
  4524. * @name isNotArray
  4525. * @param {Mixed} value
  4526. * @param {String} message
  4527. * @namespace Assert
  4528. * @api public
  4529. */
  4530. assert.isNotArray = function (val, msg) {
  4531. new Assertion(val, msg, assert.isNotArray, true).to.not.be.an('array');
  4532. };
  4533. /**
  4534. * ### .isString(value, [message])
  4535. *
  4536. * Asserts that `value` is a string.
  4537. *
  4538. * var teaOrder = 'chai';
  4539. * assert.isString(teaOrder, 'order placed');
  4540. *
  4541. * @name isString
  4542. * @param {Mixed} value
  4543. * @param {String} message
  4544. * @namespace Assert
  4545. * @api public
  4546. */
  4547. assert.isString = function (val, msg) {
  4548. new Assertion(val, msg, assert.isString, true).to.be.a('string');
  4549. };
  4550. /**
  4551. * ### .isNotString(value, [message])
  4552. *
  4553. * Asserts that `value` is _not_ a string.
  4554. *
  4555. * var teaOrder = 4;
  4556. * assert.isNotString(teaOrder, 'order placed');
  4557. *
  4558. * @name isNotString
  4559. * @param {Mixed} value
  4560. * @param {String} message
  4561. * @namespace Assert
  4562. * @api public
  4563. */
  4564. assert.isNotString = function (val, msg) {
  4565. new Assertion(val, msg, assert.isNotString, true).to.not.be.a('string');
  4566. };
  4567. /**
  4568. * ### .isNumber(value, [message])
  4569. *
  4570. * Asserts that `value` is a number.
  4571. *
  4572. * var cups = 2;
  4573. * assert.isNumber(cups, 'how many cups');
  4574. *
  4575. * @name isNumber
  4576. * @param {Number} value
  4577. * @param {String} message
  4578. * @namespace Assert
  4579. * @api public
  4580. */
  4581. assert.isNumber = function (val, msg) {
  4582. new Assertion(val, msg, assert.isNumber, true).to.be.a('number');
  4583. };
  4584. /**
  4585. * ### .isNotNumber(value, [message])
  4586. *
  4587. * Asserts that `value` is _not_ a number.
  4588. *
  4589. * var cups = '2 cups please';
  4590. * assert.isNotNumber(cups, 'how many cups');
  4591. *
  4592. * @name isNotNumber
  4593. * @param {Mixed} value
  4594. * @param {String} message
  4595. * @namespace Assert
  4596. * @api public
  4597. */
  4598. assert.isNotNumber = function (val, msg) {
  4599. new Assertion(val, msg, assert.isNotNumber, true).to.not.be.a('number');
  4600. };
  4601. /**
  4602. * ### .isFinite(value, [message])
  4603. *
  4604. * Asserts that `value` is a finite number. Unlike `.isNumber`, this will fail for `NaN` and `Infinity`.
  4605. *
  4606. * var cups = 2;
  4607. * assert.isFinite(cups, 'how many cups');
  4608. *
  4609. * assert.isFinite(NaN); // throws
  4610. *
  4611. * @name isFinite
  4612. * @param {Number} value
  4613. * @param {String} message
  4614. * @namespace Assert
  4615. * @api public
  4616. */
  4617. assert.isFinite = function (val, msg) {
  4618. new Assertion(val, msg, assert.isFinite, true).to.be.finite;
  4619. };
  4620. /**
  4621. * ### .isBoolean(value, [message])
  4622. *
  4623. * Asserts that `value` is a boolean.
  4624. *
  4625. * var teaReady = true
  4626. * , teaServed = false;
  4627. *
  4628. * assert.isBoolean(teaReady, 'is the tea ready');
  4629. * assert.isBoolean(teaServed, 'has tea been served');
  4630. *
  4631. * @name isBoolean
  4632. * @param {Mixed} value
  4633. * @param {String} message
  4634. * @namespace Assert
  4635. * @api public
  4636. */
  4637. assert.isBoolean = function (val, msg) {
  4638. new Assertion(val, msg, assert.isBoolean, true).to.be.a('boolean');
  4639. };
  4640. /**
  4641. * ### .isNotBoolean(value, [message])
  4642. *
  4643. * Asserts that `value` is _not_ a boolean.
  4644. *
  4645. * var teaReady = 'yep'
  4646. * , teaServed = 'nope';
  4647. *
  4648. * assert.isNotBoolean(teaReady, 'is the tea ready');
  4649. * assert.isNotBoolean(teaServed, 'has tea been served');
  4650. *
  4651. * @name isNotBoolean
  4652. * @param {Mixed} value
  4653. * @param {String} message
  4654. * @namespace Assert
  4655. * @api public
  4656. */
  4657. assert.isNotBoolean = function (val, msg) {
  4658. new Assertion(val, msg, assert.isNotBoolean, true).to.not.be.a('boolean');
  4659. };
  4660. /**
  4661. * ### .typeOf(value, name, [message])
  4662. *
  4663. * Asserts that `value`'s type is `name`, as determined by
  4664. * `Object.prototype.toString`.
  4665. *
  4666. * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
  4667. * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
  4668. * assert.typeOf('tea', 'string', 'we have a string');
  4669. * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
  4670. * assert.typeOf(null, 'null', 'we have a null');
  4671. * assert.typeOf(undefined, 'undefined', 'we have an undefined');
  4672. *
  4673. * @name typeOf
  4674. * @param {Mixed} value
  4675. * @param {String} name
  4676. * @param {String} message
  4677. * @namespace Assert
  4678. * @api public
  4679. */
  4680. assert.typeOf = function (val, type, msg) {
  4681. new Assertion(val, msg, assert.typeOf, true).to.be.a(type);
  4682. };
  4683. /**
  4684. * ### .notTypeOf(value, name, [message])
  4685. *
  4686. * Asserts that `value`'s type is _not_ `name`, as determined by
  4687. * `Object.prototype.toString`.
  4688. *
  4689. * assert.notTypeOf('tea', 'number', 'strings are not numbers');
  4690. *
  4691. * @name notTypeOf
  4692. * @param {Mixed} value
  4693. * @param {String} typeof name
  4694. * @param {String} message
  4695. * @namespace Assert
  4696. * @api public
  4697. */
  4698. assert.notTypeOf = function (val, type, msg) {
  4699. new Assertion(val, msg, assert.notTypeOf, true).to.not.be.a(type);
  4700. };
  4701. /**
  4702. * ### .instanceOf(object, constructor, [message])
  4703. *
  4704. * Asserts that `value` is an instance of `constructor`.
  4705. *
  4706. * var Tea = function (name) { this.name = name; }
  4707. * , chai = new Tea('chai');
  4708. *
  4709. * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
  4710. *
  4711. * @name instanceOf
  4712. * @param {Object} object
  4713. * @param {Constructor} constructor
  4714. * @param {String} message
  4715. * @namespace Assert
  4716. * @api public
  4717. */
  4718. assert.instanceOf = function (val, type, msg) {
  4719. new Assertion(val, msg, assert.instanceOf, true).to.be.instanceOf(type);
  4720. };
  4721. /**
  4722. * ### .notInstanceOf(object, constructor, [message])
  4723. *
  4724. * Asserts `value` is not an instance of `constructor`.
  4725. *
  4726. * var Tea = function (name) { this.name = name; }
  4727. * , chai = new String('chai');
  4728. *
  4729. * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
  4730. *
  4731. * @name notInstanceOf
  4732. * @param {Object} object
  4733. * @param {Constructor} constructor
  4734. * @param {String} message
  4735. * @namespace Assert
  4736. * @api public
  4737. */
  4738. assert.notInstanceOf = function (val, type, msg) {
  4739. new Assertion(val, msg, assert.notInstanceOf, true)
  4740. .to.not.be.instanceOf(type);
  4741. };
  4742. /**
  4743. * ### .include(haystack, needle, [message])
  4744. *
  4745. * Asserts that `haystack` includes `needle`. Can be used to assert the
  4746. * inclusion of a value in an array, a substring in a string, or a subset of
  4747. * properties in an object.
  4748. *
  4749. * assert.include([1,2,3], 2, 'array contains value');
  4750. * assert.include('foobar', 'foo', 'string contains substring');
  4751. * assert.include({ foo: 'bar', hello: 'universe' }, { foo: 'bar' }, 'object contains property');
  4752. *
  4753. * Strict equality (===) is used. When asserting the inclusion of a value in
  4754. * an array, the array is searched for an element that's strictly equal to the
  4755. * given value. When asserting a subset of properties in an object, the object
  4756. * is searched for the given property keys, checking that each one is present
  4757. * and strictly equal to the given property value. For instance:
  4758. *
  4759. * var obj1 = {a: 1}
  4760. * , obj2 = {b: 2};
  4761. * assert.include([obj1, obj2], obj1);
  4762. * assert.include({foo: obj1, bar: obj2}, {foo: obj1});
  4763. * assert.include({foo: obj1, bar: obj2}, {foo: obj1, bar: obj2});
  4764. *
  4765. * @name include
  4766. * @param {Array|String} haystack
  4767. * @param {Mixed} needle
  4768. * @param {String} message
  4769. * @namespace Assert
  4770. * @api public
  4771. */
  4772. assert.include = function (exp, inc, msg) {
  4773. new Assertion(exp, msg, assert.include, true).include(inc);
  4774. };
  4775. /**
  4776. * ### .notInclude(haystack, needle, [message])
  4777. *
  4778. * Asserts that `haystack` does not include `needle`. Can be used to assert
  4779. * the absence of a value in an array, a substring in a string, or a subset of
  4780. * properties in an object.
  4781. *
  4782. * assert.notInclude([1,2,3], 4, "array doesn't contain value");
  4783. * assert.notInclude('foobar', 'baz', "string doesn't contain substring");
  4784. * assert.notInclude({ foo: 'bar', hello: 'universe' }, { foo: 'baz' }, 'object doesn't contain property');
  4785. *
  4786. * Strict equality (===) is used. When asserting the absence of a value in an
  4787. * array, the array is searched to confirm the absence of an element that's
  4788. * strictly equal to the given value. When asserting a subset of properties in
  4789. * an object, the object is searched to confirm that at least one of the given
  4790. * property keys is either not present or not strictly equal to the given
  4791. * property value. For instance:
  4792. *
  4793. * var obj1 = {a: 1}
  4794. * , obj2 = {b: 2};
  4795. * assert.notInclude([obj1, obj2], {a: 1});
  4796. * assert.notInclude({foo: obj1, bar: obj2}, {foo: {a: 1}});
  4797. * assert.notInclude({foo: obj1, bar: obj2}, {foo: obj1, bar: {b: 2}});
  4798. *
  4799. * @name notInclude
  4800. * @param {Array|String} haystack
  4801. * @param {Mixed} needle
  4802. * @param {String} message
  4803. * @namespace Assert
  4804. * @api public
  4805. */
  4806. assert.notInclude = function (exp, inc, msg) {
  4807. new Assertion(exp, msg, assert.notInclude, true).not.include(inc);
  4808. };
  4809. /**
  4810. * ### .deepInclude(haystack, needle, [message])
  4811. *
  4812. * Asserts that `haystack` includes `needle`. Can be used to assert the
  4813. * inclusion 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.deepInclude([obj1, obj2], {a: 1});
  4819. * assert.deepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}});
  4820. * assert.deepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}, bar: {b: 2}});
  4821. *
  4822. * @name deepInclude
  4823. * @param {Array|String} haystack
  4824. * @param {Mixed} needle
  4825. * @param {String} message
  4826. * @namespace Assert
  4827. * @api public
  4828. */
  4829. assert.deepInclude = function (exp, inc, msg) {
  4830. new Assertion(exp, msg, assert.deepInclude, true).deep.include(inc);
  4831. };
  4832. /**
  4833. * ### .notDeepInclude(haystack, needle, [message])
  4834. *
  4835. * Asserts that `haystack` does not include `needle`. Can be used to assert
  4836. * the absence of a value in an array or a subset of properties in an object.
  4837. * Deep equality is used.
  4838. *
  4839. * var obj1 = {a: 1}
  4840. * , obj2 = {b: 2};
  4841. * assert.notDeepInclude([obj1, obj2], {a: 9});
  4842. * assert.notDeepInclude({foo: obj1, bar: obj2}, {foo: {a: 9}});
  4843. * assert.notDeepInclude({foo: obj1, bar: obj2}, {foo: {a: 1}, bar: {b: 9}});
  4844. *
  4845. * @name notDeepInclude
  4846. * @param {Array|String} haystack
  4847. * @param {Mixed} needle
  4848. * @param {String} message
  4849. * @namespace Assert
  4850. * @api public
  4851. */
  4852. assert.notDeepInclude = function (exp, inc, msg) {
  4853. new Assertion(exp, msg, assert.notDeepInclude, true).not.deep.include(inc);
  4854. };
  4855. /**
  4856. * ### .nestedInclude(haystack, needle, [message])
  4857. *
  4858. * Asserts that 'haystack' includes 'needle'.
  4859. * Can be used to assert the inclusion 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.nestedInclude({'.a': {'b': 'x'}}, {'\\.a.[b]': 'x'});
  4866. * assert.nestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'x'});
  4867. *
  4868. * @name nestedInclude
  4869. * @param {Object} haystack
  4870. * @param {Object} needle
  4871. * @param {String} message
  4872. * @namespace Assert
  4873. * @api public
  4874. */
  4875. assert.nestedInclude = function (exp, inc, msg) {
  4876. new Assertion(exp, msg, assert.nestedInclude, true).nested.include(inc);
  4877. };
  4878. /**
  4879. * ### .notNestedInclude(haystack, needle, [message])
  4880. *
  4881. * Asserts that 'haystack' does not include 'needle'.
  4882. * Can be used to assert the absence of a subset of properties in an
  4883. * object.
  4884. * Enables the use of dot- and bracket-notation for referencing nested
  4885. * properties.
  4886. * '[]' and '.' in property names can be escaped using double backslashes.
  4887. *
  4888. * assert.notNestedInclude({'.a': {'b': 'x'}}, {'\\.a.b': 'y'});
  4889. * assert.notNestedInclude({'a': {'[b]': 'x'}}, {'a.\\[b\\]': 'y'});
  4890. *
  4891. * @name notNestedInclude
  4892. * @param {Object} haystack
  4893. * @param {Object} needle
  4894. * @param {String} message
  4895. * @namespace Assert
  4896. * @api public
  4897. */
  4898. assert.notNestedInclude = function (exp, inc, msg) {
  4899. new Assertion(exp, msg, assert.notNestedInclude, true)
  4900. .not.nested.include(inc);
  4901. };
  4902. /**
  4903. * ### .deepNestedInclude(haystack, needle, [message])
  4904. *
  4905. * Asserts that 'haystack' includes 'needle'.
  4906. * Can be used to assert the inclusion of a subset of properties in an
  4907. * object while checking for deep equality.
  4908. * Enables the use of dot- and bracket-notation for referencing nested
  4909. * properties.
  4910. * '[]' and '.' in property names can be escaped using double backslashes.
  4911. *
  4912. * assert.deepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {x: 1}});
  4913. * assert.deepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {x: 1}});
  4914. *
  4915. * @name deepNestedInclude
  4916. * @param {Object} haystack
  4917. * @param {Object} needle
  4918. * @param {String} message
  4919. * @namespace Assert
  4920. * @api public
  4921. */
  4922. assert.deepNestedInclude = function(exp, inc, msg) {
  4923. new Assertion(exp, msg, assert.deepNestedInclude, true)
  4924. .deep.nested.include(inc);
  4925. };
  4926. /**
  4927. * ### .notDeepNestedInclude(haystack, needle, [message])
  4928. *
  4929. * Asserts that 'haystack' does not include 'needle'.
  4930. * Can be used to assert the absence of a subset of properties in an
  4931. * object while checking for deep equality.
  4932. * Enables the use of dot- and bracket-notation for referencing nested
  4933. * properties.
  4934. * '[]' and '.' in property names can be escaped using double backslashes.
  4935. *
  4936. * assert.notDeepNestedInclude({a: {b: [{x: 1}]}}, {'a.b[0]': {y: 1}})
  4937. * assert.notDeepNestedInclude({'.a': {'[b]': {x: 1}}}, {'\\.a.\\[b\\]': {y: 2}});
  4938. *
  4939. * @name notDeepNestedInclude
  4940. * @param {Object} haystack
  4941. * @param {Object} needle
  4942. * @param {String} message
  4943. * @namespace Assert
  4944. * @api public
  4945. */
  4946. assert.notDeepNestedInclude = function(exp, inc, msg) {
  4947. new Assertion(exp, msg, assert.notDeepNestedInclude, true)
  4948. .not.deep.nested.include(inc);
  4949. };
  4950. /**
  4951. * ### .ownInclude(haystack, needle, [message])
  4952. *
  4953. * Asserts that 'haystack' includes 'needle'.
  4954. * Can be used to assert the inclusion of a subset of properties in an
  4955. * object while ignoring inherited properties.
  4956. *
  4957. * assert.ownInclude({ a: 1 }, { a: 1 });
  4958. *
  4959. * @name ownInclude
  4960. * @param {Object} haystack
  4961. * @param {Object} needle
  4962. * @param {String} message
  4963. * @namespace Assert
  4964. * @api public
  4965. */
  4966. assert.ownInclude = function(exp, inc, msg) {
  4967. new Assertion(exp, msg, assert.ownInclude, true).own.include(inc);
  4968. };
  4969. /**
  4970. * ### .notOwnInclude(haystack, needle, [message])
  4971. *
  4972. * Asserts that 'haystack' includes 'needle'.
  4973. * Can be used to assert the absence of a subset of properties in an
  4974. * object while ignoring inherited properties.
  4975. *
  4976. * Object.prototype.b = 2;
  4977. *
  4978. * assert.notOwnInclude({ a: 1 }, { b: 2 });
  4979. *
  4980. * @name notOwnInclude
  4981. * @param {Object} haystack
  4982. * @param {Object} needle
  4983. * @param {String} message
  4984. * @namespace Assert
  4985. * @api public
  4986. */
  4987. assert.notOwnInclude = function(exp, inc, msg) {
  4988. new Assertion(exp, msg, assert.notOwnInclude, true).not.own.include(inc);
  4989. };
  4990. /**
  4991. * ### .deepOwnInclude(haystack, needle, [message])
  4992. *
  4993. * Asserts that 'haystack' includes 'needle'.
  4994. * Can be used to assert the inclusion of a subset of properties in an
  4995. * object while ignoring inherited properties and checking for deep equality.
  4996. *
  4997. * assert.deepOwnInclude({a: {b: 2}}, {a: {b: 2}});
  4998. *
  4999. * @name deepOwnInclude
  5000. * @param {Object} haystack
  5001. * @param {Object} needle
  5002. * @param {String} message
  5003. * @namespace Assert
  5004. * @api public
  5005. */
  5006. assert.deepOwnInclude = function(exp, inc, msg) {
  5007. new Assertion(exp, msg, assert.deepOwnInclude, true)
  5008. .deep.own.include(inc);
  5009. };
  5010. /**
  5011. * ### .notDeepOwnInclude(haystack, needle, [message])
  5012. *
  5013. * Asserts that 'haystack' includes 'needle'.
  5014. * Can be used to assert the absence of a subset of properties in an
  5015. * object while ignoring inherited properties and checking for deep equality.
  5016. *
  5017. * assert.notDeepOwnInclude({a: {b: 2}}, {a: {c: 3}});
  5018. *
  5019. * @name notDeepOwnInclude
  5020. * @param {Object} haystack
  5021. * @param {Object} needle
  5022. * @param {String} message
  5023. * @namespace Assert
  5024. * @api public
  5025. */
  5026. assert.notDeepOwnInclude = function(exp, inc, msg) {
  5027. new Assertion(exp, msg, assert.notDeepOwnInclude, true)
  5028. .not.deep.own.include(inc);
  5029. };
  5030. /**
  5031. * ### .match(value, regexp, [message])
  5032. *
  5033. * Asserts that `value` matches the regular expression `regexp`.
  5034. *
  5035. * assert.match('foobar', /^foo/, 'regexp matches');
  5036. *
  5037. * @name match
  5038. * @param {Mixed} value
  5039. * @param {RegExp} regexp
  5040. * @param {String} message
  5041. * @namespace Assert
  5042. * @api public
  5043. */
  5044. assert.match = function (exp, re, msg) {
  5045. new Assertion(exp, msg, assert.match, true).to.match(re);
  5046. };
  5047. /**
  5048. * ### .notMatch(value, regexp, [message])
  5049. *
  5050. * Asserts that `value` does not match the regular expression `regexp`.
  5051. *
  5052. * assert.notMatch('foobar', /^foo/, 'regexp does not match');
  5053. *
  5054. * @name notMatch
  5055. * @param {Mixed} value
  5056. * @param {RegExp} regexp
  5057. * @param {String} message
  5058. * @namespace Assert
  5059. * @api public
  5060. */
  5061. assert.notMatch = function (exp, re, msg) {
  5062. new Assertion(exp, msg, assert.notMatch, true).to.not.match(re);
  5063. };
  5064. /**
  5065. * ### .property(object, property, [message])
  5066. *
  5067. * Asserts that `object` has a direct or inherited property named by
  5068. * `property`.
  5069. *
  5070. * assert.property({ tea: { green: 'matcha' }}, 'tea');
  5071. * assert.property({ tea: { green: 'matcha' }}, 'toString');
  5072. *
  5073. * @name property
  5074. * @param {Object} object
  5075. * @param {String} property
  5076. * @param {String} message
  5077. * @namespace Assert
  5078. * @api public
  5079. */
  5080. assert.property = function (obj, prop, msg) {
  5081. new Assertion(obj, msg, assert.property, true).to.have.property(prop);
  5082. };
  5083. /**
  5084. * ### .notProperty(object, property, [message])
  5085. *
  5086. * Asserts that `object` does _not_ have a direct or inherited property named
  5087. * by `property`.
  5088. *
  5089. * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
  5090. *
  5091. * @name notProperty
  5092. * @param {Object} object
  5093. * @param {String} property
  5094. * @param {String} message
  5095. * @namespace Assert
  5096. * @api public
  5097. */
  5098. assert.notProperty = function (obj, prop, msg) {
  5099. new Assertion(obj, msg, assert.notProperty, true)
  5100. .to.not.have.property(prop);
  5101. };
  5102. /**
  5103. * ### .propertyVal(object, property, value, [message])
  5104. *
  5105. * Asserts that `object` has a direct or inherited property named by
  5106. * `property` with a value given by `value`. Uses a strict equality check
  5107. * (===).
  5108. *
  5109. * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
  5110. *
  5111. * @name propertyVal
  5112. * @param {Object} object
  5113. * @param {String} property
  5114. * @param {Mixed} value
  5115. * @param {String} message
  5116. * @namespace Assert
  5117. * @api public
  5118. */
  5119. assert.propertyVal = function (obj, prop, val, msg) {
  5120. new Assertion(obj, msg, assert.propertyVal, true)
  5121. .to.have.property(prop, val);
  5122. };
  5123. /**
  5124. * ### .notPropertyVal(object, property, value, [message])
  5125. *
  5126. * Asserts that `object` does _not_ have a direct or inherited property named
  5127. * by `property` with value given by `value`. Uses a strict equality check
  5128. * (===).
  5129. *
  5130. * assert.notPropertyVal({ tea: 'is good' }, 'tea', 'is bad');
  5131. * assert.notPropertyVal({ tea: 'is good' }, 'coffee', 'is good');
  5132. *
  5133. * @name notPropertyVal
  5134. * @param {Object} object
  5135. * @param {String} property
  5136. * @param {Mixed} value
  5137. * @param {String} message
  5138. * @namespace Assert
  5139. * @api public
  5140. */
  5141. assert.notPropertyVal = function (obj, prop, val, msg) {
  5142. new Assertion(obj, msg, assert.notPropertyVal, true)
  5143. .to.not.have.property(prop, val);
  5144. };
  5145. /**
  5146. * ### .deepPropertyVal(object, property, value, [message])
  5147. *
  5148. * Asserts that `object` has a direct or inherited property named by
  5149. * `property` with a value given by `value`. Uses a deep equality check.
  5150. *
  5151. * assert.deepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'matcha' });
  5152. *
  5153. * @name deepPropertyVal
  5154. * @param {Object} object
  5155. * @param {String} property
  5156. * @param {Mixed} value
  5157. * @param {String} message
  5158. * @namespace Assert
  5159. * @api public
  5160. */
  5161. assert.deepPropertyVal = function (obj, prop, val, msg) {
  5162. new Assertion(obj, msg, assert.deepPropertyVal, true)
  5163. .to.have.deep.property(prop, val);
  5164. };
  5165. /**
  5166. * ### .notDeepPropertyVal(object, property, value, [message])
  5167. *
  5168. * Asserts that `object` does _not_ have a direct or inherited property named
  5169. * by `property` with value given by `value`. Uses a deep equality check.
  5170. *
  5171. * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { black: 'matcha' });
  5172. * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'oolong' });
  5173. * assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'coffee', { green: 'matcha' });
  5174. *
  5175. * @name notDeepPropertyVal
  5176. * @param {Object} object
  5177. * @param {String} property
  5178. * @param {Mixed} value
  5179. * @param {String} message
  5180. * @namespace Assert
  5181. * @api public
  5182. */
  5183. assert.notDeepPropertyVal = function (obj, prop, val, msg) {
  5184. new Assertion(obj, msg, assert.notDeepPropertyVal, true)
  5185. .to.not.have.deep.property(prop, val);
  5186. };
  5187. /**
  5188. * ### .ownProperty(object, property, [message])
  5189. *
  5190. * Asserts that `object` has a direct property named by `property`. Inherited
  5191. * properties aren't checked.
  5192. *
  5193. * assert.ownProperty({ tea: { green: 'matcha' }}, 'tea');
  5194. *
  5195. * @name ownProperty
  5196. * @param {Object} object
  5197. * @param {String} property
  5198. * @param {String} message
  5199. * @api public
  5200. */
  5201. assert.ownProperty = function (obj, prop, msg) {
  5202. new Assertion(obj, msg, assert.ownProperty, true)
  5203. .to.have.own.property(prop);
  5204. };
  5205. /**
  5206. * ### .notOwnProperty(object, property, [message])
  5207. *
  5208. * Asserts that `object` does _not_ have a direct property named by
  5209. * `property`. Inherited properties aren't checked.
  5210. *
  5211. * assert.notOwnProperty({ tea: { green: 'matcha' }}, 'coffee');
  5212. * assert.notOwnProperty({}, 'toString');
  5213. *
  5214. * @name notOwnProperty
  5215. * @param {Object} object
  5216. * @param {String} property
  5217. * @param {String} message
  5218. * @api public
  5219. */
  5220. assert.notOwnProperty = function (obj, prop, msg) {
  5221. new Assertion(obj, msg, assert.notOwnProperty, true)
  5222. .to.not.have.own.property(prop);
  5223. };
  5224. /**
  5225. * ### .ownPropertyVal(object, property, value, [message])
  5226. *
  5227. * Asserts that `object` has a direct property named by `property` and a value
  5228. * equal to the provided `value`. Uses a strict equality check (===).
  5229. * Inherited properties aren't checked.
  5230. *
  5231. * assert.ownPropertyVal({ coffee: 'is good'}, 'coffee', 'is good');
  5232. *
  5233. * @name ownPropertyVal
  5234. * @param {Object} object
  5235. * @param {String} property
  5236. * @param {Mixed} value
  5237. * @param {String} message
  5238. * @api public
  5239. */
  5240. assert.ownPropertyVal = function (obj, prop, value, msg) {
  5241. new Assertion(obj, msg, assert.ownPropertyVal, true)
  5242. .to.have.own.property(prop, value);
  5243. };
  5244. /**
  5245. * ### .notOwnPropertyVal(object, property, value, [message])
  5246. *
  5247. * Asserts that `object` does _not_ have a direct property named by `property`
  5248. * with a value equal to the provided `value`. Uses a strict equality check
  5249. * (===). Inherited properties aren't checked.
  5250. *
  5251. * assert.notOwnPropertyVal({ tea: 'is better'}, 'tea', 'is worse');
  5252. * assert.notOwnPropertyVal({}, 'toString', Object.prototype.toString);
  5253. *
  5254. * @name notOwnPropertyVal
  5255. * @param {Object} object
  5256. * @param {String} property
  5257. * @param {Mixed} value
  5258. * @param {String} message
  5259. * @api public
  5260. */
  5261. assert.notOwnPropertyVal = function (obj, prop, value, msg) {
  5262. new Assertion(obj, msg, assert.notOwnPropertyVal, true)
  5263. .to.not.have.own.property(prop, value);
  5264. };
  5265. /**
  5266. * ### .deepOwnPropertyVal(object, property, value, [message])
  5267. *
  5268. * Asserts that `object` has a direct property named by `property` and a value
  5269. * equal to the provided `value`. Uses a deep equality check. Inherited
  5270. * properties aren't checked.
  5271. *
  5272. * assert.deepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'matcha' });
  5273. *
  5274. * @name deepOwnPropertyVal
  5275. * @param {Object} object
  5276. * @param {String} property
  5277. * @param {Mixed} value
  5278. * @param {String} message
  5279. * @api public
  5280. */
  5281. assert.deepOwnPropertyVal = function (obj, prop, value, msg) {
  5282. new Assertion(obj, msg, assert.deepOwnPropertyVal, true)
  5283. .to.have.deep.own.property(prop, value);
  5284. };
  5285. /**
  5286. * ### .notDeepOwnPropertyVal(object, property, value, [message])
  5287. *
  5288. * Asserts that `object` does _not_ have a direct property named by `property`
  5289. * with a value equal to the provided `value`. Uses a deep equality check.
  5290. * Inherited properties aren't checked.
  5291. *
  5292. * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { black: 'matcha' });
  5293. * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'oolong' });
  5294. * assert.notDeepOwnPropertyVal({ tea: { green: 'matcha' } }, 'coffee', { green: 'matcha' });
  5295. * assert.notDeepOwnPropertyVal({}, 'toString', Object.prototype.toString);
  5296. *
  5297. * @name notDeepOwnPropertyVal
  5298. * @param {Object} object
  5299. * @param {String} property
  5300. * @param {Mixed} value
  5301. * @param {String} message
  5302. * @api public
  5303. */
  5304. assert.notDeepOwnPropertyVal = function (obj, prop, value, msg) {
  5305. new Assertion(obj, msg, assert.notDeepOwnPropertyVal, true)
  5306. .to.not.have.deep.own.property(prop, value);
  5307. };
  5308. /**
  5309. * ### .nestedProperty(object, property, [message])
  5310. *
  5311. * Asserts that `object` has a direct or inherited property named by
  5312. * `property`, which can be a string using dot- and bracket-notation for
  5313. * nested reference.
  5314. *
  5315. * assert.nestedProperty({ tea: { green: 'matcha' }}, 'tea.green');
  5316. *
  5317. * @name nestedProperty
  5318. * @param {Object} object
  5319. * @param {String} property
  5320. * @param {String} message
  5321. * @namespace Assert
  5322. * @api public
  5323. */
  5324. assert.nestedProperty = function (obj, prop, msg) {
  5325. new Assertion(obj, msg, assert.nestedProperty, true)
  5326. .to.have.nested.property(prop);
  5327. };
  5328. /**
  5329. * ### .notNestedProperty(object, property, [message])
  5330. *
  5331. * Asserts that `object` does _not_ have a property named by `property`, which
  5332. * can be a string using dot- and bracket-notation for nested reference. The
  5333. * property cannot exist on the object nor anywhere in its prototype chain.
  5334. *
  5335. * assert.notNestedProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
  5336. *
  5337. * @name notNestedProperty
  5338. * @param {Object} object
  5339. * @param {String} property
  5340. * @param {String} message
  5341. * @namespace Assert
  5342. * @api public
  5343. */
  5344. assert.notNestedProperty = function (obj, prop, msg) {
  5345. new Assertion(obj, msg, assert.notNestedProperty, true)
  5346. .to.not.have.nested.property(prop);
  5347. };
  5348. /**
  5349. * ### .nestedPropertyVal(object, property, value, [message])
  5350. *
  5351. * Asserts that `object` has a property named by `property` with value given
  5352. * by `value`. `property` can use dot- and bracket-notation for nested
  5353. * reference. Uses a strict equality check (===).
  5354. *
  5355. * assert.nestedPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
  5356. *
  5357. * @name nestedPropertyVal
  5358. * @param {Object} object
  5359. * @param {String} property
  5360. * @param {Mixed} value
  5361. * @param {String} message
  5362. * @namespace Assert
  5363. * @api public
  5364. */
  5365. assert.nestedPropertyVal = function (obj, prop, val, msg) {
  5366. new Assertion(obj, msg, assert.nestedPropertyVal, true)
  5367. .to.have.nested.property(prop, val);
  5368. };
  5369. /**
  5370. * ### .notNestedPropertyVal(object, property, value, [message])
  5371. *
  5372. * Asserts that `object` does _not_ have a property named by `property` with
  5373. * value given by `value`. `property` can use dot- and bracket-notation for
  5374. * nested reference. Uses a strict equality check (===).
  5375. *
  5376. * assert.notNestedPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
  5377. * assert.notNestedPropertyVal({ tea: { green: 'matcha' }}, 'coffee.green', 'matcha');
  5378. *
  5379. * @name notNestedPropertyVal
  5380. * @param {Object} object
  5381. * @param {String} property
  5382. * @param {Mixed} value
  5383. * @param {String} message
  5384. * @namespace Assert
  5385. * @api public
  5386. */
  5387. assert.notNestedPropertyVal = function (obj, prop, val, msg) {
  5388. new Assertion(obj, msg, assert.notNestedPropertyVal, true)
  5389. .to.not.have.nested.property(prop, val);
  5390. };
  5391. /**
  5392. * ### .deepNestedPropertyVal(object, property, value, [message])
  5393. *
  5394. * Asserts that `object` has a property named by `property` with a value given
  5395. * by `value`. `property` can use dot- and bracket-notation for nested
  5396. * reference. Uses a deep equality check.
  5397. *
  5398. * assert.deepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { matcha: 'yum' });
  5399. *
  5400. * @name deepNestedPropertyVal
  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.deepNestedPropertyVal = function (obj, prop, val, msg) {
  5409. new Assertion(obj, msg, assert.deepNestedPropertyVal, true)
  5410. .to.have.deep.nested.property(prop, val);
  5411. };
  5412. /**
  5413. * ### .notDeepNestedPropertyVal(object, property, value, [message])
  5414. *
  5415. * Asserts that `object` does _not_ have a property named by `property` with
  5416. * value given by `value`. `property` can use dot- and bracket-notation for
  5417. * nested reference. Uses a deep equality check.
  5418. *
  5419. * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { oolong: 'yum' });
  5420. * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { matcha: 'yuck' });
  5421. * assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.black', { matcha: 'yum' });
  5422. *
  5423. * @name notDeepNestedPropertyVal
  5424. * @param {Object} object
  5425. * @param {String} property
  5426. * @param {Mixed} value
  5427. * @param {String} message
  5428. * @namespace Assert
  5429. * @api public
  5430. */
  5431. assert.notDeepNestedPropertyVal = function (obj, prop, val, msg) {
  5432. new Assertion(obj, msg, assert.notDeepNestedPropertyVal, true)
  5433. .to.not.have.deep.nested.property(prop, val);
  5434. }
  5435. /**
  5436. * ### .lengthOf(object, length, [message])
  5437. *
  5438. * Asserts that `object` has a `length` or `size` with the expected value.
  5439. *
  5440. * assert.lengthOf([1,2,3], 3, 'array has length of 3');
  5441. * assert.lengthOf('foobar', 6, 'string has length of 6');
  5442. * assert.lengthOf(new Set([1,2,3]), 3, 'set has size of 3');
  5443. * assert.lengthOf(new Map([['a',1],['b',2],['c',3]]), 3, 'map has size of 3');
  5444. *
  5445. * @name lengthOf
  5446. * @param {Mixed} object
  5447. * @param {Number} length
  5448. * @param {String} message
  5449. * @namespace Assert
  5450. * @api public
  5451. */
  5452. assert.lengthOf = function (exp, len, msg) {
  5453. new Assertion(exp, msg, assert.lengthOf, true).to.have.lengthOf(len);
  5454. };
  5455. /**
  5456. * ### .hasAnyKeys(object, [keys], [message])
  5457. *
  5458. * Asserts that `object` has at least one of the `keys` provided.
  5459. * You can also provide a single object instead of a `keys` array and its keys
  5460. * will be used as the expected set of keys.
  5461. *
  5462. * assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'iDontExist', 'baz']);
  5463. * assert.hasAnyKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, iDontExist: 99, baz: 1337});
  5464. * assert.hasAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
  5465. * assert.hasAnyKeys(new Set([{foo: 'bar'}, 'anotherKey']), [{foo: 'bar'}, 'anotherKey']);
  5466. *
  5467. * @name hasAnyKeys
  5468. * @param {Mixed} object
  5469. * @param {Array|Object} keys
  5470. * @param {String} message
  5471. * @namespace Assert
  5472. * @api public
  5473. */
  5474. assert.hasAnyKeys = function (obj, keys, msg) {
  5475. new Assertion(obj, msg, assert.hasAnyKeys, true).to.have.any.keys(keys);
  5476. }
  5477. /**
  5478. * ### .hasAllKeys(object, [keys], [message])
  5479. *
  5480. * Asserts that `object` has all and only all of the `keys` provided.
  5481. * You can also provide a single object instead of a `keys` array and its keys
  5482. * will be used as the expected set of keys.
  5483. *
  5484. * assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']);
  5485. * assert.hasAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337]);
  5486. * assert.hasAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
  5487. * assert.hasAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}, 'anotherKey']);
  5488. *
  5489. * @name hasAllKeys
  5490. * @param {Mixed} object
  5491. * @param {String[]} keys
  5492. * @param {String} message
  5493. * @namespace Assert
  5494. * @api public
  5495. */
  5496. assert.hasAllKeys = function (obj, keys, msg) {
  5497. new Assertion(obj, msg, assert.hasAllKeys, true).to.have.all.keys(keys);
  5498. }
  5499. /**
  5500. * ### .containsAllKeys(object, [keys], [message])
  5501. *
  5502. * Asserts that `object` has all of the `keys` provided but may have more keys not listed.
  5503. * You can also provide a single object instead of a `keys` array and its keys
  5504. * will be used as the expected set of keys.
  5505. *
  5506. * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'baz']);
  5507. * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, ['foo', 'bar', 'baz']);
  5508. * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, baz: 1337});
  5509. * assert.containsAllKeys({foo: 1, bar: 2, baz: 3}, {foo: 30, bar: 99, baz: 1337});
  5510. * assert.containsAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}]);
  5511. * assert.containsAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{foo: 1}, 'key']);
  5512. * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}]);
  5513. * assert.containsAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{foo: 'bar'}, 'anotherKey']);
  5514. *
  5515. * @name containsAllKeys
  5516. * @param {Mixed} object
  5517. * @param {String[]} keys
  5518. * @param {String} message
  5519. * @namespace Assert
  5520. * @api public
  5521. */
  5522. assert.containsAllKeys = function (obj, keys, msg) {
  5523. new Assertion(obj, msg, assert.containsAllKeys, true)
  5524. .to.contain.all.keys(keys);
  5525. }
  5526. /**
  5527. * ### .doesNotHaveAnyKeys(object, [keys], [message])
  5528. *
  5529. * Asserts that `object` has none 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.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']);
  5534. * assert.doesNotHaveAnyKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'});
  5535. * assert.doesNotHaveAnyKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']);
  5536. * assert.doesNotHaveAnyKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{one: 'two'}, 'example']);
  5537. *
  5538. * @name doesNotHaveAnyKeys
  5539. * @param {Mixed} object
  5540. * @param {String[]} keys
  5541. * @param {String} message
  5542. * @namespace Assert
  5543. * @api public
  5544. */
  5545. assert.doesNotHaveAnyKeys = function (obj, keys, msg) {
  5546. new Assertion(obj, msg, assert.doesNotHaveAnyKeys, true)
  5547. .to.not.have.any.keys(keys);
  5548. }
  5549. /**
  5550. * ### .doesNotHaveAllKeys(object, [keys], [message])
  5551. *
  5552. * Asserts that `object` does not have at least one of the `keys` provided.
  5553. * You can also provide a single object instead of a `keys` array and its keys
  5554. * will be used as the expected set of keys.
  5555. *
  5556. * assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, ['one', 'two', 'example']);
  5557. * assert.doesNotHaveAllKeys({foo: 1, bar: 2, baz: 3}, {one: 1, two: 2, example: 'foo'});
  5558. * assert.doesNotHaveAllKeys(new Map([[{foo: 1}, 'bar'], ['key', 'value']]), [{one: 'two'}, 'example']);
  5559. * assert.doesNotHaveAllKeys(new Set([{foo: 'bar'}, 'anotherKey'], [{one: 'two'}, 'example']);
  5560. *
  5561. * @name doesNotHaveAllKeys
  5562. * @param {Mixed} object
  5563. * @param {String[]} keys
  5564. * @param {String} message
  5565. * @namespace Assert
  5566. * @api public
  5567. */
  5568. assert.doesNotHaveAllKeys = function (obj, keys, msg) {
  5569. new Assertion(obj, msg, assert.doesNotHaveAllKeys, true)
  5570. .to.not.have.all.keys(keys);
  5571. }
  5572. /**
  5573. * ### .hasAnyDeepKeys(object, [keys], [message])
  5574. *
  5575. * Asserts that `object` has at least one of the `keys` provided.
  5576. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5577. * a deep comparison.
  5578. * You can also provide a single object instead of a `keys` array and its keys
  5579. * will be used as the expected set of keys.
  5580. *
  5581. * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {one: 'one'});
  5582. * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), [{one: 'one'}, {two: 'two'}]);
  5583. * assert.hasAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
  5584. * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {one: 'one'});
  5585. * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {three: 'three'}]);
  5586. * assert.hasAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
  5587. *
  5588. * @name hasAnyDeepKeys
  5589. * @param {Mixed} object
  5590. * @param {Array|Object} keys
  5591. * @param {String} message
  5592. * @namespace Assert
  5593. * @api public
  5594. */
  5595. assert.hasAnyDeepKeys = function (obj, keys, msg) {
  5596. new Assertion(obj, msg, assert.hasAnyDeepKeys, true)
  5597. .to.have.any.deep.keys(keys);
  5598. }
  5599. /**
  5600. * ### .hasAllDeepKeys(object, [keys], [message])
  5601. *
  5602. * Asserts that `object` has all and only all of the `keys` provided.
  5603. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5604. * a deep comparison.
  5605. * You can also provide a single object instead of a `keys` array and its keys
  5606. * will be used as the expected set of keys.
  5607. *
  5608. * assert.hasAllDeepKeys(new Map([[{one: 'one'}, 'valueOne']]), {one: 'one'});
  5609. * assert.hasAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
  5610. * assert.hasAllDeepKeys(new Set([{one: 'one'}]), {one: 'one'});
  5611. * assert.hasAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
  5612. *
  5613. * @name hasAllDeepKeys
  5614. * @param {Mixed} object
  5615. * @param {Array|Object} keys
  5616. * @param {String} message
  5617. * @namespace Assert
  5618. * @api public
  5619. */
  5620. assert.hasAllDeepKeys = function (obj, keys, msg) {
  5621. new Assertion(obj, msg, assert.hasAllDeepKeys, true)
  5622. .to.have.all.deep.keys(keys);
  5623. }
  5624. /**
  5625. * ### .containsAllDeepKeys(object, [keys], [message])
  5626. *
  5627. * Asserts that `object` contains all of the `keys` provided.
  5628. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5629. * a deep comparison.
  5630. * You can also provide a single object instead of a `keys` array and its keys
  5631. * will be used as the expected set of keys.
  5632. *
  5633. * assert.containsAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {one: 'one'});
  5634. * assert.containsAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{one: 'one'}, {two: 'two'}]);
  5635. * assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {one: 'one'});
  5636. * assert.containsAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {two: 'two'}]);
  5637. *
  5638. * @name containsAllDeepKeys
  5639. * @param {Mixed} object
  5640. * @param {Array|Object} keys
  5641. * @param {String} message
  5642. * @namespace Assert
  5643. * @api public
  5644. */
  5645. assert.containsAllDeepKeys = function (obj, keys, msg) {
  5646. new Assertion(obj, msg, assert.containsAllDeepKeys, true)
  5647. .to.contain.all.deep.keys(keys);
  5648. }
  5649. /**
  5650. * ### .doesNotHaveAnyDeepKeys(object, [keys], [message])
  5651. *
  5652. * Asserts that `object` has none of the `keys` provided.
  5653. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5654. * a deep comparison.
  5655. * You can also provide a single object instead of a `keys` array and its keys
  5656. * will be used as the expected set of keys.
  5657. *
  5658. * assert.doesNotHaveAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {thisDoesNot: 'exist'});
  5659. * assert.doesNotHaveAnyDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{twenty: 'twenty'}, {fifty: 'fifty'}]);
  5660. * assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {twenty: 'twenty'});
  5661. * assert.doesNotHaveAnyDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{twenty: 'twenty'}, {fifty: 'fifty'}]);
  5662. *
  5663. * @name doesNotHaveAnyDeepKeys
  5664. * @param {Mixed} object
  5665. * @param {Array|Object} keys
  5666. * @param {String} message
  5667. * @namespace Assert
  5668. * @api public
  5669. */
  5670. assert.doesNotHaveAnyDeepKeys = function (obj, keys, msg) {
  5671. new Assertion(obj, msg, assert.doesNotHaveAnyDeepKeys, true)
  5672. .to.not.have.any.deep.keys(keys);
  5673. }
  5674. /**
  5675. * ### .doesNotHaveAllDeepKeys(object, [keys], [message])
  5676. *
  5677. * Asserts that `object` does not have at least one of the `keys` provided.
  5678. * Since Sets and Maps can have objects as keys you can use this assertion to perform
  5679. * a deep comparison.
  5680. * You can also provide a single object instead of a `keys` array and its keys
  5681. * will be used as the expected set of keys.
  5682. *
  5683. * assert.doesNotHaveAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [1, 2]]), {thisDoesNot: 'exist'});
  5684. * assert.doesNotHaveAllDeepKeys(new Map([[{one: 'one'}, 'valueOne'], [{two: 'two'}, 'valueTwo']]), [{twenty: 'twenty'}, {one: 'one'}]);
  5685. * assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), {twenty: 'twenty'});
  5686. * assert.doesNotHaveAllDeepKeys(new Set([{one: 'one'}, {two: 'two'}]), [{one: 'one'}, {fifty: 'fifty'}]);
  5687. *
  5688. * @name doesNotHaveAllDeepKeys
  5689. * @param {Mixed} object
  5690. * @param {Array|Object} keys
  5691. * @param {String} message
  5692. * @namespace Assert
  5693. * @api public
  5694. */
  5695. assert.doesNotHaveAllDeepKeys = function (obj, keys, msg) {
  5696. new Assertion(obj, msg, assert.doesNotHaveAllDeepKeys, true)
  5697. .to.not.have.all.deep.keys(keys);
  5698. }
  5699. /**
  5700. * ### .throws(fn, [errorLike/string/regexp], [string/regexp], [message])
  5701. *
  5702. * If `errorLike` is an `Error` constructor, asserts that `fn` will throw an error that is an
  5703. * instance of `errorLike`.
  5704. * If `errorLike` is an `Error` instance, asserts that the error thrown is the same
  5705. * instance as `errorLike`.
  5706. * If `errMsgMatcher` is provided, it also asserts that the error thrown will have a
  5707. * message matching `errMsgMatcher`.
  5708. *
  5709. * assert.throws(fn, 'Error thrown must have this msg');
  5710. * assert.throws(fn, /Error thrown must have a msg that matches this/);
  5711. * assert.throws(fn, ReferenceError);
  5712. * assert.throws(fn, errorInstance);
  5713. * assert.throws(fn, ReferenceError, 'Error thrown must be a ReferenceError and have this msg');
  5714. * assert.throws(fn, errorInstance, 'Error thrown must be the same errorInstance and have this msg');
  5715. * assert.throws(fn, ReferenceError, /Error thrown must be a ReferenceError and match this/);
  5716. * assert.throws(fn, errorInstance, /Error thrown must be the same errorInstance and match this/);
  5717. *
  5718. * @name throws
  5719. * @alias throw
  5720. * @alias Throw
  5721. * @param {Function} fn
  5722. * @param {ErrorConstructor|Error} errorLike
  5723. * @param {RegExp|String} errMsgMatcher
  5724. * @param {String} message
  5725. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  5726. * @namespace Assert
  5727. * @api public
  5728. */
  5729. assert.throws = function (fn, errorLike, errMsgMatcher, msg) {
  5730. if ('string' === typeof errorLike || errorLike instanceof RegExp) {
  5731. errMsgMatcher = errorLike;
  5732. errorLike = null;
  5733. }
  5734. var assertErr = new Assertion(fn, msg, assert.throws, true)
  5735. .to.throw(errorLike, errMsgMatcher);
  5736. return flag(assertErr, 'object');
  5737. };
  5738. /**
  5739. * ### .doesNotThrow(fn, [errorLike/string/regexp], [string/regexp], [message])
  5740. *
  5741. * If `errorLike` is an `Error` constructor, asserts that `fn` will _not_ throw an error that is an
  5742. * instance of `errorLike`.
  5743. * If `errorLike` is an `Error` instance, asserts that the error thrown is _not_ the same
  5744. * instance as `errorLike`.
  5745. * If `errMsgMatcher` is provided, it also asserts that the error thrown will _not_ have a
  5746. * message matching `errMsgMatcher`.
  5747. *
  5748. * assert.doesNotThrow(fn, 'Any Error thrown must not have this message');
  5749. * assert.doesNotThrow(fn, /Any Error thrown must not match this/);
  5750. * assert.doesNotThrow(fn, Error);
  5751. * assert.doesNotThrow(fn, errorInstance);
  5752. * assert.doesNotThrow(fn, Error, 'Error must not have this message');
  5753. * assert.doesNotThrow(fn, errorInstance, 'Error must not have this message');
  5754. * assert.doesNotThrow(fn, Error, /Error must not match this/);
  5755. * assert.doesNotThrow(fn, errorInstance, /Error must not match this/);
  5756. *
  5757. * @name doesNotThrow
  5758. * @param {Function} fn
  5759. * @param {ErrorConstructor} errorLike
  5760. * @param {RegExp|String} errMsgMatcher
  5761. * @param {String} message
  5762. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  5763. * @namespace Assert
  5764. * @api public
  5765. */
  5766. assert.doesNotThrow = function (fn, errorLike, errMsgMatcher, msg) {
  5767. if ('string' === typeof errorLike || errorLike instanceof RegExp) {
  5768. errMsgMatcher = errorLike;
  5769. errorLike = null;
  5770. }
  5771. new Assertion(fn, msg, assert.doesNotThrow, true)
  5772. .to.not.throw(errorLike, errMsgMatcher);
  5773. };
  5774. /**
  5775. * ### .operator(val1, operator, val2, [message])
  5776. *
  5777. * Compares two values using `operator`.
  5778. *
  5779. * assert.operator(1, '<', 2, 'everything is ok');
  5780. * assert.operator(1, '>', 2, 'this will fail');
  5781. *
  5782. * @name operator
  5783. * @param {Mixed} val1
  5784. * @param {String} operator
  5785. * @param {Mixed} val2
  5786. * @param {String} message
  5787. * @namespace Assert
  5788. * @api public
  5789. */
  5790. assert.operator = function (val, operator, val2, msg) {
  5791. var ok;
  5792. switch(operator) {
  5793. case '==':
  5794. ok = val == val2;
  5795. break;
  5796. case '===':
  5797. ok = val === val2;
  5798. break;
  5799. case '>':
  5800. ok = val > val2;
  5801. break;
  5802. case '>=':
  5803. ok = val >= val2;
  5804. break;
  5805. case '<':
  5806. ok = val < val2;
  5807. break;
  5808. case '<=':
  5809. ok = val <= val2;
  5810. break;
  5811. case '!=':
  5812. ok = val != val2;
  5813. break;
  5814. case '!==':
  5815. ok = val !== val2;
  5816. break;
  5817. default:
  5818. msg = msg ? msg + ': ' : msg;
  5819. throw new chai.AssertionError(
  5820. msg + 'Invalid operator "' + operator + '"',
  5821. undefined,
  5822. assert.operator
  5823. );
  5824. }
  5825. var test = new Assertion(ok, msg, assert.operator, true);
  5826. test.assert(
  5827. true === flag(test, 'object')
  5828. , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
  5829. , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
  5830. };
  5831. /**
  5832. * ### .closeTo(actual, expected, delta, [message])
  5833. *
  5834. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  5835. *
  5836. * assert.closeTo(1.5, 1, 0.5, 'numbers are close');
  5837. *
  5838. * @name closeTo
  5839. * @param {Number} actual
  5840. * @param {Number} expected
  5841. * @param {Number} delta
  5842. * @param {String} message
  5843. * @namespace Assert
  5844. * @api public
  5845. */
  5846. assert.closeTo = function (act, exp, delta, msg) {
  5847. new Assertion(act, msg, assert.closeTo, true).to.be.closeTo(exp, delta);
  5848. };
  5849. /**
  5850. * ### .approximately(actual, expected, delta, [message])
  5851. *
  5852. * Asserts that the target is equal `expected`, to within a +/- `delta` range.
  5853. *
  5854. * assert.approximately(1.5, 1, 0.5, 'numbers are close');
  5855. *
  5856. * @name approximately
  5857. * @param {Number} actual
  5858. * @param {Number} expected
  5859. * @param {Number} delta
  5860. * @param {String} message
  5861. * @namespace Assert
  5862. * @api public
  5863. */
  5864. assert.approximately = function (act, exp, delta, msg) {
  5865. new Assertion(act, msg, assert.approximately, true)
  5866. .to.be.approximately(exp, delta);
  5867. };
  5868. /**
  5869. * ### .sameMembers(set1, set2, [message])
  5870. *
  5871. * Asserts that `set1` and `set2` have the same members in any order. Uses a
  5872. * strict equality check (===).
  5873. *
  5874. * assert.sameMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'same members');
  5875. *
  5876. * @name sameMembers
  5877. * @param {Array} set1
  5878. * @param {Array} set2
  5879. * @param {String} message
  5880. * @namespace Assert
  5881. * @api public
  5882. */
  5883. assert.sameMembers = function (set1, set2, msg) {
  5884. new Assertion(set1, msg, assert.sameMembers, true)
  5885. .to.have.same.members(set2);
  5886. }
  5887. /**
  5888. * ### .notSameMembers(set1, set2, [message])
  5889. *
  5890. * Asserts that `set1` and `set2` don't have the same members in any order.
  5891. * Uses a strict equality check (===).
  5892. *
  5893. * assert.notSameMembers([ 1, 2, 3 ], [ 5, 1, 3 ], 'not same members');
  5894. *
  5895. * @name notSameMembers
  5896. * @param {Array} set1
  5897. * @param {Array} set2
  5898. * @param {String} message
  5899. * @namespace Assert
  5900. * @api public
  5901. */
  5902. assert.notSameMembers = function (set1, set2, msg) {
  5903. new Assertion(set1, msg, assert.notSameMembers, true)
  5904. .to.not.have.same.members(set2);
  5905. }
  5906. /**
  5907. * ### .sameDeepMembers(set1, set2, [message])
  5908. *
  5909. * Asserts that `set1` and `set2` have the same members in any order. Uses a
  5910. * deep equality check.
  5911. *
  5912. * assert.sameDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [{ b: 2 }, { a: 1 }, { c: 3 }], 'same deep members');
  5913. *
  5914. * @name sameDeepMembers
  5915. * @param {Array} set1
  5916. * @param {Array} set2
  5917. * @param {String} message
  5918. * @namespace Assert
  5919. * @api public
  5920. */
  5921. assert.sameDeepMembers = function (set1, set2, msg) {
  5922. new Assertion(set1, msg, assert.sameDeepMembers, true)
  5923. .to.have.same.deep.members(set2);
  5924. }
  5925. /**
  5926. * ### .notSameDeepMembers(set1, set2, [message])
  5927. *
  5928. * Asserts that `set1` and `set2` don't have the same members in any order.
  5929. * Uses a deep equality check.
  5930. *
  5931. * assert.notSameDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [{ b: 2 }, { a: 1 }, { f: 5 }], 'not same deep members');
  5932. *
  5933. * @name notSameDeepMembers
  5934. * @param {Array} set1
  5935. * @param {Array} set2
  5936. * @param {String} message
  5937. * @namespace Assert
  5938. * @api public
  5939. */
  5940. assert.notSameDeepMembers = function (set1, set2, msg) {
  5941. new Assertion(set1, msg, assert.notSameDeepMembers, true)
  5942. .to.not.have.same.deep.members(set2);
  5943. }
  5944. /**
  5945. * ### .sameOrderedMembers(set1, set2, [message])
  5946. *
  5947. * Asserts that `set1` and `set2` have the same members in the same order.
  5948. * Uses a strict equality check (===).
  5949. *
  5950. * assert.sameOrderedMembers([ 1, 2, 3 ], [ 1, 2, 3 ], 'same ordered members');
  5951. *
  5952. * @name sameOrderedMembers
  5953. * @param {Array} set1
  5954. * @param {Array} set2
  5955. * @param {String} message
  5956. * @namespace Assert
  5957. * @api public
  5958. */
  5959. assert.sameOrderedMembers = function (set1, set2, msg) {
  5960. new Assertion(set1, msg, assert.sameOrderedMembers, true)
  5961. .to.have.same.ordered.members(set2);
  5962. }
  5963. /**
  5964. * ### .notSameOrderedMembers(set1, set2, [message])
  5965. *
  5966. * Asserts that `set1` and `set2` don't have the same members in the same
  5967. * order. Uses a strict equality check (===).
  5968. *
  5969. * assert.notSameOrderedMembers([ 1, 2, 3 ], [ 2, 1, 3 ], 'not same ordered members');
  5970. *
  5971. * @name notSameOrderedMembers
  5972. * @param {Array} set1
  5973. * @param {Array} set2
  5974. * @param {String} message
  5975. * @namespace Assert
  5976. * @api public
  5977. */
  5978. assert.notSameOrderedMembers = function (set1, set2, msg) {
  5979. new Assertion(set1, msg, assert.notSameOrderedMembers, true)
  5980. .to.not.have.same.ordered.members(set2);
  5981. }
  5982. /**
  5983. * ### .sameDeepOrderedMembers(set1, set2, [message])
  5984. *
  5985. * Asserts that `set1` and `set2` have the same members in the same order.
  5986. * Uses a deep equality check.
  5987. *
  5988. * assert.sameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { c: 3 } ], 'same deep ordered members');
  5989. *
  5990. * @name sameDeepOrderedMembers
  5991. * @param {Array} set1
  5992. * @param {Array} set2
  5993. * @param {String} message
  5994. * @namespace Assert
  5995. * @api public
  5996. */
  5997. assert.sameDeepOrderedMembers = function (set1, set2, msg) {
  5998. new Assertion(set1, msg, assert.sameDeepOrderedMembers, true)
  5999. .to.have.same.deep.ordered.members(set2);
  6000. }
  6001. /**
  6002. * ### .notSameDeepOrderedMembers(set1, set2, [message])
  6003. *
  6004. * Asserts that `set1` and `set2` don't have the same members in the same
  6005. * order. Uses a deep equality check.
  6006. *
  6007. * assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 }, { z: 5 } ], 'not same deep ordered members');
  6008. * assert.notSameDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 }, { c: 3 } ], 'not same deep ordered members');
  6009. *
  6010. * @name notSameDeepOrderedMembers
  6011. * @param {Array} set1
  6012. * @param {Array} set2
  6013. * @param {String} message
  6014. * @namespace Assert
  6015. * @api public
  6016. */
  6017. assert.notSameDeepOrderedMembers = function (set1, set2, msg) {
  6018. new Assertion(set1, msg, assert.notSameDeepOrderedMembers, true)
  6019. .to.not.have.same.deep.ordered.members(set2);
  6020. }
  6021. /**
  6022. * ### .includeMembers(superset, subset, [message])
  6023. *
  6024. * Asserts that `subset` is included in `superset` in any order. Uses a
  6025. * strict equality check (===). Duplicates are ignored.
  6026. *
  6027. * assert.includeMembers([ 1, 2, 3 ], [ 2, 1, 2 ], 'include members');
  6028. *
  6029. * @name includeMembers
  6030. * @param {Array} superset
  6031. * @param {Array} subset
  6032. * @param {String} message
  6033. * @namespace Assert
  6034. * @api public
  6035. */
  6036. assert.includeMembers = function (superset, subset, msg) {
  6037. new Assertion(superset, msg, assert.includeMembers, true)
  6038. .to.include.members(subset);
  6039. }
  6040. /**
  6041. * ### .notIncludeMembers(superset, subset, [message])
  6042. *
  6043. * Asserts that `subset` isn't included in `superset` in any order. Uses a
  6044. * strict equality check (===). Duplicates are ignored.
  6045. *
  6046. * assert.notIncludeMembers([ 1, 2, 3 ], [ 5, 1 ], 'not include members');
  6047. *
  6048. * @name notIncludeMembers
  6049. * @param {Array} superset
  6050. * @param {Array} subset
  6051. * @param {String} message
  6052. * @namespace Assert
  6053. * @api public
  6054. */
  6055. assert.notIncludeMembers = function (superset, subset, msg) {
  6056. new Assertion(superset, msg, assert.notIncludeMembers, true)
  6057. .to.not.include.members(subset);
  6058. }
  6059. /**
  6060. * ### .includeDeepMembers(superset, subset, [message])
  6061. *
  6062. * Asserts that `subset` is included in `superset` in any order. Uses a deep
  6063. * equality check. Duplicates are ignored.
  6064. *
  6065. * assert.includeDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 }, { b: 2 } ], 'include deep members');
  6066. *
  6067. * @name includeDeepMembers
  6068. * @param {Array} superset
  6069. * @param {Array} subset
  6070. * @param {String} message
  6071. * @namespace Assert
  6072. * @api public
  6073. */
  6074. assert.includeDeepMembers = function (superset, subset, msg) {
  6075. new Assertion(superset, msg, assert.includeDeepMembers, true)
  6076. .to.include.deep.members(subset);
  6077. }
  6078. /**
  6079. * ### .notIncludeDeepMembers(superset, subset, [message])
  6080. *
  6081. * Asserts that `subset` isn't included in `superset` in any order. Uses a
  6082. * deep equality check. Duplicates are ignored.
  6083. *
  6084. * assert.notIncludeDeepMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { f: 5 } ], 'not include deep members');
  6085. *
  6086. * @name notIncludeDeepMembers
  6087. * @param {Array} superset
  6088. * @param {Array} subset
  6089. * @param {String} message
  6090. * @namespace Assert
  6091. * @api public
  6092. */
  6093. assert.notIncludeDeepMembers = function (superset, subset, msg) {
  6094. new Assertion(superset, msg, assert.notIncludeDeepMembers, true)
  6095. .to.not.include.deep.members(subset);
  6096. }
  6097. /**
  6098. * ### .includeOrderedMembers(superset, subset, [message])
  6099. *
  6100. * Asserts that `subset` is included in `superset` in the same order
  6101. * beginning with the first element in `superset`. Uses a strict equality
  6102. * check (===).
  6103. *
  6104. * assert.includeOrderedMembers([ 1, 2, 3 ], [ 1, 2 ], 'include ordered members');
  6105. *
  6106. * @name includeOrderedMembers
  6107. * @param {Array} superset
  6108. * @param {Array} subset
  6109. * @param {String} message
  6110. * @namespace Assert
  6111. * @api public
  6112. */
  6113. assert.includeOrderedMembers = function (superset, subset, msg) {
  6114. new Assertion(superset, msg, assert.includeOrderedMembers, true)
  6115. .to.include.ordered.members(subset);
  6116. }
  6117. /**
  6118. * ### .notIncludeOrderedMembers(superset, subset, [message])
  6119. *
  6120. * Asserts that `subset` isn't included in `superset` in the same order
  6121. * beginning with the first element in `superset`. Uses a strict equality
  6122. * check (===).
  6123. *
  6124. * assert.notIncludeOrderedMembers([ 1, 2, 3 ], [ 2, 1 ], 'not include ordered members');
  6125. * assert.notIncludeOrderedMembers([ 1, 2, 3 ], [ 2, 3 ], 'not include ordered members');
  6126. *
  6127. * @name notIncludeOrderedMembers
  6128. * @param {Array} superset
  6129. * @param {Array} subset
  6130. * @param {String} message
  6131. * @namespace Assert
  6132. * @api public
  6133. */
  6134. assert.notIncludeOrderedMembers = function (superset, subset, msg) {
  6135. new Assertion(superset, msg, assert.notIncludeOrderedMembers, true)
  6136. .to.not.include.ordered.members(subset);
  6137. }
  6138. /**
  6139. * ### .includeDeepOrderedMembers(superset, subset, [message])
  6140. *
  6141. * Asserts that `subset` is included in `superset` in the same order
  6142. * beginning with the first element in `superset`. Uses a deep equality
  6143. * check.
  6144. *
  6145. * assert.includeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { b: 2 } ], 'include deep ordered members');
  6146. *
  6147. * @name includeDeepOrderedMembers
  6148. * @param {Array} superset
  6149. * @param {Array} subset
  6150. * @param {String} message
  6151. * @namespace Assert
  6152. * @api public
  6153. */
  6154. assert.includeDeepOrderedMembers = function (superset, subset, msg) {
  6155. new Assertion(superset, msg, assert.includeDeepOrderedMembers, true)
  6156. .to.include.deep.ordered.members(subset);
  6157. }
  6158. /**
  6159. * ### .notIncludeDeepOrderedMembers(superset, subset, [message])
  6160. *
  6161. * Asserts that `subset` isn't included in `superset` in the same order
  6162. * beginning with the first element in `superset`. Uses a deep equality
  6163. * check.
  6164. *
  6165. * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { a: 1 }, { f: 5 } ], 'not include deep ordered members');
  6166. * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { a: 1 } ], 'not include deep ordered members');
  6167. * assert.notIncludeDeepOrderedMembers([ { a: 1 }, { b: 2 }, { c: 3 } ], [ { b: 2 }, { c: 3 } ], 'not include deep ordered members');
  6168. *
  6169. * @name notIncludeDeepOrderedMembers
  6170. * @param {Array} superset
  6171. * @param {Array} subset
  6172. * @param {String} message
  6173. * @namespace Assert
  6174. * @api public
  6175. */
  6176. assert.notIncludeDeepOrderedMembers = function (superset, subset, msg) {
  6177. new Assertion(superset, msg, assert.notIncludeDeepOrderedMembers, true)
  6178. .to.not.include.deep.ordered.members(subset);
  6179. }
  6180. /**
  6181. * ### .oneOf(inList, list, [message])
  6182. *
  6183. * Asserts that non-object, non-array value `inList` appears in the flat array `list`.
  6184. *
  6185. * assert.oneOf(1, [ 2, 1 ], 'Not found in list');
  6186. *
  6187. * @name oneOf
  6188. * @param {*} inList
  6189. * @param {Array<*>} list
  6190. * @param {String} message
  6191. * @namespace Assert
  6192. * @api public
  6193. */
  6194. assert.oneOf = function (inList, list, msg) {
  6195. new Assertion(inList, msg, assert.oneOf, true).to.be.oneOf(list);
  6196. }
  6197. /**
  6198. * ### .changes(function, object, property, [message])
  6199. *
  6200. * Asserts that a function changes the value of a property.
  6201. *
  6202. * var obj = { val: 10 };
  6203. * var fn = function() { obj.val = 22 };
  6204. * assert.changes(fn, obj, 'val');
  6205. *
  6206. * @name changes
  6207. * @param {Function} modifier function
  6208. * @param {Object} object or getter function
  6209. * @param {String} property name _optional_
  6210. * @param {String} message _optional_
  6211. * @namespace Assert
  6212. * @api public
  6213. */
  6214. assert.changes = function (fn, obj, prop, msg) {
  6215. if (arguments.length === 3 && typeof obj === 'function') {
  6216. msg = prop;
  6217. prop = null;
  6218. }
  6219. new Assertion(fn, msg, assert.changes, true).to.change(obj, prop);
  6220. }
  6221. /**
  6222. * ### .changesBy(function, object, property, delta, [message])
  6223. *
  6224. * Asserts that a function changes the value of a property by an amount (delta).
  6225. *
  6226. * var obj = { val: 10 };
  6227. * var fn = function() { obj.val += 2 };
  6228. * assert.changesBy(fn, obj, 'val', 2);
  6229. *
  6230. * @name changesBy
  6231. * @param {Function} modifier function
  6232. * @param {Object} object or getter function
  6233. * @param {String} property name _optional_
  6234. * @param {Number} change amount (delta)
  6235. * @param {String} message _optional_
  6236. * @namespace Assert
  6237. * @api public
  6238. */
  6239. assert.changesBy = function (fn, obj, prop, delta, msg) {
  6240. if (arguments.length === 4 && typeof obj === 'function') {
  6241. var tmpMsg = delta;
  6242. delta = prop;
  6243. msg = tmpMsg;
  6244. } else if (arguments.length === 3) {
  6245. delta = prop;
  6246. prop = null;
  6247. }
  6248. new Assertion(fn, msg, assert.changesBy, true)
  6249. .to.change(obj, prop).by(delta);
  6250. }
  6251. /**
  6252. * ### .doesNotChange(function, object, property, [message])
  6253. *
  6254. * Asserts that a function does not change the value of a property.
  6255. *
  6256. * var obj = { val: 10 };
  6257. * var fn = function() { console.log('foo'); };
  6258. * assert.doesNotChange(fn, obj, 'val');
  6259. *
  6260. * @name doesNotChange
  6261. * @param {Function} modifier function
  6262. * @param {Object} object or getter function
  6263. * @param {String} property name _optional_
  6264. * @param {String} message _optional_
  6265. * @namespace Assert
  6266. * @api public
  6267. */
  6268. assert.doesNotChange = function (fn, obj, prop, msg) {
  6269. if (arguments.length === 3 && typeof obj === 'function') {
  6270. msg = prop;
  6271. prop = null;
  6272. }
  6273. return new Assertion(fn, msg, assert.doesNotChange, true)
  6274. .to.not.change(obj, prop);
  6275. }
  6276. /**
  6277. * ### .changesButNotBy(function, object, property, delta, [message])
  6278. *
  6279. * Asserts that a function does not change the value of a property or of a function's return value by an amount (delta)
  6280. *
  6281. * var obj = { val: 10 };
  6282. * var fn = function() { obj.val += 10 };
  6283. * assert.changesButNotBy(fn, obj, 'val', 5);
  6284. *
  6285. * @name changesButNotBy
  6286. * @param {Function} modifier function
  6287. * @param {Object} object or getter function
  6288. * @param {String} property name _optional_
  6289. * @param {Number} change amount (delta)
  6290. * @param {String} message _optional_
  6291. * @namespace Assert
  6292. * @api public
  6293. */
  6294. assert.changesButNotBy = function (fn, obj, prop, delta, msg) {
  6295. if (arguments.length === 4 && typeof obj === 'function') {
  6296. var tmpMsg = delta;
  6297. delta = prop;
  6298. msg = tmpMsg;
  6299. } else if (arguments.length === 3) {
  6300. delta = prop;
  6301. prop = null;
  6302. }
  6303. new Assertion(fn, msg, assert.changesButNotBy, true)
  6304. .to.change(obj, prop).but.not.by(delta);
  6305. }
  6306. /**
  6307. * ### .increases(function, object, property, [message])
  6308. *
  6309. * Asserts that a function increases a numeric object property.
  6310. *
  6311. * var obj = { val: 10 };
  6312. * var fn = function() { obj.val = 13 };
  6313. * assert.increases(fn, obj, 'val');
  6314. *
  6315. * @name increases
  6316. * @param {Function} modifier function
  6317. * @param {Object} object or getter function
  6318. * @param {String} property name _optional_
  6319. * @param {String} message _optional_
  6320. * @namespace Assert
  6321. * @api public
  6322. */
  6323. assert.increases = function (fn, obj, prop, msg) {
  6324. if (arguments.length === 3 && typeof obj === 'function') {
  6325. msg = prop;
  6326. prop = null;
  6327. }
  6328. return new Assertion(fn, msg, assert.increases, true)
  6329. .to.increase(obj, prop);
  6330. }
  6331. /**
  6332. * ### .increasesBy(function, object, property, delta, [message])
  6333. *
  6334. * Asserts that a function increases a numeric object property or a function's return value by an amount (delta).
  6335. *
  6336. * var obj = { val: 10 };
  6337. * var fn = function() { obj.val += 10 };
  6338. * assert.increasesBy(fn, obj, 'val', 10);
  6339. *
  6340. * @name increasesBy
  6341. * @param {Function} modifier function
  6342. * @param {Object} object or getter function
  6343. * @param {String} property name _optional_
  6344. * @param {Number} change amount (delta)
  6345. * @param {String} message _optional_
  6346. * @namespace Assert
  6347. * @api public
  6348. */
  6349. assert.increasesBy = function (fn, obj, prop, delta, msg) {
  6350. if (arguments.length === 4 && typeof obj === 'function') {
  6351. var tmpMsg = delta;
  6352. delta = prop;
  6353. msg = tmpMsg;
  6354. } else if (arguments.length === 3) {
  6355. delta = prop;
  6356. prop = null;
  6357. }
  6358. new Assertion(fn, msg, assert.increasesBy, true)
  6359. .to.increase(obj, prop).by(delta);
  6360. }
  6361. /**
  6362. * ### .doesNotIncrease(function, object, property, [message])
  6363. *
  6364. * Asserts that a function does not increase a numeric object property.
  6365. *
  6366. * var obj = { val: 10 };
  6367. * var fn = function() { obj.val = 8 };
  6368. * assert.doesNotIncrease(fn, obj, 'val');
  6369. *
  6370. * @name doesNotIncrease
  6371. * @param {Function} modifier function
  6372. * @param {Object} object or getter function
  6373. * @param {String} property name _optional_
  6374. * @param {String} message _optional_
  6375. * @namespace Assert
  6376. * @api public
  6377. */
  6378. assert.doesNotIncrease = function (fn, obj, prop, msg) {
  6379. if (arguments.length === 3 && typeof obj === 'function') {
  6380. msg = prop;
  6381. prop = null;
  6382. }
  6383. return new Assertion(fn, msg, assert.doesNotIncrease, true)
  6384. .to.not.increase(obj, prop);
  6385. }
  6386. /**
  6387. * ### .increasesButNotBy(function, object, property, delta, [message])
  6388. *
  6389. * Asserts that a function does not increase a numeric object property or function's return value by an amount (delta).
  6390. *
  6391. * var obj = { val: 10 };
  6392. * var fn = function() { obj.val = 15 };
  6393. * assert.increasesButNotBy(fn, obj, 'val', 10);
  6394. *
  6395. * @name increasesButNotBy
  6396. * @param {Function} modifier function
  6397. * @param {Object} object or getter function
  6398. * @param {String} property name _optional_
  6399. * @param {Number} change amount (delta)
  6400. * @param {String} message _optional_
  6401. * @namespace Assert
  6402. * @api public
  6403. */
  6404. assert.increasesButNotBy = function (fn, obj, prop, delta, msg) {
  6405. if (arguments.length === 4 && typeof obj === 'function') {
  6406. var tmpMsg = delta;
  6407. delta = prop;
  6408. msg = tmpMsg;
  6409. } else if (arguments.length === 3) {
  6410. delta = prop;
  6411. prop = null;
  6412. }
  6413. new Assertion(fn, msg, assert.increasesButNotBy, true)
  6414. .to.increase(obj, prop).but.not.by(delta);
  6415. }
  6416. /**
  6417. * ### .decreases(function, object, property, [message])
  6418. *
  6419. * Asserts that a function decreases a numeric object property.
  6420. *
  6421. * var obj = { val: 10 };
  6422. * var fn = function() { obj.val = 5 };
  6423. * assert.decreases(fn, obj, 'val');
  6424. *
  6425. * @name decreases
  6426. * @param {Function} modifier function
  6427. * @param {Object} object or getter function
  6428. * @param {String} property name _optional_
  6429. * @param {String} message _optional_
  6430. * @namespace Assert
  6431. * @api public
  6432. */
  6433. assert.decreases = function (fn, obj, prop, msg) {
  6434. if (arguments.length === 3 && typeof obj === 'function') {
  6435. msg = prop;
  6436. prop = null;
  6437. }
  6438. return new Assertion(fn, msg, assert.decreases, true)
  6439. .to.decrease(obj, prop);
  6440. }
  6441. /**
  6442. * ### .decreasesBy(function, object, property, delta, [message])
  6443. *
  6444. * Asserts that a function decreases a numeric object property or a function's return value by an amount (delta)
  6445. *
  6446. * var obj = { val: 10 };
  6447. * var fn = function() { obj.val -= 5 };
  6448. * assert.decreasesBy(fn, obj, 'val', 5);
  6449. *
  6450. * @name decreasesBy
  6451. * @param {Function} modifier function
  6452. * @param {Object} object or getter function
  6453. * @param {String} property name _optional_
  6454. * @param {Number} change amount (delta)
  6455. * @param {String} message _optional_
  6456. * @namespace Assert
  6457. * @api public
  6458. */
  6459. assert.decreasesBy = function (fn, obj, prop, delta, msg) {
  6460. if (arguments.length === 4 && typeof obj === 'function') {
  6461. var tmpMsg = delta;
  6462. delta = prop;
  6463. msg = tmpMsg;
  6464. } else if (arguments.length === 3) {
  6465. delta = prop;
  6466. prop = null;
  6467. }
  6468. new Assertion(fn, msg, assert.decreasesBy, true)
  6469. .to.decrease(obj, prop).by(delta);
  6470. }
  6471. /**
  6472. * ### .doesNotDecrease(function, object, property, [message])
  6473. *
  6474. * Asserts that a function does not decreases a numeric object property.
  6475. *
  6476. * var obj = { val: 10 };
  6477. * var fn = function() { obj.val = 15 };
  6478. * assert.doesNotDecrease(fn, obj, 'val');
  6479. *
  6480. * @name doesNotDecrease
  6481. * @param {Function} modifier function
  6482. * @param {Object} object or getter function
  6483. * @param {String} property name _optional_
  6484. * @param {String} message _optional_
  6485. * @namespace Assert
  6486. * @api public
  6487. */
  6488. assert.doesNotDecrease = function (fn, obj, prop, msg) {
  6489. if (arguments.length === 3 && typeof obj === 'function') {
  6490. msg = prop;
  6491. prop = null;
  6492. }
  6493. return new Assertion(fn, msg, assert.doesNotDecrease, true)
  6494. .to.not.decrease(obj, prop);
  6495. }
  6496. /**
  6497. * ### .doesNotDecreaseBy(function, object, property, delta, [message])
  6498. *
  6499. * Asserts that a function does not decreases a numeric object property or a function's return value by an amount (delta)
  6500. *
  6501. * var obj = { val: 10 };
  6502. * var fn = function() { obj.val = 5 };
  6503. * assert.doesNotDecreaseBy(fn, obj, 'val', 1);
  6504. *
  6505. * @name doesNotDecreaseBy
  6506. * @param {Function} modifier function
  6507. * @param {Object} object or getter function
  6508. * @param {String} property name _optional_
  6509. * @param {Number} change amount (delta)
  6510. * @param {String} message _optional_
  6511. * @namespace Assert
  6512. * @api public
  6513. */
  6514. assert.doesNotDecreaseBy = function (fn, obj, prop, delta, msg) {
  6515. if (arguments.length === 4 && typeof obj === 'function') {
  6516. var tmpMsg = delta;
  6517. delta = prop;
  6518. msg = tmpMsg;
  6519. } else if (arguments.length === 3) {
  6520. delta = prop;
  6521. prop = null;
  6522. }
  6523. return new Assertion(fn, msg, assert.doesNotDecreaseBy, true)
  6524. .to.not.decrease(obj, prop).by(delta);
  6525. }
  6526. /**
  6527. * ### .decreasesButNotBy(function, object, property, delta, [message])
  6528. *
  6529. * Asserts that a function does not decreases a numeric object property or a function's return value by an amount (delta)
  6530. *
  6531. * var obj = { val: 10 };
  6532. * var fn = function() { obj.val = 5 };
  6533. * assert.decreasesButNotBy(fn, obj, 'val', 1);
  6534. *
  6535. * @name decreasesButNotBy
  6536. * @param {Function} modifier function
  6537. * @param {Object} object or getter function
  6538. * @param {String} property name _optional_
  6539. * @param {Number} change amount (delta)
  6540. * @param {String} message _optional_
  6541. * @namespace Assert
  6542. * @api public
  6543. */
  6544. assert.decreasesButNotBy = function (fn, obj, prop, delta, msg) {
  6545. if (arguments.length === 4 && typeof obj === 'function') {
  6546. var tmpMsg = delta;
  6547. delta = prop;
  6548. msg = tmpMsg;
  6549. } else if (arguments.length === 3) {
  6550. delta = prop;
  6551. prop = null;
  6552. }
  6553. new Assertion(fn, msg, assert.decreasesButNotBy, true)
  6554. .to.decrease(obj, prop).but.not.by(delta);
  6555. }
  6556. /*!
  6557. * ### .ifError(object)
  6558. *
  6559. * Asserts if value is not a false value, and throws if it is a true value.
  6560. * This is added to allow for chai to be a drop-in replacement for Node's
  6561. * assert class.
  6562. *
  6563. * var err = new Error('I am a custom error');
  6564. * assert.ifError(err); // Rethrows err!
  6565. *
  6566. * @name ifError
  6567. * @param {Object} object
  6568. * @namespace Assert
  6569. * @api public
  6570. */
  6571. assert.ifError = function (val) {
  6572. if (val) {
  6573. throw(val);
  6574. }
  6575. };
  6576. /**
  6577. * ### .isExtensible(object)
  6578. *
  6579. * Asserts that `object` is extensible (can have new properties added to it).
  6580. *
  6581. * assert.isExtensible({});
  6582. *
  6583. * @name isExtensible
  6584. * @alias extensible
  6585. * @param {Object} object
  6586. * @param {String} message _optional_
  6587. * @namespace Assert
  6588. * @api public
  6589. */
  6590. assert.isExtensible = function (obj, msg) {
  6591. new Assertion(obj, msg, assert.isExtensible, true).to.be.extensible;
  6592. };
  6593. /**
  6594. * ### .isNotExtensible(object)
  6595. *
  6596. * Asserts that `object` is _not_ extensible.
  6597. *
  6598. * var nonExtensibleObject = Object.preventExtensions({});
  6599. * var sealedObject = Object.seal({});
  6600. * var frozenObject = Object.freeze({});
  6601. *
  6602. * assert.isNotExtensible(nonExtensibleObject);
  6603. * assert.isNotExtensible(sealedObject);
  6604. * assert.isNotExtensible(frozenObject);
  6605. *
  6606. * @name isNotExtensible
  6607. * @alias notExtensible
  6608. * @param {Object} object
  6609. * @param {String} message _optional_
  6610. * @namespace Assert
  6611. * @api public
  6612. */
  6613. assert.isNotExtensible = function (obj, msg) {
  6614. new Assertion(obj, msg, assert.isNotExtensible, true).to.not.be.extensible;
  6615. };
  6616. /**
  6617. * ### .isSealed(object)
  6618. *
  6619. * Asserts that `object` is sealed (cannot have new properties added to it
  6620. * and its existing properties cannot be removed).
  6621. *
  6622. * var sealedObject = Object.seal({});
  6623. * var frozenObject = Object.seal({});
  6624. *
  6625. * assert.isSealed(sealedObject);
  6626. * assert.isSealed(frozenObject);
  6627. *
  6628. * @name isSealed
  6629. * @alias sealed
  6630. * @param {Object} object
  6631. * @param {String} message _optional_
  6632. * @namespace Assert
  6633. * @api public
  6634. */
  6635. assert.isSealed = function (obj, msg) {
  6636. new Assertion(obj, msg, assert.isSealed, true).to.be.sealed;
  6637. };
  6638. /**
  6639. * ### .isNotSealed(object)
  6640. *
  6641. * Asserts that `object` is _not_ sealed.
  6642. *
  6643. * assert.isNotSealed({});
  6644. *
  6645. * @name isNotSealed
  6646. * @alias notSealed
  6647. * @param {Object} object
  6648. * @param {String} message _optional_
  6649. * @namespace Assert
  6650. * @api public
  6651. */
  6652. assert.isNotSealed = function (obj, msg) {
  6653. new Assertion(obj, msg, assert.isNotSealed, true).to.not.be.sealed;
  6654. };
  6655. /**
  6656. * ### .isFrozen(object)
  6657. *
  6658. * Asserts that `object` is frozen (cannot have new properties added to it
  6659. * and its existing properties cannot be modified).
  6660. *
  6661. * var frozenObject = Object.freeze({});
  6662. * assert.frozen(frozenObject);
  6663. *
  6664. * @name isFrozen
  6665. * @alias frozen
  6666. * @param {Object} object
  6667. * @param {String} message _optional_
  6668. * @namespace Assert
  6669. * @api public
  6670. */
  6671. assert.isFrozen = function (obj, msg) {
  6672. new Assertion(obj, msg, assert.isFrozen, true).to.be.frozen;
  6673. };
  6674. /**
  6675. * ### .isNotFrozen(object)
  6676. *
  6677. * Asserts that `object` is _not_ frozen.
  6678. *
  6679. * assert.isNotFrozen({});
  6680. *
  6681. * @name isNotFrozen
  6682. * @alias notFrozen
  6683. * @param {Object} object
  6684. * @param {String} message _optional_
  6685. * @namespace Assert
  6686. * @api public
  6687. */
  6688. assert.isNotFrozen = function (obj, msg) {
  6689. new Assertion(obj, msg, assert.isNotFrozen, true).to.not.be.frozen;
  6690. };
  6691. /**
  6692. * ### .isEmpty(target)
  6693. *
  6694. * Asserts that the target does not contain any values.
  6695. * For arrays and strings, it checks the `length` property.
  6696. * For `Map` and `Set` instances, it checks the `size` property.
  6697. * For non-function objects, it gets the count of own
  6698. * enumerable string keys.
  6699. *
  6700. * assert.isEmpty([]);
  6701. * assert.isEmpty('');
  6702. * assert.isEmpty(new Map);
  6703. * assert.isEmpty({});
  6704. *
  6705. * @name isEmpty
  6706. * @alias empty
  6707. * @param {Object|Array|String|Map|Set} target
  6708. * @param {String} message _optional_
  6709. * @namespace Assert
  6710. * @api public
  6711. */
  6712. assert.isEmpty = function(val, msg) {
  6713. new Assertion(val, msg, assert.isEmpty, true).to.be.empty;
  6714. };
  6715. /**
  6716. * ### .isNotEmpty(target)
  6717. *
  6718. * Asserts that the target contains values.
  6719. * For arrays and strings, it checks the `length` property.
  6720. * For `Map` and `Set` instances, it checks the `size` property.
  6721. * For non-function objects, it gets the count of own
  6722. * enumerable string keys.
  6723. *
  6724. * assert.isNotEmpty([1, 2]);
  6725. * assert.isNotEmpty('34');
  6726. * assert.isNotEmpty(new Set([5, 6]));
  6727. * assert.isNotEmpty({ key: 7 });
  6728. *
  6729. * @name isNotEmpty
  6730. * @alias notEmpty
  6731. * @param {Object|Array|String|Map|Set} target
  6732. * @param {String} message _optional_
  6733. * @namespace Assert
  6734. * @api public
  6735. */
  6736. assert.isNotEmpty = function(val, msg) {
  6737. new Assertion(val, msg, assert.isNotEmpty, true).to.not.be.empty;
  6738. };
  6739. /*!
  6740. * Aliases.
  6741. */
  6742. (function alias(name, as){
  6743. assert[as] = assert[name];
  6744. return alias;
  6745. })
  6746. ('isOk', 'ok')
  6747. ('isNotOk', 'notOk')
  6748. ('throws', 'throw')
  6749. ('throws', 'Throw')
  6750. ('isExtensible', 'extensible')
  6751. ('isNotExtensible', 'notExtensible')
  6752. ('isSealed', 'sealed')
  6753. ('isNotSealed', 'notSealed')
  6754. ('isFrozen', 'frozen')
  6755. ('isNotFrozen', 'notFrozen')
  6756. ('isEmpty', 'empty')
  6757. ('isNotEmpty', 'notEmpty');
  6758. };
  6759. },{}],7:[function(require,module,exports){
  6760. /*!
  6761. * chai
  6762. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  6763. * MIT Licensed
  6764. */
  6765. module.exports = function (chai, util) {
  6766. chai.expect = function (val, message) {
  6767. return new chai.Assertion(val, message);
  6768. };
  6769. /**
  6770. * ### .fail([message])
  6771. * ### .fail(actual, expected, [message], [operator])
  6772. *
  6773. * Throw a failure.
  6774. *
  6775. * expect.fail();
  6776. * expect.fail("custom error message");
  6777. * expect.fail(1, 2);
  6778. * expect.fail(1, 2, "custom error message");
  6779. * expect.fail(1, 2, "custom error message", ">");
  6780. * expect.fail(1, 2, undefined, ">");
  6781. *
  6782. * @name fail
  6783. * @param {Mixed} actual
  6784. * @param {Mixed} expected
  6785. * @param {String} message
  6786. * @param {String} operator
  6787. * @namespace BDD
  6788. * @api public
  6789. */
  6790. chai.expect.fail = function (actual, expected, message, operator) {
  6791. if (arguments.length < 2) {
  6792. message = actual;
  6793. actual = undefined;
  6794. }
  6795. message = message || 'expect.fail()';
  6796. throw new chai.AssertionError(message, {
  6797. actual: actual
  6798. , expected: expected
  6799. , operator: operator
  6800. }, chai.expect.fail);
  6801. };
  6802. };
  6803. },{}],8:[function(require,module,exports){
  6804. /*!
  6805. * chai
  6806. * Copyright(c) 2011-2014 Jake Luer <jake@alogicalparadox.com>
  6807. * MIT Licensed
  6808. */
  6809. module.exports = function (chai, util) {
  6810. var Assertion = chai.Assertion;
  6811. function loadShould () {
  6812. // explicitly define this method as function as to have it's name to include as `ssfi`
  6813. function shouldGetter() {
  6814. if (this instanceof String
  6815. || this instanceof Number
  6816. || this instanceof Boolean
  6817. || typeof Symbol === 'function' && this instanceof Symbol
  6818. || typeof BigInt === 'function' && this instanceof BigInt) {
  6819. return new Assertion(this.valueOf(), null, shouldGetter);
  6820. }
  6821. return new Assertion(this, null, shouldGetter);
  6822. }
  6823. function shouldSetter(value) {
  6824. // See https://github.com/chaijs/chai/issues/86: this makes
  6825. // `whatever.should = someValue` actually set `someValue`, which is
  6826. // especially useful for `global.should = require('chai').should()`.
  6827. //
  6828. // Note that we have to use [[DefineProperty]] instead of [[Put]]
  6829. // since otherwise we would trigger this very setter!
  6830. Object.defineProperty(this, 'should', {
  6831. value: value,
  6832. enumerable: true,
  6833. configurable: true,
  6834. writable: true
  6835. });
  6836. }
  6837. // modify Object.prototype to have `should`
  6838. Object.defineProperty(Object.prototype, 'should', {
  6839. set: shouldSetter
  6840. , get: shouldGetter
  6841. , configurable: true
  6842. });
  6843. var should = {};
  6844. /**
  6845. * ### .fail([message])
  6846. * ### .fail(actual, expected, [message], [operator])
  6847. *
  6848. * Throw a failure.
  6849. *
  6850. * should.fail();
  6851. * should.fail("custom error message");
  6852. * should.fail(1, 2);
  6853. * should.fail(1, 2, "custom error message");
  6854. * should.fail(1, 2, "custom error message", ">");
  6855. * should.fail(1, 2, undefined, ">");
  6856. *
  6857. *
  6858. * @name fail
  6859. * @param {Mixed} actual
  6860. * @param {Mixed} expected
  6861. * @param {String} message
  6862. * @param {String} operator
  6863. * @namespace BDD
  6864. * @api public
  6865. */
  6866. should.fail = function (actual, expected, message, operator) {
  6867. if (arguments.length < 2) {
  6868. message = actual;
  6869. actual = undefined;
  6870. }
  6871. message = message || 'should.fail()';
  6872. throw new chai.AssertionError(message, {
  6873. actual: actual
  6874. , expected: expected
  6875. , operator: operator
  6876. }, should.fail);
  6877. };
  6878. /**
  6879. * ### .equal(actual, expected, [message])
  6880. *
  6881. * Asserts non-strict equality (`==`) of `actual` and `expected`.
  6882. *
  6883. * should.equal(3, '3', '== coerces values to strings');
  6884. *
  6885. * @name equal
  6886. * @param {Mixed} actual
  6887. * @param {Mixed} expected
  6888. * @param {String} message
  6889. * @namespace Should
  6890. * @api public
  6891. */
  6892. should.equal = function (val1, val2, msg) {
  6893. new Assertion(val1, msg).to.equal(val2);
  6894. };
  6895. /**
  6896. * ### .throw(function, [constructor/string/regexp], [string/regexp], [message])
  6897. *
  6898. * Asserts that `function` will throw an error that is an instance of
  6899. * `constructor`, or alternately that it will throw an error with message
  6900. * matching `regexp`.
  6901. *
  6902. * should.throw(fn, 'function throws a reference error');
  6903. * should.throw(fn, /function throws a reference error/);
  6904. * should.throw(fn, ReferenceError);
  6905. * should.throw(fn, ReferenceError, 'function throws a reference error');
  6906. * should.throw(fn, ReferenceError, /function throws a reference error/);
  6907. *
  6908. * @name throw
  6909. * @alias Throw
  6910. * @param {Function} function
  6911. * @param {ErrorConstructor} constructor
  6912. * @param {RegExp} regexp
  6913. * @param {String} message
  6914. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  6915. * @namespace Should
  6916. * @api public
  6917. */
  6918. should.Throw = function (fn, errt, errs, msg) {
  6919. new Assertion(fn, msg).to.Throw(errt, errs);
  6920. };
  6921. /**
  6922. * ### .exist
  6923. *
  6924. * Asserts that the target is neither `null` nor `undefined`.
  6925. *
  6926. * var foo = 'hi';
  6927. *
  6928. * should.exist(foo, 'foo exists');
  6929. *
  6930. * @name exist
  6931. * @namespace Should
  6932. * @api public
  6933. */
  6934. should.exist = function (val, msg) {
  6935. new Assertion(val, msg).to.exist;
  6936. }
  6937. // negation
  6938. should.not = {}
  6939. /**
  6940. * ### .not.equal(actual, expected, [message])
  6941. *
  6942. * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
  6943. *
  6944. * should.not.equal(3, 4, 'these numbers are not equal');
  6945. *
  6946. * @name not.equal
  6947. * @param {Mixed} actual
  6948. * @param {Mixed} expected
  6949. * @param {String} message
  6950. * @namespace Should
  6951. * @api public
  6952. */
  6953. should.not.equal = function (val1, val2, msg) {
  6954. new Assertion(val1, msg).to.not.equal(val2);
  6955. };
  6956. /**
  6957. * ### .throw(function, [constructor/regexp], [message])
  6958. *
  6959. * Asserts that `function` will _not_ throw an error that is an instance of
  6960. * `constructor`, or alternately that it will not throw an error with message
  6961. * matching `regexp`.
  6962. *
  6963. * should.not.throw(fn, Error, 'function does not throw');
  6964. *
  6965. * @name not.throw
  6966. * @alias not.Throw
  6967. * @param {Function} function
  6968. * @param {ErrorConstructor} constructor
  6969. * @param {RegExp} regexp
  6970. * @param {String} message
  6971. * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
  6972. * @namespace Should
  6973. * @api public
  6974. */
  6975. should.not.Throw = function (fn, errt, errs, msg) {
  6976. new Assertion(fn, msg).to.not.Throw(errt, errs);
  6977. };
  6978. /**
  6979. * ### .not.exist
  6980. *
  6981. * Asserts that the target is neither `null` nor `undefined`.
  6982. *
  6983. * var bar = null;
  6984. *
  6985. * should.not.exist(bar, 'bar does not exist');
  6986. *
  6987. * @name not.exist
  6988. * @namespace Should
  6989. * @api public
  6990. */
  6991. should.not.exist = function (val, msg) {
  6992. new Assertion(val, msg).to.not.exist;
  6993. }
  6994. should['throw'] = should['Throw'];
  6995. should.not['throw'] = should.not['Throw'];
  6996. return should;
  6997. };
  6998. chai.should = loadShould;
  6999. chai.Should = loadShould;
  7000. };
  7001. },{}],9:[function(require,module,exports){
  7002. /*!
  7003. * Chai - addChainingMethod utility
  7004. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7005. * MIT Licensed
  7006. */
  7007. /*!
  7008. * Module dependencies
  7009. */
  7010. var addLengthGuard = require('./addLengthGuard');
  7011. var chai = require('../../chai');
  7012. var flag = require('./flag');
  7013. var proxify = require('./proxify');
  7014. var transferFlags = require('./transferFlags');
  7015. /*!
  7016. * Module variables
  7017. */
  7018. // Check whether `Object.setPrototypeOf` is supported
  7019. var canSetPrototype = typeof Object.setPrototypeOf === 'function';
  7020. // Without `Object.setPrototypeOf` support, this module will need to add properties to a function.
  7021. // However, some of functions' own props are not configurable and should be skipped.
  7022. var testFn = function() {};
  7023. var excludeNames = Object.getOwnPropertyNames(testFn).filter(function(name) {
  7024. var propDesc = Object.getOwnPropertyDescriptor(testFn, name);
  7025. // Note: PhantomJS 1.x includes `callee` as one of `testFn`'s own properties,
  7026. // but then returns `undefined` as the property descriptor for `callee`. As a
  7027. // workaround, we perform an otherwise unnecessary type-check for `propDesc`,
  7028. // and then filter it out if it's not an object as it should be.
  7029. if (typeof propDesc !== 'object')
  7030. return true;
  7031. return !propDesc.configurable;
  7032. });
  7033. // Cache `Function` properties
  7034. var call = Function.prototype.call,
  7035. apply = Function.prototype.apply;
  7036. /**
  7037. * ### .addChainableMethod(ctx, name, method, chainingBehavior)
  7038. *
  7039. * Adds a method to an object, such that the method can also be chained.
  7040. *
  7041. * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
  7042. * var obj = utils.flag(this, 'object');
  7043. * new chai.Assertion(obj).to.be.equal(str);
  7044. * });
  7045. *
  7046. * Can also be accessed directly from `chai.Assertion`.
  7047. *
  7048. * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
  7049. *
  7050. * The result can then be used as both a method assertion, executing both `method` and
  7051. * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
  7052. *
  7053. * expect(fooStr).to.be.foo('bar');
  7054. * expect(fooStr).to.be.foo.equal('foo');
  7055. *
  7056. * @param {Object} ctx object to which the method is added
  7057. * @param {String} name of method to add
  7058. * @param {Function} method function to be used for `name`, when called
  7059. * @param {Function} chainingBehavior function to be called every time the property is accessed
  7060. * @namespace Utils
  7061. * @name addChainableMethod
  7062. * @api public
  7063. */
  7064. module.exports = function addChainableMethod(ctx, name, method, chainingBehavior) {
  7065. if (typeof chainingBehavior !== 'function') {
  7066. chainingBehavior = function () { };
  7067. }
  7068. var chainableBehavior = {
  7069. method: method
  7070. , chainingBehavior: chainingBehavior
  7071. };
  7072. // save the methods so we can overwrite them later, if we need to.
  7073. if (!ctx.__methods) {
  7074. ctx.__methods = {};
  7075. }
  7076. ctx.__methods[name] = chainableBehavior;
  7077. Object.defineProperty(ctx, name,
  7078. { get: function chainableMethodGetter() {
  7079. chainableBehavior.chainingBehavior.call(this);
  7080. var chainableMethodWrapper = function () {
  7081. // Setting the `ssfi` flag to `chainableMethodWrapper` causes this
  7082. // function to be the starting point for removing implementation
  7083. // frames from the stack trace of a failed assertion.
  7084. //
  7085. // However, we only want to use this function as the starting point if
  7086. // the `lockSsfi` flag isn't set.
  7087. //
  7088. // If the `lockSsfi` flag is set, then this assertion is being
  7089. // invoked from inside of another assertion. In this case, the `ssfi`
  7090. // flag has already been set by the outer assertion.
  7091. //
  7092. // Note that overwriting a chainable method merely replaces the saved
  7093. // methods in `ctx.__methods` instead of completely replacing the
  7094. // overwritten assertion. Therefore, an overwriting assertion won't
  7095. // set the `ssfi` or `lockSsfi` flags.
  7096. if (!flag(this, 'lockSsfi')) {
  7097. flag(this, 'ssfi', chainableMethodWrapper);
  7098. }
  7099. var result = chainableBehavior.method.apply(this, arguments);
  7100. if (result !== undefined) {
  7101. return result;
  7102. }
  7103. var newAssertion = new chai.Assertion();
  7104. transferFlags(this, newAssertion);
  7105. return newAssertion;
  7106. };
  7107. addLengthGuard(chainableMethodWrapper, name, true);
  7108. // Use `Object.setPrototypeOf` if available
  7109. if (canSetPrototype) {
  7110. // Inherit all properties from the object by replacing the `Function` prototype
  7111. var prototype = Object.create(this);
  7112. // Restore the `call` and `apply` methods from `Function`
  7113. prototype.call = call;
  7114. prototype.apply = apply;
  7115. Object.setPrototypeOf(chainableMethodWrapper, prototype);
  7116. }
  7117. // Otherwise, redefine all properties (slow!)
  7118. else {
  7119. var asserterNames = Object.getOwnPropertyNames(ctx);
  7120. asserterNames.forEach(function (asserterName) {
  7121. if (excludeNames.indexOf(asserterName) !== -1) {
  7122. return;
  7123. }
  7124. var pd = Object.getOwnPropertyDescriptor(ctx, asserterName);
  7125. Object.defineProperty(chainableMethodWrapper, asserterName, pd);
  7126. });
  7127. }
  7128. transferFlags(this, chainableMethodWrapper);
  7129. return proxify(chainableMethodWrapper);
  7130. }
  7131. , configurable: true
  7132. });
  7133. };
  7134. },{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":30,"./transferFlags":32}],10:[function(require,module,exports){
  7135. var fnLengthDesc = Object.getOwnPropertyDescriptor(function () {}, 'length');
  7136. /*!
  7137. * Chai - addLengthGuard utility
  7138. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7139. * MIT Licensed
  7140. */
  7141. /**
  7142. * ### .addLengthGuard(fn, assertionName, isChainable)
  7143. *
  7144. * Define `length` as a getter on the given uninvoked method assertion. The
  7145. * getter acts as a guard against chaining `length` directly off of an uninvoked
  7146. * method assertion, which is a problem because it references `function`'s
  7147. * built-in `length` property instead of Chai's `length` assertion. When the
  7148. * getter catches the user making this mistake, it throws an error with a
  7149. * helpful message.
  7150. *
  7151. * There are two ways in which this mistake can be made. The first way is by
  7152. * chaining the `length` assertion directly off of an uninvoked chainable
  7153. * method. In this case, Chai suggests that the user use `lengthOf` instead. The
  7154. * second way is by chaining the `length` assertion directly off of an uninvoked
  7155. * non-chainable method. Non-chainable methods must be invoked prior to
  7156. * chaining. In this case, Chai suggests that the user consult the docs for the
  7157. * given assertion.
  7158. *
  7159. * If the `length` property of functions is unconfigurable, then return `fn`
  7160. * without modification.
  7161. *
  7162. * Note that in ES6, the function's `length` property is configurable, so once
  7163. * support for legacy environments is dropped, Chai's `length` property can
  7164. * replace the built-in function's `length` property, and this length guard will
  7165. * no longer be necessary. In the mean time, maintaining consistency across all
  7166. * environments is the priority.
  7167. *
  7168. * @param {Function} fn
  7169. * @param {String} assertionName
  7170. * @param {Boolean} isChainable
  7171. * @namespace Utils
  7172. * @name addLengthGuard
  7173. */
  7174. module.exports = function addLengthGuard (fn, assertionName, isChainable) {
  7175. if (!fnLengthDesc.configurable) return fn;
  7176. Object.defineProperty(fn, 'length', {
  7177. get: function () {
  7178. if (isChainable) {
  7179. throw Error('Invalid Chai property: ' + assertionName + '.length. Due' +
  7180. ' to a compatibility issue, "length" cannot directly follow "' +
  7181. assertionName + '". Use "' + assertionName + '.lengthOf" instead.');
  7182. }
  7183. throw Error('Invalid Chai property: ' + assertionName + '.length. See' +
  7184. ' docs for proper usage of "' + assertionName + '".');
  7185. }
  7186. });
  7187. return fn;
  7188. };
  7189. },{}],11:[function(require,module,exports){
  7190. /*!
  7191. * Chai - addMethod utility
  7192. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7193. * MIT Licensed
  7194. */
  7195. var addLengthGuard = require('./addLengthGuard');
  7196. var chai = require('../../chai');
  7197. var flag = require('./flag');
  7198. var proxify = require('./proxify');
  7199. var transferFlags = require('./transferFlags');
  7200. /**
  7201. * ### .addMethod(ctx, name, method)
  7202. *
  7203. * Adds a method to the prototype of an object.
  7204. *
  7205. * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
  7206. * var obj = utils.flag(this, 'object');
  7207. * new chai.Assertion(obj).to.be.equal(str);
  7208. * });
  7209. *
  7210. * Can also be accessed directly from `chai.Assertion`.
  7211. *
  7212. * chai.Assertion.addMethod('foo', fn);
  7213. *
  7214. * Then can be used as any other assertion.
  7215. *
  7216. * expect(fooStr).to.be.foo('bar');
  7217. *
  7218. * @param {Object} ctx object to which the method is added
  7219. * @param {String} name of method to add
  7220. * @param {Function} method function to be used for name
  7221. * @namespace Utils
  7222. * @name addMethod
  7223. * @api public
  7224. */
  7225. module.exports = function addMethod(ctx, name, method) {
  7226. var methodWrapper = function () {
  7227. // Setting the `ssfi` flag to `methodWrapper` causes this function to be the
  7228. // starting point for removing implementation frames from the stack trace of
  7229. // a failed assertion.
  7230. //
  7231. // However, we only want to use this function as the starting point if the
  7232. // `lockSsfi` flag isn't set.
  7233. //
  7234. // If the `lockSsfi` flag is set, then either this assertion has been
  7235. // overwritten by another assertion, or this assertion is being invoked from
  7236. // inside of another assertion. In the first case, the `ssfi` flag has
  7237. // already been set by the overwriting assertion. In the second case, the
  7238. // `ssfi` flag has already been set by the outer assertion.
  7239. if (!flag(this, 'lockSsfi')) {
  7240. flag(this, 'ssfi', methodWrapper);
  7241. }
  7242. var result = method.apply(this, arguments);
  7243. if (result !== undefined)
  7244. return result;
  7245. var newAssertion = new chai.Assertion();
  7246. transferFlags(this, newAssertion);
  7247. return newAssertion;
  7248. };
  7249. addLengthGuard(methodWrapper, name, false);
  7250. ctx[name] = proxify(methodWrapper, name);
  7251. };
  7252. },{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":30,"./transferFlags":32}],12:[function(require,module,exports){
  7253. /*!
  7254. * Chai - addProperty utility
  7255. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7256. * MIT Licensed
  7257. */
  7258. var chai = require('../../chai');
  7259. var flag = require('./flag');
  7260. var isProxyEnabled = require('./isProxyEnabled');
  7261. var transferFlags = require('./transferFlags');
  7262. /**
  7263. * ### .addProperty(ctx, name, getter)
  7264. *
  7265. * Adds a property to the prototype of an object.
  7266. *
  7267. * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
  7268. * var obj = utils.flag(this, 'object');
  7269. * new chai.Assertion(obj).to.be.instanceof(Foo);
  7270. * });
  7271. *
  7272. * Can also be accessed directly from `chai.Assertion`.
  7273. *
  7274. * chai.Assertion.addProperty('foo', fn);
  7275. *
  7276. * Then can be used as any other assertion.
  7277. *
  7278. * expect(myFoo).to.be.foo;
  7279. *
  7280. * @param {Object} ctx object to which the property is added
  7281. * @param {String} name of property to add
  7282. * @param {Function} getter function to be used for name
  7283. * @namespace Utils
  7284. * @name addProperty
  7285. * @api public
  7286. */
  7287. module.exports = function addProperty(ctx, name, getter) {
  7288. getter = getter === undefined ? function () {} : getter;
  7289. Object.defineProperty(ctx, name,
  7290. { get: function propertyGetter() {
  7291. // Setting the `ssfi` flag to `propertyGetter` causes this function to
  7292. // be the starting point for removing implementation frames from the
  7293. // stack trace of a failed assertion.
  7294. //
  7295. // However, we only want to use this function as the starting point if
  7296. // the `lockSsfi` flag isn't set and proxy protection is disabled.
  7297. //
  7298. // If the `lockSsfi` flag is set, then either this assertion has been
  7299. // overwritten by another assertion, or this assertion is being invoked
  7300. // from inside of another assertion. In the first case, the `ssfi` flag
  7301. // has already been set by the overwriting assertion. In the second
  7302. // case, the `ssfi` flag has already been set by the outer assertion.
  7303. //
  7304. // If proxy protection is enabled, then the `ssfi` flag has already been
  7305. // set by the proxy getter.
  7306. if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
  7307. flag(this, 'ssfi', propertyGetter);
  7308. }
  7309. var result = getter.call(this);
  7310. if (result !== undefined)
  7311. return result;
  7312. var newAssertion = new chai.Assertion();
  7313. transferFlags(this, newAssertion);
  7314. return newAssertion;
  7315. }
  7316. , configurable: true
  7317. });
  7318. };
  7319. },{"../../chai":2,"./flag":15,"./isProxyEnabled":25,"./transferFlags":32}],13:[function(require,module,exports){
  7320. /*!
  7321. * Chai - compareByInspect utility
  7322. * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
  7323. * MIT Licensed
  7324. */
  7325. /*!
  7326. * Module dependencies
  7327. */
  7328. var inspect = require('./inspect');
  7329. /**
  7330. * ### .compareByInspect(mixed, mixed)
  7331. *
  7332. * To be used as a compareFunction with Array.prototype.sort. Compares elements
  7333. * using inspect instead of default behavior of using toString so that Symbols
  7334. * and objects with irregular/missing toString can still be sorted without a
  7335. * TypeError.
  7336. *
  7337. * @param {Mixed} first element to compare
  7338. * @param {Mixed} second element to compare
  7339. * @returns {Number} -1 if 'a' should come before 'b'; otherwise 1
  7340. * @name compareByInspect
  7341. * @namespace Utils
  7342. * @api public
  7343. */
  7344. module.exports = function compareByInspect(a, b) {
  7345. return inspect(a) < inspect(b) ? -1 : 1;
  7346. };
  7347. },{"./inspect":23}],14:[function(require,module,exports){
  7348. /*!
  7349. * Chai - expectTypes utility
  7350. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7351. * MIT Licensed
  7352. */
  7353. /**
  7354. * ### .expectTypes(obj, types)
  7355. *
  7356. * Ensures that the object being tested against is of a valid type.
  7357. *
  7358. * utils.expectTypes(this, ['array', 'object', 'string']);
  7359. *
  7360. * @param {Mixed} obj constructed Assertion
  7361. * @param {Array} type A list of allowed types for this assertion
  7362. * @namespace Utils
  7363. * @name expectTypes
  7364. * @api public
  7365. */
  7366. var AssertionError = require('assertion-error');
  7367. var flag = require('./flag');
  7368. var type = require('type-detect');
  7369. module.exports = function expectTypes(obj, types) {
  7370. var flagMsg = flag(obj, 'message');
  7371. var ssfi = flag(obj, 'ssfi');
  7372. flagMsg = flagMsg ? flagMsg + ': ' : '';
  7373. obj = flag(obj, 'object');
  7374. types = types.map(function (t) { return t.toLowerCase(); });
  7375. types.sort();
  7376. // Transforms ['lorem', 'ipsum'] into 'a lorem, or an ipsum'
  7377. var str = types.map(function (t, index) {
  7378. var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a';
  7379. var or = types.length > 1 && index === types.length - 1 ? 'or ' : '';
  7380. return or + art + ' ' + t;
  7381. }).join(', ');
  7382. var objType = type(obj).toLowerCase();
  7383. if (!types.some(function (expected) { return objType === expected; })) {
  7384. throw new AssertionError(
  7385. flagMsg + 'object tested must be ' + str + ', but ' + objType + ' given',
  7386. undefined,
  7387. ssfi
  7388. );
  7389. }
  7390. };
  7391. },{"./flag":15,"assertion-error":33,"type-detect":39}],15:[function(require,module,exports){
  7392. /*!
  7393. * Chai - flag utility
  7394. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7395. * MIT Licensed
  7396. */
  7397. /**
  7398. * ### .flag(object, key, [value])
  7399. *
  7400. * Get or set a flag value on an object. If a
  7401. * value is provided it will be set, else it will
  7402. * return the currently set value or `undefined` if
  7403. * the value is not set.
  7404. *
  7405. * utils.flag(this, 'foo', 'bar'); // setter
  7406. * utils.flag(this, 'foo'); // getter, returns `bar`
  7407. *
  7408. * @param {Object} object constructed Assertion
  7409. * @param {String} key
  7410. * @param {Mixed} value (optional)
  7411. * @namespace Utils
  7412. * @name flag
  7413. * @api private
  7414. */
  7415. module.exports = function flag(obj, key, value) {
  7416. var flags = obj.__flags || (obj.__flags = Object.create(null));
  7417. if (arguments.length === 3) {
  7418. flags[key] = value;
  7419. } else {
  7420. return flags[key];
  7421. }
  7422. };
  7423. },{}],16:[function(require,module,exports){
  7424. /*!
  7425. * Chai - getActual utility
  7426. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7427. * MIT Licensed
  7428. */
  7429. /**
  7430. * ### .getActual(object, [actual])
  7431. *
  7432. * Returns the `actual` value for an Assertion.
  7433. *
  7434. * @param {Object} object (constructed Assertion)
  7435. * @param {Arguments} chai.Assertion.prototype.assert arguments
  7436. * @namespace Utils
  7437. * @name getActual
  7438. */
  7439. module.exports = function getActual(obj, args) {
  7440. return args.length > 4 ? args[4] : obj._obj;
  7441. };
  7442. },{}],17:[function(require,module,exports){
  7443. /*!
  7444. * Chai - message composition utility
  7445. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7446. * MIT Licensed
  7447. */
  7448. /*!
  7449. * Module dependencies
  7450. */
  7451. var flag = require('./flag')
  7452. , getActual = require('./getActual')
  7453. , objDisplay = require('./objDisplay');
  7454. /**
  7455. * ### .getMessage(object, message, negateMessage)
  7456. *
  7457. * Construct the error message based on flags
  7458. * and template tags. Template tags will return
  7459. * a stringified inspection of the object referenced.
  7460. *
  7461. * Message template tags:
  7462. * - `#{this}` current asserted object
  7463. * - `#{act}` actual value
  7464. * - `#{exp}` expected value
  7465. *
  7466. * @param {Object} object (constructed Assertion)
  7467. * @param {Arguments} chai.Assertion.prototype.assert arguments
  7468. * @namespace Utils
  7469. * @name getMessage
  7470. * @api public
  7471. */
  7472. module.exports = function getMessage(obj, args) {
  7473. var negate = flag(obj, 'negate')
  7474. , val = flag(obj, 'object')
  7475. , expected = args[3]
  7476. , actual = getActual(obj, args)
  7477. , msg = negate ? args[2] : args[1]
  7478. , flagMsg = flag(obj, 'message');
  7479. if(typeof msg === "function") msg = msg();
  7480. msg = msg || '';
  7481. msg = msg
  7482. .replace(/#\{this\}/g, function () { return objDisplay(val); })
  7483. .replace(/#\{act\}/g, function () { return objDisplay(actual); })
  7484. .replace(/#\{exp\}/g, function () { return objDisplay(expected); });
  7485. return flagMsg ? flagMsg + ': ' + msg : msg;
  7486. };
  7487. },{"./flag":15,"./getActual":16,"./objDisplay":26}],18:[function(require,module,exports){
  7488. var type = require('type-detect');
  7489. var flag = require('./flag');
  7490. function isObjectType(obj) {
  7491. var objectType = type(obj);
  7492. var objectTypes = ['Array', 'Object', 'function'];
  7493. return objectTypes.indexOf(objectType) !== -1;
  7494. }
  7495. /**
  7496. * ### .getOperator(message)
  7497. *
  7498. * Extract the operator from error message.
  7499. * Operator defined is based on below link
  7500. * https://nodejs.org/api/assert.html#assert_assert.
  7501. *
  7502. * Returns the `operator` or `undefined` value for an Assertion.
  7503. *
  7504. * @param {Object} object (constructed Assertion)
  7505. * @param {Arguments} chai.Assertion.prototype.assert arguments
  7506. * @namespace Utils
  7507. * @name getOperator
  7508. * @api public
  7509. */
  7510. module.exports = function getOperator(obj, args) {
  7511. var operator = flag(obj, 'operator');
  7512. var negate = flag(obj, 'negate');
  7513. var expected = args[3];
  7514. var msg = negate ? args[2] : args[1];
  7515. if (operator) {
  7516. return operator;
  7517. }
  7518. if (typeof msg === 'function') msg = msg();
  7519. msg = msg || '';
  7520. if (!msg) {
  7521. return undefined;
  7522. }
  7523. if (/\shave\s/.test(msg)) {
  7524. return undefined;
  7525. }
  7526. var isObject = isObjectType(expected);
  7527. if (/\snot\s/.test(msg)) {
  7528. return isObject ? 'notDeepStrictEqual' : 'notStrictEqual';
  7529. }
  7530. return isObject ? 'deepStrictEqual' : 'strictEqual';
  7531. };
  7532. },{"./flag":15,"type-detect":39}],19:[function(require,module,exports){
  7533. /*!
  7534. * Chai - getOwnEnumerableProperties utility
  7535. * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
  7536. * MIT Licensed
  7537. */
  7538. /*!
  7539. * Module dependencies
  7540. */
  7541. var getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols');
  7542. /**
  7543. * ### .getOwnEnumerableProperties(object)
  7544. *
  7545. * This allows the retrieval of directly-owned enumerable property names and
  7546. * symbols of an object. This function is necessary because Object.keys only
  7547. * returns enumerable property names, not enumerable property symbols.
  7548. *
  7549. * @param {Object} object
  7550. * @returns {Array}
  7551. * @namespace Utils
  7552. * @name getOwnEnumerableProperties
  7553. * @api public
  7554. */
  7555. module.exports = function getOwnEnumerableProperties(obj) {
  7556. return Object.keys(obj).concat(getOwnEnumerablePropertySymbols(obj));
  7557. };
  7558. },{"./getOwnEnumerablePropertySymbols":20}],20:[function(require,module,exports){
  7559. /*!
  7560. * Chai - getOwnEnumerablePropertySymbols utility
  7561. * Copyright(c) 2011-2016 Jake Luer <jake@alogicalparadox.com>
  7562. * MIT Licensed
  7563. */
  7564. /**
  7565. * ### .getOwnEnumerablePropertySymbols(object)
  7566. *
  7567. * This allows the retrieval of directly-owned enumerable property symbols of an
  7568. * object. This function is necessary because Object.getOwnPropertySymbols
  7569. * returns both enumerable and non-enumerable property symbols.
  7570. *
  7571. * @param {Object} object
  7572. * @returns {Array}
  7573. * @namespace Utils
  7574. * @name getOwnEnumerablePropertySymbols
  7575. * @api public
  7576. */
  7577. module.exports = function getOwnEnumerablePropertySymbols(obj) {
  7578. if (typeof Object.getOwnPropertySymbols !== 'function') return [];
  7579. return Object.getOwnPropertySymbols(obj).filter(function (sym) {
  7580. return Object.getOwnPropertyDescriptor(obj, sym).enumerable;
  7581. });
  7582. };
  7583. },{}],21:[function(require,module,exports){
  7584. /*!
  7585. * Chai - getProperties utility
  7586. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7587. * MIT Licensed
  7588. */
  7589. /**
  7590. * ### .getProperties(object)
  7591. *
  7592. * This allows the retrieval of property names of an object, enumerable or not,
  7593. * inherited or not.
  7594. *
  7595. * @param {Object} object
  7596. * @returns {Array}
  7597. * @namespace Utils
  7598. * @name getProperties
  7599. * @api public
  7600. */
  7601. module.exports = function getProperties(object) {
  7602. var result = Object.getOwnPropertyNames(object);
  7603. function addProperty(property) {
  7604. if (result.indexOf(property) === -1) {
  7605. result.push(property);
  7606. }
  7607. }
  7608. var proto = Object.getPrototypeOf(object);
  7609. while (proto !== null) {
  7610. Object.getOwnPropertyNames(proto).forEach(addProperty);
  7611. proto = Object.getPrototypeOf(proto);
  7612. }
  7613. return result;
  7614. };
  7615. },{}],22:[function(require,module,exports){
  7616. /*!
  7617. * chai
  7618. * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
  7619. * MIT Licensed
  7620. */
  7621. /*!
  7622. * Dependencies that are used for multiple exports are required here only once
  7623. */
  7624. var pathval = require('pathval');
  7625. /*!
  7626. * test utility
  7627. */
  7628. exports.test = require('./test');
  7629. /*!
  7630. * type utility
  7631. */
  7632. exports.type = require('type-detect');
  7633. /*!
  7634. * expectTypes utility
  7635. */
  7636. exports.expectTypes = require('./expectTypes');
  7637. /*!
  7638. * message utility
  7639. */
  7640. exports.getMessage = require('./getMessage');
  7641. /*!
  7642. * actual utility
  7643. */
  7644. exports.getActual = require('./getActual');
  7645. /*!
  7646. * Inspect util
  7647. */
  7648. exports.inspect = require('./inspect');
  7649. /*!
  7650. * Object Display util
  7651. */
  7652. exports.objDisplay = require('./objDisplay');
  7653. /*!
  7654. * Flag utility
  7655. */
  7656. exports.flag = require('./flag');
  7657. /*!
  7658. * Flag transferring utility
  7659. */
  7660. exports.transferFlags = require('./transferFlags');
  7661. /*!
  7662. * Deep equal utility
  7663. */
  7664. exports.eql = require('deep-eql');
  7665. /*!
  7666. * Deep path info
  7667. */
  7668. exports.getPathInfo = pathval.getPathInfo;
  7669. /*!
  7670. * Check if a property exists
  7671. */
  7672. exports.hasProperty = pathval.hasProperty;
  7673. /*!
  7674. * Function name
  7675. */
  7676. exports.getName = require('get-func-name');
  7677. /*!
  7678. * add Property
  7679. */
  7680. exports.addProperty = require('./addProperty');
  7681. /*!
  7682. * add Method
  7683. */
  7684. exports.addMethod = require('./addMethod');
  7685. /*!
  7686. * overwrite Property
  7687. */
  7688. exports.overwriteProperty = require('./overwriteProperty');
  7689. /*!
  7690. * overwrite Method
  7691. */
  7692. exports.overwriteMethod = require('./overwriteMethod');
  7693. /*!
  7694. * Add a chainable method
  7695. */
  7696. exports.addChainableMethod = require('./addChainableMethod');
  7697. /*!
  7698. * Overwrite chainable method
  7699. */
  7700. exports.overwriteChainableMethod = require('./overwriteChainableMethod');
  7701. /*!
  7702. * Compare by inspect method
  7703. */
  7704. exports.compareByInspect = require('./compareByInspect');
  7705. /*!
  7706. * Get own enumerable property symbols method
  7707. */
  7708. exports.getOwnEnumerablePropertySymbols = require('./getOwnEnumerablePropertySymbols');
  7709. /*!
  7710. * Get own enumerable properties method
  7711. */
  7712. exports.getOwnEnumerableProperties = require('./getOwnEnumerableProperties');
  7713. /*!
  7714. * Checks error against a given set of criteria
  7715. */
  7716. exports.checkError = require('check-error');
  7717. /*!
  7718. * Proxify util
  7719. */
  7720. exports.proxify = require('./proxify');
  7721. /*!
  7722. * addLengthGuard util
  7723. */
  7724. exports.addLengthGuard = require('./addLengthGuard');
  7725. /*!
  7726. * isProxyEnabled helper
  7727. */
  7728. exports.isProxyEnabled = require('./isProxyEnabled');
  7729. /*!
  7730. * isNaN method
  7731. */
  7732. exports.isNaN = require('./isNaN');
  7733. /*!
  7734. * getOperator method
  7735. */
  7736. exports.getOperator = require('./getOperator');
  7737. },{"./addChainableMethod":9,"./addLengthGuard":10,"./addMethod":11,"./addProperty":12,"./compareByInspect":13,"./expectTypes":14,"./flag":15,"./getActual":16,"./getMessage":17,"./getOperator":18,"./getOwnEnumerableProperties":19,"./getOwnEnumerablePropertySymbols":20,"./inspect":23,"./isNaN":24,"./isProxyEnabled":25,"./objDisplay":26,"./overwriteChainableMethod":27,"./overwriteMethod":28,"./overwriteProperty":29,"./proxify":30,"./test":31,"./transferFlags":32,"check-error":34,"deep-eql":35,"get-func-name":36,"pathval":38,"type-detect":39}],23:[function(require,module,exports){
  7738. // This is (almost) directly from Node.js utils
  7739. // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
  7740. var getName = require('get-func-name');
  7741. var loupe = require('loupe');
  7742. var config = require('../config');
  7743. module.exports = inspect;
  7744. /**
  7745. * ### .inspect(obj, [showHidden], [depth], [colors])
  7746. *
  7747. * Echoes the value of a value. Tries to print the value out
  7748. * in the best way possible given the different types.
  7749. *
  7750. * @param {Object} obj The object to print out.
  7751. * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
  7752. * properties of objects. Default is false.
  7753. * @param {Number} depth Depth in which to descend in object. Default is 2.
  7754. * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
  7755. * output. Default is false (no coloring).
  7756. * @namespace Utils
  7757. * @name inspect
  7758. */
  7759. function inspect(obj, showHidden, depth, colors) {
  7760. var options = {
  7761. colors: colors,
  7762. depth: (typeof depth === 'undefined' ? 2 : depth),
  7763. showHidden: showHidden,
  7764. truncate: config.truncateThreshold ? config.truncateThreshold : Infinity,
  7765. };
  7766. return loupe.inspect(obj, options);
  7767. }
  7768. },{"../config":4,"get-func-name":36,"loupe":37}],24:[function(require,module,exports){
  7769. /*!
  7770. * Chai - isNaN utility
  7771. * Copyright(c) 2012-2015 Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  7772. * MIT Licensed
  7773. */
  7774. /**
  7775. * ### .isNaN(value)
  7776. *
  7777. * Checks if the given value is NaN or not.
  7778. *
  7779. * utils.isNaN(NaN); // true
  7780. *
  7781. * @param {Value} The value which has to be checked if it is NaN
  7782. * @name isNaN
  7783. * @api private
  7784. */
  7785. function isNaN(value) {
  7786. // Refer http://www.ecma-international.org/ecma-262/6.0/#sec-isnan-number
  7787. // section's NOTE.
  7788. return value !== value;
  7789. }
  7790. // If ECMAScript 6's Number.isNaN is present, prefer that.
  7791. module.exports = Number.isNaN || isNaN;
  7792. },{}],25:[function(require,module,exports){
  7793. var config = require('../config');
  7794. /*!
  7795. * Chai - isProxyEnabled helper
  7796. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7797. * MIT Licensed
  7798. */
  7799. /**
  7800. * ### .isProxyEnabled()
  7801. *
  7802. * Helper function to check if Chai's proxy protection feature is enabled. If
  7803. * proxies are unsupported or disabled via the user's Chai config, then return
  7804. * false. Otherwise, return true.
  7805. *
  7806. * @namespace Utils
  7807. * @name isProxyEnabled
  7808. */
  7809. module.exports = function isProxyEnabled() {
  7810. return config.useProxy &&
  7811. typeof Proxy !== 'undefined' &&
  7812. typeof Reflect !== 'undefined';
  7813. };
  7814. },{"../config":4}],26:[function(require,module,exports){
  7815. /*!
  7816. * Chai - flag utility
  7817. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7818. * MIT Licensed
  7819. */
  7820. /*!
  7821. * Module dependencies
  7822. */
  7823. var inspect = require('./inspect');
  7824. var config = require('../config');
  7825. /**
  7826. * ### .objDisplay(object)
  7827. *
  7828. * Determines if an object or an array matches
  7829. * criteria to be inspected in-line for error
  7830. * messages or should be truncated.
  7831. *
  7832. * @param {Mixed} javascript object to inspect
  7833. * @returns {string} stringified object
  7834. * @name objDisplay
  7835. * @namespace Utils
  7836. * @api public
  7837. */
  7838. module.exports = function objDisplay(obj) {
  7839. var str = inspect(obj)
  7840. , type = Object.prototype.toString.call(obj);
  7841. if (config.truncateThreshold && str.length >= config.truncateThreshold) {
  7842. if (type === '[object Function]') {
  7843. return !obj.name || obj.name === ''
  7844. ? '[Function]'
  7845. : '[Function: ' + obj.name + ']';
  7846. } else if (type === '[object Array]') {
  7847. return '[ Array(' + obj.length + ') ]';
  7848. } else if (type === '[object Object]') {
  7849. var keys = Object.keys(obj)
  7850. , kstr = keys.length > 2
  7851. ? keys.splice(0, 2).join(', ') + ', ...'
  7852. : keys.join(', ');
  7853. return '{ Object (' + kstr + ') }';
  7854. } else {
  7855. return str;
  7856. }
  7857. } else {
  7858. return str;
  7859. }
  7860. };
  7861. },{"../config":4,"./inspect":23}],27:[function(require,module,exports){
  7862. /*!
  7863. * Chai - overwriteChainableMethod utility
  7864. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7865. * MIT Licensed
  7866. */
  7867. var chai = require('../../chai');
  7868. var transferFlags = require('./transferFlags');
  7869. /**
  7870. * ### .overwriteChainableMethod(ctx, name, method, chainingBehavior)
  7871. *
  7872. * Overwrites an already existing chainable method
  7873. * and provides access to the previous function or
  7874. * property. Must return functions to be used for
  7875. * name.
  7876. *
  7877. * utils.overwriteChainableMethod(chai.Assertion.prototype, 'lengthOf',
  7878. * function (_super) {
  7879. * }
  7880. * , function (_super) {
  7881. * }
  7882. * );
  7883. *
  7884. * Can also be accessed directly from `chai.Assertion`.
  7885. *
  7886. * chai.Assertion.overwriteChainableMethod('foo', fn, fn);
  7887. *
  7888. * Then can be used as any other assertion.
  7889. *
  7890. * expect(myFoo).to.have.lengthOf(3);
  7891. * expect(myFoo).to.have.lengthOf.above(3);
  7892. *
  7893. * @param {Object} ctx object whose method / property is to be overwritten
  7894. * @param {String} name of method / property to overwrite
  7895. * @param {Function} method function that returns a function to be used for name
  7896. * @param {Function} chainingBehavior function that returns a function to be used for property
  7897. * @namespace Utils
  7898. * @name overwriteChainableMethod
  7899. * @api public
  7900. */
  7901. module.exports = function overwriteChainableMethod(ctx, name, method, chainingBehavior) {
  7902. var chainableBehavior = ctx.__methods[name];
  7903. var _chainingBehavior = chainableBehavior.chainingBehavior;
  7904. chainableBehavior.chainingBehavior = function overwritingChainableMethodGetter() {
  7905. var result = chainingBehavior(_chainingBehavior).call(this);
  7906. if (result !== undefined) {
  7907. return result;
  7908. }
  7909. var newAssertion = new chai.Assertion();
  7910. transferFlags(this, newAssertion);
  7911. return newAssertion;
  7912. };
  7913. var _method = chainableBehavior.method;
  7914. chainableBehavior.method = function overwritingChainableMethodWrapper() {
  7915. var result = method(_method).apply(this, arguments);
  7916. if (result !== undefined) {
  7917. return result;
  7918. }
  7919. var newAssertion = new chai.Assertion();
  7920. transferFlags(this, newAssertion);
  7921. return newAssertion;
  7922. };
  7923. };
  7924. },{"../../chai":2,"./transferFlags":32}],28:[function(require,module,exports){
  7925. /*!
  7926. * Chai - overwriteMethod utility
  7927. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  7928. * MIT Licensed
  7929. */
  7930. var addLengthGuard = require('./addLengthGuard');
  7931. var chai = require('../../chai');
  7932. var flag = require('./flag');
  7933. var proxify = require('./proxify');
  7934. var transferFlags = require('./transferFlags');
  7935. /**
  7936. * ### .overwriteMethod(ctx, name, fn)
  7937. *
  7938. * Overwrites an already existing method and provides
  7939. * access to previous function. Must return function
  7940. * to be used for name.
  7941. *
  7942. * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
  7943. * return function (str) {
  7944. * var obj = utils.flag(this, 'object');
  7945. * if (obj instanceof Foo) {
  7946. * new chai.Assertion(obj.value).to.equal(str);
  7947. * } else {
  7948. * _super.apply(this, arguments);
  7949. * }
  7950. * }
  7951. * });
  7952. *
  7953. * Can also be accessed directly from `chai.Assertion`.
  7954. *
  7955. * chai.Assertion.overwriteMethod('foo', fn);
  7956. *
  7957. * Then can be used as any other assertion.
  7958. *
  7959. * expect(myFoo).to.equal('bar');
  7960. *
  7961. * @param {Object} ctx object whose method is to be overwritten
  7962. * @param {String} name of method to overwrite
  7963. * @param {Function} method function that returns a function to be used for name
  7964. * @namespace Utils
  7965. * @name overwriteMethod
  7966. * @api public
  7967. */
  7968. module.exports = function overwriteMethod(ctx, name, method) {
  7969. var _method = ctx[name]
  7970. , _super = function () {
  7971. throw new Error(name + ' is not a function');
  7972. };
  7973. if (_method && 'function' === typeof _method)
  7974. _super = _method;
  7975. var overwritingMethodWrapper = function () {
  7976. // Setting the `ssfi` flag to `overwritingMethodWrapper` causes this
  7977. // function to be the starting point for removing implementation frames from
  7978. // the stack trace of a failed assertion.
  7979. //
  7980. // However, we only want to use this function as the starting point if the
  7981. // `lockSsfi` flag isn't set.
  7982. //
  7983. // If the `lockSsfi` flag is set, then either this assertion has been
  7984. // overwritten by another assertion, or this assertion is being invoked from
  7985. // inside of another assertion. In the first case, the `ssfi` flag has
  7986. // already been set by the overwriting assertion. In the second case, the
  7987. // `ssfi` flag has already been set by the outer assertion.
  7988. if (!flag(this, 'lockSsfi')) {
  7989. flag(this, 'ssfi', overwritingMethodWrapper);
  7990. }
  7991. // Setting the `lockSsfi` flag to `true` prevents the overwritten assertion
  7992. // from changing the `ssfi` flag. By this point, the `ssfi` flag is already
  7993. // set to the correct starting point for this assertion.
  7994. var origLockSsfi = flag(this, 'lockSsfi');
  7995. flag(this, 'lockSsfi', true);
  7996. var result = method(_super).apply(this, arguments);
  7997. flag(this, 'lockSsfi', origLockSsfi);
  7998. if (result !== undefined) {
  7999. return result;
  8000. }
  8001. var newAssertion = new chai.Assertion();
  8002. transferFlags(this, newAssertion);
  8003. return newAssertion;
  8004. }
  8005. addLengthGuard(overwritingMethodWrapper, name, false);
  8006. ctx[name] = proxify(overwritingMethodWrapper, name);
  8007. };
  8008. },{"../../chai":2,"./addLengthGuard":10,"./flag":15,"./proxify":30,"./transferFlags":32}],29:[function(require,module,exports){
  8009. /*!
  8010. * Chai - overwriteProperty utility
  8011. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8012. * MIT Licensed
  8013. */
  8014. var chai = require('../../chai');
  8015. var flag = require('./flag');
  8016. var isProxyEnabled = require('./isProxyEnabled');
  8017. var transferFlags = require('./transferFlags');
  8018. /**
  8019. * ### .overwriteProperty(ctx, name, fn)
  8020. *
  8021. * Overwrites an already existing property getter and provides
  8022. * access to previous value. Must return function to use as getter.
  8023. *
  8024. * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
  8025. * return function () {
  8026. * var obj = utils.flag(this, 'object');
  8027. * if (obj instanceof Foo) {
  8028. * new chai.Assertion(obj.name).to.equal('bar');
  8029. * } else {
  8030. * _super.call(this);
  8031. * }
  8032. * }
  8033. * });
  8034. *
  8035. *
  8036. * Can also be accessed directly from `chai.Assertion`.
  8037. *
  8038. * chai.Assertion.overwriteProperty('foo', fn);
  8039. *
  8040. * Then can be used as any other assertion.
  8041. *
  8042. * expect(myFoo).to.be.ok;
  8043. *
  8044. * @param {Object} ctx object whose property is to be overwritten
  8045. * @param {String} name of property to overwrite
  8046. * @param {Function} getter function that returns a getter function to be used for name
  8047. * @namespace Utils
  8048. * @name overwriteProperty
  8049. * @api public
  8050. */
  8051. module.exports = function overwriteProperty(ctx, name, getter) {
  8052. var _get = Object.getOwnPropertyDescriptor(ctx, name)
  8053. , _super = function () {};
  8054. if (_get && 'function' === typeof _get.get)
  8055. _super = _get.get
  8056. Object.defineProperty(ctx, name,
  8057. { get: function overwritingPropertyGetter() {
  8058. // Setting the `ssfi` flag to `overwritingPropertyGetter` causes this
  8059. // function to be the starting point for removing implementation frames
  8060. // from the stack trace of a failed assertion.
  8061. //
  8062. // However, we only want to use this function as the starting point if
  8063. // the `lockSsfi` flag isn't set and proxy protection is disabled.
  8064. //
  8065. // If the `lockSsfi` flag is set, then either this assertion has been
  8066. // overwritten by another assertion, or this assertion is being invoked
  8067. // from inside of another assertion. In the first case, the `ssfi` flag
  8068. // has already been set by the overwriting assertion. In the second
  8069. // case, the `ssfi` flag has already been set by the outer assertion.
  8070. //
  8071. // If proxy protection is enabled, then the `ssfi` flag has already been
  8072. // set by the proxy getter.
  8073. if (!isProxyEnabled() && !flag(this, 'lockSsfi')) {
  8074. flag(this, 'ssfi', overwritingPropertyGetter);
  8075. }
  8076. // Setting the `lockSsfi` flag to `true` prevents the overwritten
  8077. // assertion from changing the `ssfi` flag. By this point, the `ssfi`
  8078. // flag is already set to the correct starting point for this assertion.
  8079. var origLockSsfi = flag(this, 'lockSsfi');
  8080. flag(this, 'lockSsfi', true);
  8081. var result = getter(_super).call(this);
  8082. flag(this, 'lockSsfi', origLockSsfi);
  8083. if (result !== undefined) {
  8084. return result;
  8085. }
  8086. var newAssertion = new chai.Assertion();
  8087. transferFlags(this, newAssertion);
  8088. return newAssertion;
  8089. }
  8090. , configurable: true
  8091. });
  8092. };
  8093. },{"../../chai":2,"./flag":15,"./isProxyEnabled":25,"./transferFlags":32}],30:[function(require,module,exports){
  8094. var config = require('../config');
  8095. var flag = require('./flag');
  8096. var getProperties = require('./getProperties');
  8097. var isProxyEnabled = require('./isProxyEnabled');
  8098. /*!
  8099. * Chai - proxify utility
  8100. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8101. * MIT Licensed
  8102. */
  8103. /**
  8104. * ### .proxify(object)
  8105. *
  8106. * Return a proxy of given object that throws an error when a non-existent
  8107. * property is read. By default, the root cause is assumed to be a misspelled
  8108. * property, and thus an attempt is made to offer a reasonable suggestion from
  8109. * the list of existing properties. However, if a nonChainableMethodName is
  8110. * provided, then the root cause is instead a failure to invoke a non-chainable
  8111. * method prior to reading the non-existent property.
  8112. *
  8113. * If proxies are unsupported or disabled via the user's Chai config, then
  8114. * return object without modification.
  8115. *
  8116. * @param {Object} obj
  8117. * @param {String} nonChainableMethodName
  8118. * @namespace Utils
  8119. * @name proxify
  8120. */
  8121. var builtins = ['__flags', '__methods', '_obj', 'assert'];
  8122. module.exports = function proxify(obj, nonChainableMethodName) {
  8123. if (!isProxyEnabled()) return obj;
  8124. return new Proxy(obj, {
  8125. get: function proxyGetter(target, property) {
  8126. // This check is here because we should not throw errors on Symbol properties
  8127. // such as `Symbol.toStringTag`.
  8128. // The values for which an error should be thrown can be configured using
  8129. // the `config.proxyExcludedKeys` setting.
  8130. if (typeof property === 'string' &&
  8131. config.proxyExcludedKeys.indexOf(property) === -1 &&
  8132. !Reflect.has(target, property)) {
  8133. // Special message for invalid property access of non-chainable methods.
  8134. if (nonChainableMethodName) {
  8135. throw Error('Invalid Chai property: ' + nonChainableMethodName + '.' +
  8136. property + '. See docs for proper usage of "' +
  8137. nonChainableMethodName + '".');
  8138. }
  8139. // If the property is reasonably close to an existing Chai property,
  8140. // suggest that property to the user. Only suggest properties with a
  8141. // distance less than 4.
  8142. var suggestion = null;
  8143. var suggestionDistance = 4;
  8144. getProperties(target).forEach(function(prop) {
  8145. if (
  8146. !Object.prototype.hasOwnProperty(prop) &&
  8147. builtins.indexOf(prop) === -1
  8148. ) {
  8149. var dist = stringDistanceCapped(
  8150. property,
  8151. prop,
  8152. suggestionDistance
  8153. );
  8154. if (dist < suggestionDistance) {
  8155. suggestion = prop;
  8156. suggestionDistance = dist;
  8157. }
  8158. }
  8159. });
  8160. if (suggestion !== null) {
  8161. throw Error('Invalid Chai property: ' + property +
  8162. '. Did you mean "' + suggestion + '"?');
  8163. } else {
  8164. throw Error('Invalid Chai property: ' + property);
  8165. }
  8166. }
  8167. // Use this proxy getter as the starting point for removing implementation
  8168. // frames from the stack trace of a failed assertion. For property
  8169. // assertions, this prevents the proxy getter from showing up in the stack
  8170. // trace since it's invoked before the property getter. For method and
  8171. // chainable method assertions, this flag will end up getting changed to
  8172. // the method wrapper, which is good since this frame will no longer be in
  8173. // the stack once the method is invoked. Note that Chai builtin assertion
  8174. // properties such as `__flags` are skipped since this is only meant to
  8175. // capture the starting point of an assertion. This step is also skipped
  8176. // if the `lockSsfi` flag is set, thus indicating that this assertion is
  8177. // being called from within another assertion. In that case, the `ssfi`
  8178. // flag is already set to the outer assertion's starting point.
  8179. if (builtins.indexOf(property) === -1 && !flag(target, 'lockSsfi')) {
  8180. flag(target, 'ssfi', proxyGetter);
  8181. }
  8182. return Reflect.get(target, property);
  8183. }
  8184. });
  8185. };
  8186. /**
  8187. * # stringDistanceCapped(strA, strB, cap)
  8188. * Return the Levenshtein distance between two strings, but no more than cap.
  8189. * @param {string} strA
  8190. * @param {string} strB
  8191. * @param {number} number
  8192. * @return {number} min(string distance between strA and strB, cap)
  8193. * @api private
  8194. */
  8195. function stringDistanceCapped(strA, strB, cap) {
  8196. if (Math.abs(strA.length - strB.length) >= cap) {
  8197. return cap;
  8198. }
  8199. var memo = [];
  8200. // `memo` is a two-dimensional array containing distances.
  8201. // memo[i][j] is the distance between strA.slice(0, i) and
  8202. // strB.slice(0, j).
  8203. for (var i = 0; i <= strA.length; i++) {
  8204. memo[i] = Array(strB.length + 1).fill(0);
  8205. memo[i][0] = i;
  8206. }
  8207. for (var j = 0; j < strB.length; j++) {
  8208. memo[0][j] = j;
  8209. }
  8210. for (var i = 1; i <= strA.length; i++) {
  8211. var ch = strA.charCodeAt(i - 1);
  8212. for (var j = 1; j <= strB.length; j++) {
  8213. if (Math.abs(i - j) >= cap) {
  8214. memo[i][j] = cap;
  8215. continue;
  8216. }
  8217. memo[i][j] = Math.min(
  8218. memo[i - 1][j] + 1,
  8219. memo[i][j - 1] + 1,
  8220. memo[i - 1][j - 1] +
  8221. (ch === strB.charCodeAt(j - 1) ? 0 : 1)
  8222. );
  8223. }
  8224. }
  8225. return memo[strA.length][strB.length];
  8226. }
  8227. },{"../config":4,"./flag":15,"./getProperties":21,"./isProxyEnabled":25}],31:[function(require,module,exports){
  8228. /*!
  8229. * Chai - test utility
  8230. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8231. * MIT Licensed
  8232. */
  8233. /*!
  8234. * Module dependencies
  8235. */
  8236. var flag = require('./flag');
  8237. /**
  8238. * ### .test(object, expression)
  8239. *
  8240. * Test an object for expression.
  8241. *
  8242. * @param {Object} object (constructed Assertion)
  8243. * @param {Arguments} chai.Assertion.prototype.assert arguments
  8244. * @namespace Utils
  8245. * @name test
  8246. */
  8247. module.exports = function test(obj, args) {
  8248. var negate = flag(obj, 'negate')
  8249. , expr = args[0];
  8250. return negate ? !expr : expr;
  8251. };
  8252. },{"./flag":15}],32:[function(require,module,exports){
  8253. /*!
  8254. * Chai - transferFlags utility
  8255. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  8256. * MIT Licensed
  8257. */
  8258. /**
  8259. * ### .transferFlags(assertion, object, includeAll = true)
  8260. *
  8261. * Transfer all the flags for `assertion` to `object`. If
  8262. * `includeAll` is set to `false`, then the base Chai
  8263. * assertion flags (namely `object`, `ssfi`, `lockSsfi`,
  8264. * and `message`) will not be transferred.
  8265. *
  8266. *
  8267. * var newAssertion = new Assertion();
  8268. * utils.transferFlags(assertion, newAssertion);
  8269. *
  8270. * var anotherAssertion = new Assertion(myObj);
  8271. * utils.transferFlags(assertion, anotherAssertion, false);
  8272. *
  8273. * @param {Assertion} assertion the assertion to transfer the flags from
  8274. * @param {Object} object the object to transfer the flags to; usually a new assertion
  8275. * @param {Boolean} includeAll
  8276. * @namespace Utils
  8277. * @name transferFlags
  8278. * @api private
  8279. */
  8280. module.exports = function transferFlags(assertion, object, includeAll) {
  8281. var flags = assertion.__flags || (assertion.__flags = Object.create(null));
  8282. if (!object.__flags) {
  8283. object.__flags = Object.create(null);
  8284. }
  8285. includeAll = arguments.length === 3 ? includeAll : true;
  8286. for (var flag in flags) {
  8287. if (includeAll ||
  8288. (flag !== 'object' && flag !== 'ssfi' && flag !== 'lockSsfi' && flag != 'message')) {
  8289. object.__flags[flag] = flags[flag];
  8290. }
  8291. }
  8292. };
  8293. },{}],33:[function(require,module,exports){
  8294. /*!
  8295. * assertion-error
  8296. * Copyright(c) 2013 Jake Luer <jake@qualiancy.com>
  8297. * MIT Licensed
  8298. */
  8299. /*!
  8300. * Return a function that will copy properties from
  8301. * one object to another excluding any originally
  8302. * listed. Returned function will create a new `{}`.
  8303. *
  8304. * @param {String} excluded properties ...
  8305. * @return {Function}
  8306. */
  8307. function exclude () {
  8308. var excludes = [].slice.call(arguments);
  8309. function excludeProps (res, obj) {
  8310. Object.keys(obj).forEach(function (key) {
  8311. if (!~excludes.indexOf(key)) res[key] = obj[key];
  8312. });
  8313. }
  8314. return function extendExclude () {
  8315. var args = [].slice.call(arguments)
  8316. , i = 0
  8317. , res = {};
  8318. for (; i < args.length; i++) {
  8319. excludeProps(res, args[i]);
  8320. }
  8321. return res;
  8322. };
  8323. };
  8324. /*!
  8325. * Primary Exports
  8326. */
  8327. module.exports = AssertionError;
  8328. /**
  8329. * ### AssertionError
  8330. *
  8331. * An extension of the JavaScript `Error` constructor for
  8332. * assertion and validation scenarios.
  8333. *
  8334. * @param {String} message
  8335. * @param {Object} properties to include (optional)
  8336. * @param {callee} start stack function (optional)
  8337. */
  8338. function AssertionError (message, _props, ssf) {
  8339. var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
  8340. , props = extend(_props || {});
  8341. // default values
  8342. this.message = message || 'Unspecified AssertionError';
  8343. this.showDiff = false;
  8344. // copy from properties
  8345. for (var key in props) {
  8346. this[key] = props[key];
  8347. }
  8348. // capture stack trace
  8349. ssf = ssf || AssertionError;
  8350. if (Error.captureStackTrace) {
  8351. Error.captureStackTrace(this, ssf);
  8352. } else {
  8353. try {
  8354. throw new Error();
  8355. } catch(e) {
  8356. this.stack = e.stack;
  8357. }
  8358. }
  8359. }
  8360. /*!
  8361. * Inherit from Error.prototype
  8362. */
  8363. AssertionError.prototype = Object.create(Error.prototype);
  8364. /*!
  8365. * Statically set name
  8366. */
  8367. AssertionError.prototype.name = 'AssertionError';
  8368. /*!
  8369. * Ensure correct constructor
  8370. */
  8371. AssertionError.prototype.constructor = AssertionError;
  8372. /**
  8373. * Allow errors to be converted to JSON for static transfer.
  8374. *
  8375. * @param {Boolean} include stack (default: `true`)
  8376. * @return {Object} object that can be `JSON.stringify`
  8377. */
  8378. AssertionError.prototype.toJSON = function (stack) {
  8379. var extend = exclude('constructor', 'toJSON', 'stack')
  8380. , props = extend({ name: this.name }, this);
  8381. // include stack if exists and not turned off
  8382. if (false !== stack && this.stack) {
  8383. props.stack = this.stack;
  8384. }
  8385. return props;
  8386. };
  8387. },{}],34:[function(require,module,exports){
  8388. 'use strict';
  8389. /* !
  8390. * Chai - checkError utility
  8391. * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
  8392. * MIT Licensed
  8393. */
  8394. var getFunctionName = require('get-func-name');
  8395. /**
  8396. * ### .checkError
  8397. *
  8398. * Checks that an error conforms to a given set of criteria and/or retrieves information about it.
  8399. *
  8400. * @api public
  8401. */
  8402. /**
  8403. * ### .compatibleInstance(thrown, errorLike)
  8404. *
  8405. * Checks if two instances are compatible (strict equal).
  8406. * Returns false if errorLike is not an instance of Error, because instances
  8407. * can only be compatible if they're both error instances.
  8408. *
  8409. * @name compatibleInstance
  8410. * @param {Error} thrown error
  8411. * @param {Error|ErrorConstructor} errorLike object to compare against
  8412. * @namespace Utils
  8413. * @api public
  8414. */
  8415. function compatibleInstance(thrown, errorLike) {
  8416. return errorLike instanceof Error && thrown === errorLike;
  8417. }
  8418. /**
  8419. * ### .compatibleConstructor(thrown, errorLike)
  8420. *
  8421. * Checks if two constructors are compatible.
  8422. * This function can receive either an error constructor or
  8423. * an error instance as the `errorLike` argument.
  8424. * Constructors are compatible if they're the same or if one is
  8425. * an instance of another.
  8426. *
  8427. * @name compatibleConstructor
  8428. * @param {Error} thrown error
  8429. * @param {Error|ErrorConstructor} errorLike object to compare against
  8430. * @namespace Utils
  8431. * @api public
  8432. */
  8433. function compatibleConstructor(thrown, errorLike) {
  8434. if (errorLike instanceof Error) {
  8435. // If `errorLike` is an instance of any error we compare their constructors
  8436. return thrown.constructor === errorLike.constructor || thrown instanceof errorLike.constructor;
  8437. } else if (errorLike.prototype instanceof Error || errorLike === Error) {
  8438. // If `errorLike` is a constructor that inherits from Error, we compare `thrown` to `errorLike` directly
  8439. return thrown.constructor === errorLike || thrown instanceof errorLike;
  8440. }
  8441. return false;
  8442. }
  8443. /**
  8444. * ### .compatibleMessage(thrown, errMatcher)
  8445. *
  8446. * Checks if an error's message is compatible with a matcher (String or RegExp).
  8447. * If the message contains the String or passes the RegExp test,
  8448. * it is considered compatible.
  8449. *
  8450. * @name compatibleMessage
  8451. * @param {Error} thrown error
  8452. * @param {String|RegExp} errMatcher to look for into the message
  8453. * @namespace Utils
  8454. * @api public
  8455. */
  8456. function compatibleMessage(thrown, errMatcher) {
  8457. var comparisonString = typeof thrown === 'string' ? thrown : thrown.message;
  8458. if (errMatcher instanceof RegExp) {
  8459. return errMatcher.test(comparisonString);
  8460. } else if (typeof errMatcher === 'string') {
  8461. return comparisonString.indexOf(errMatcher) !== -1; // eslint-disable-line no-magic-numbers
  8462. }
  8463. return false;
  8464. }
  8465. /**
  8466. * ### .getConstructorName(errorLike)
  8467. *
  8468. * Gets the constructor name for an Error instance or constructor itself.
  8469. *
  8470. * @name getConstructorName
  8471. * @param {Error|ErrorConstructor} errorLike
  8472. * @namespace Utils
  8473. * @api public
  8474. */
  8475. function getConstructorName(errorLike) {
  8476. var constructorName = errorLike;
  8477. if (errorLike instanceof Error) {
  8478. constructorName = getFunctionName(errorLike.constructor);
  8479. } else if (typeof errorLike === 'function') {
  8480. // If `err` is not an instance of Error it is an error constructor itself or another function.
  8481. // If we've got a common function we get its name, otherwise we may need to create a new instance
  8482. // of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more.
  8483. constructorName = getFunctionName(errorLike);
  8484. if (constructorName === '') {
  8485. var newConstructorName = getFunctionName(new errorLike()); // eslint-disable-line new-cap
  8486. constructorName = newConstructorName || constructorName;
  8487. }
  8488. }
  8489. return constructorName;
  8490. }
  8491. /**
  8492. * ### .getMessage(errorLike)
  8493. *
  8494. * Gets the error message from an error.
  8495. * If `err` is a String itself, we return it.
  8496. * If the error has no message, we return an empty string.
  8497. *
  8498. * @name getMessage
  8499. * @param {Error|String} errorLike
  8500. * @namespace Utils
  8501. * @api public
  8502. */
  8503. function getMessage(errorLike) {
  8504. var msg = '';
  8505. if (errorLike && errorLike.message) {
  8506. msg = errorLike.message;
  8507. } else if (typeof errorLike === 'string') {
  8508. msg = errorLike;
  8509. }
  8510. return msg;
  8511. }
  8512. module.exports = {
  8513. compatibleInstance: compatibleInstance,
  8514. compatibleConstructor: compatibleConstructor,
  8515. compatibleMessage: compatibleMessage,
  8516. getMessage: getMessage,
  8517. getConstructorName: getConstructorName,
  8518. };
  8519. },{"get-func-name":36}],35:[function(require,module,exports){
  8520. 'use strict';
  8521. /* globals Symbol: false, Uint8Array: false, WeakMap: false */
  8522. /*!
  8523. * deep-eql
  8524. * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
  8525. * MIT Licensed
  8526. */
  8527. var type = require('type-detect');
  8528. function FakeMap() {
  8529. this._key = 'chai/deep-eql__' + Math.random() + Date.now();
  8530. }
  8531. FakeMap.prototype = {
  8532. get: function get(key) {
  8533. return key[this._key];
  8534. },
  8535. set: function set(key, value) {
  8536. if (Object.isExtensible(key)) {
  8537. Object.defineProperty(key, this._key, {
  8538. value: value,
  8539. configurable: true,
  8540. });
  8541. }
  8542. },
  8543. };
  8544. var MemoizeMap = typeof WeakMap === 'function' ? WeakMap : FakeMap;
  8545. /*!
  8546. * Check to see if the MemoizeMap has recorded a result of the two operands
  8547. *
  8548. * @param {Mixed} leftHandOperand
  8549. * @param {Mixed} rightHandOperand
  8550. * @param {MemoizeMap} memoizeMap
  8551. * @returns {Boolean|null} result
  8552. */
  8553. function memoizeCompare(leftHandOperand, rightHandOperand, memoizeMap) {
  8554. // Technically, WeakMap keys can *only* be objects, not primitives.
  8555. if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  8556. return null;
  8557. }
  8558. var leftHandMap = memoizeMap.get(leftHandOperand);
  8559. if (leftHandMap) {
  8560. var result = leftHandMap.get(rightHandOperand);
  8561. if (typeof result === 'boolean') {
  8562. return result;
  8563. }
  8564. }
  8565. return null;
  8566. }
  8567. /*!
  8568. * Set the result of the equality into the MemoizeMap
  8569. *
  8570. * @param {Mixed} leftHandOperand
  8571. * @param {Mixed} rightHandOperand
  8572. * @param {MemoizeMap} memoizeMap
  8573. * @param {Boolean} result
  8574. */
  8575. function memoizeSet(leftHandOperand, rightHandOperand, memoizeMap, result) {
  8576. // Technically, WeakMap keys can *only* be objects, not primitives.
  8577. if (!memoizeMap || isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  8578. return;
  8579. }
  8580. var leftHandMap = memoizeMap.get(leftHandOperand);
  8581. if (leftHandMap) {
  8582. leftHandMap.set(rightHandOperand, result);
  8583. } else {
  8584. leftHandMap = new MemoizeMap();
  8585. leftHandMap.set(rightHandOperand, result);
  8586. memoizeMap.set(leftHandOperand, leftHandMap);
  8587. }
  8588. }
  8589. /*!
  8590. * Primary Export
  8591. */
  8592. module.exports = deepEqual;
  8593. module.exports.MemoizeMap = MemoizeMap;
  8594. /**
  8595. * Assert deeply nested sameValue equality between two objects of any type.
  8596. *
  8597. * @param {Mixed} leftHandOperand
  8598. * @param {Mixed} rightHandOperand
  8599. * @param {Object} [options] (optional) Additional options
  8600. * @param {Array} [options.comparator] (optional) Override default algorithm, determining custom equality.
  8601. * @param {Array} [options.memoize] (optional) Provide a custom memoization object which will cache the results of
  8602. complex objects for a speed boost. By passing `false` you can disable memoization, but this will cause circular
  8603. references to blow the stack.
  8604. * @return {Boolean} equal match
  8605. */
  8606. function deepEqual(leftHandOperand, rightHandOperand, options) {
  8607. // If we have a comparator, we can't assume anything; so bail to its check first.
  8608. if (options && options.comparator) {
  8609. return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
  8610. }
  8611. var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
  8612. if (simpleResult !== null) {
  8613. return simpleResult;
  8614. }
  8615. // Deeper comparisons are pushed through to a larger function
  8616. return extensiveDeepEqual(leftHandOperand, rightHandOperand, options);
  8617. }
  8618. /**
  8619. * Many comparisons can be canceled out early via simple equality or primitive checks.
  8620. * @param {Mixed} leftHandOperand
  8621. * @param {Mixed} rightHandOperand
  8622. * @return {Boolean|null} equal match
  8623. */
  8624. function simpleEqual(leftHandOperand, rightHandOperand) {
  8625. // Equal references (except for Numbers) can be returned early
  8626. if (leftHandOperand === rightHandOperand) {
  8627. // Handle +-0 cases
  8628. return leftHandOperand !== 0 || 1 / leftHandOperand === 1 / rightHandOperand;
  8629. }
  8630. // handle NaN cases
  8631. if (
  8632. leftHandOperand !== leftHandOperand && // eslint-disable-line no-self-compare
  8633. rightHandOperand !== rightHandOperand // eslint-disable-line no-self-compare
  8634. ) {
  8635. return true;
  8636. }
  8637. // Anything that is not an 'object', i.e. symbols, functions, booleans, numbers,
  8638. // strings, and undefined, can be compared by reference.
  8639. if (isPrimitive(leftHandOperand) || isPrimitive(rightHandOperand)) {
  8640. // Easy out b/c it would have passed the first equality check
  8641. return false;
  8642. }
  8643. return null;
  8644. }
  8645. /*!
  8646. * The main logic of the `deepEqual` function.
  8647. *
  8648. * @param {Mixed} leftHandOperand
  8649. * @param {Mixed} rightHandOperand
  8650. * @param {Object} [options] (optional) Additional options
  8651. * @param {Array} [options.comparator] (optional) Override default algorithm, determining custom equality.
  8652. * @param {Array} [options.memoize] (optional) Provide a custom memoization object which will cache the results of
  8653. complex objects for a speed boost. By passing `false` you can disable memoization, but this will cause circular
  8654. references to blow the stack.
  8655. * @return {Boolean} equal match
  8656. */
  8657. function extensiveDeepEqual(leftHandOperand, rightHandOperand, options) {
  8658. options = options || {};
  8659. options.memoize = options.memoize === false ? false : options.memoize || new MemoizeMap();
  8660. var comparator = options && options.comparator;
  8661. // Check if a memoized result exists.
  8662. var memoizeResultLeft = memoizeCompare(leftHandOperand, rightHandOperand, options.memoize);
  8663. if (memoizeResultLeft !== null) {
  8664. return memoizeResultLeft;
  8665. }
  8666. var memoizeResultRight = memoizeCompare(rightHandOperand, leftHandOperand, options.memoize);
  8667. if (memoizeResultRight !== null) {
  8668. return memoizeResultRight;
  8669. }
  8670. // If a comparator is present, use it.
  8671. if (comparator) {
  8672. var comparatorResult = comparator(leftHandOperand, rightHandOperand);
  8673. // Comparators may return null, in which case we want to go back to default behavior.
  8674. if (comparatorResult === false || comparatorResult === true) {
  8675. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, comparatorResult);
  8676. return comparatorResult;
  8677. }
  8678. // To allow comparators to override *any* behavior, we ran them first. Since it didn't decide
  8679. // what to do, we need to make sure to return the basic tests first before we move on.
  8680. var simpleResult = simpleEqual(leftHandOperand, rightHandOperand);
  8681. if (simpleResult !== null) {
  8682. // Don't memoize this, it takes longer to set/retrieve than to just compare.
  8683. return simpleResult;
  8684. }
  8685. }
  8686. var leftHandType = type(leftHandOperand);
  8687. if (leftHandType !== type(rightHandOperand)) {
  8688. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, false);
  8689. return false;
  8690. }
  8691. // Temporarily set the operands in the memoize object to prevent blowing the stack
  8692. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, true);
  8693. var result = extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options);
  8694. memoizeSet(leftHandOperand, rightHandOperand, options.memoize, result);
  8695. return result;
  8696. }
  8697. function extensiveDeepEqualByType(leftHandOperand, rightHandOperand, leftHandType, options) {
  8698. switch (leftHandType) {
  8699. case 'String':
  8700. case 'Number':
  8701. case 'Boolean':
  8702. case 'Date':
  8703. // If these types are their instance types (e.g. `new Number`) then re-deepEqual against their values
  8704. return deepEqual(leftHandOperand.valueOf(), rightHandOperand.valueOf());
  8705. case 'Promise':
  8706. case 'Symbol':
  8707. case 'function':
  8708. case 'WeakMap':
  8709. case 'WeakSet':
  8710. return leftHandOperand === rightHandOperand;
  8711. case 'Error':
  8712. return keysEqual(leftHandOperand, rightHandOperand, [ 'name', 'message', 'code' ], options);
  8713. case 'Arguments':
  8714. case 'Int8Array':
  8715. case 'Uint8Array':
  8716. case 'Uint8ClampedArray':
  8717. case 'Int16Array':
  8718. case 'Uint16Array':
  8719. case 'Int32Array':
  8720. case 'Uint32Array':
  8721. case 'Float32Array':
  8722. case 'Float64Array':
  8723. case 'Array':
  8724. return iterableEqual(leftHandOperand, rightHandOperand, options);
  8725. case 'RegExp':
  8726. return regexpEqual(leftHandOperand, rightHandOperand);
  8727. case 'Generator':
  8728. return generatorEqual(leftHandOperand, rightHandOperand, options);
  8729. case 'DataView':
  8730. return iterableEqual(new Uint8Array(leftHandOperand.buffer), new Uint8Array(rightHandOperand.buffer), options);
  8731. case 'ArrayBuffer':
  8732. return iterableEqual(new Uint8Array(leftHandOperand), new Uint8Array(rightHandOperand), options);
  8733. case 'Set':
  8734. return entriesEqual(leftHandOperand, rightHandOperand, options);
  8735. case 'Map':
  8736. return entriesEqual(leftHandOperand, rightHandOperand, options);
  8737. case 'Temporal.PlainDate':
  8738. case 'Temporal.PlainTime':
  8739. case 'Temporal.PlainDateTime':
  8740. case 'Temporal.Instant':
  8741. case 'Temporal.ZonedDateTime':
  8742. case 'Temporal.PlainYearMonth':
  8743. case 'Temporal.PlainMonthDay':
  8744. return leftHandOperand.equals(rightHandOperand);
  8745. case 'Temporal.Duration':
  8746. return leftHandOperand.total('nanoseconds') === rightHandOperand.total('nanoseconds');
  8747. case 'Temporal.TimeZone':
  8748. case 'Temporal.Calendar':
  8749. return leftHandOperand.toString() === rightHandOperand.toString();
  8750. default:
  8751. return objectEqual(leftHandOperand, rightHandOperand, options);
  8752. }
  8753. }
  8754. /*!
  8755. * Compare two Regular Expressions for equality.
  8756. *
  8757. * @param {RegExp} leftHandOperand
  8758. * @param {RegExp} rightHandOperand
  8759. * @return {Boolean} result
  8760. */
  8761. function regexpEqual(leftHandOperand, rightHandOperand) {
  8762. return leftHandOperand.toString() === rightHandOperand.toString();
  8763. }
  8764. /*!
  8765. * Compare two Sets/Maps for equality. Faster than other equality functions.
  8766. *
  8767. * @param {Set} leftHandOperand
  8768. * @param {Set} rightHandOperand
  8769. * @param {Object} [options] (Optional)
  8770. * @return {Boolean} result
  8771. */
  8772. function entriesEqual(leftHandOperand, rightHandOperand, options) {
  8773. // IE11 doesn't support Set#entries or Set#@@iterator, so we need manually populate using Set#forEach
  8774. if (leftHandOperand.size !== rightHandOperand.size) {
  8775. return false;
  8776. }
  8777. if (leftHandOperand.size === 0) {
  8778. return true;
  8779. }
  8780. var leftHandItems = [];
  8781. var rightHandItems = [];
  8782. leftHandOperand.forEach(function gatherEntries(key, value) {
  8783. leftHandItems.push([ key, value ]);
  8784. });
  8785. rightHandOperand.forEach(function gatherEntries(key, value) {
  8786. rightHandItems.push([ key, value ]);
  8787. });
  8788. return iterableEqual(leftHandItems.sort(), rightHandItems.sort(), options);
  8789. }
  8790. /*!
  8791. * Simple equality for flat iterable objects such as Arrays, TypedArrays or Node.js buffers.
  8792. *
  8793. * @param {Iterable} leftHandOperand
  8794. * @param {Iterable} rightHandOperand
  8795. * @param {Object} [options] (Optional)
  8796. * @return {Boolean} result
  8797. */
  8798. function iterableEqual(leftHandOperand, rightHandOperand, options) {
  8799. var length = leftHandOperand.length;
  8800. if (length !== rightHandOperand.length) {
  8801. return false;
  8802. }
  8803. if (length === 0) {
  8804. return true;
  8805. }
  8806. var index = -1;
  8807. while (++index < length) {
  8808. if (deepEqual(leftHandOperand[index], rightHandOperand[index], options) === false) {
  8809. return false;
  8810. }
  8811. }
  8812. return true;
  8813. }
  8814. /*!
  8815. * Simple equality for generator objects such as those returned by generator functions.
  8816. *
  8817. * @param {Iterable} leftHandOperand
  8818. * @param {Iterable} rightHandOperand
  8819. * @param {Object} [options] (Optional)
  8820. * @return {Boolean} result
  8821. */
  8822. function generatorEqual(leftHandOperand, rightHandOperand, options) {
  8823. return iterableEqual(getGeneratorEntries(leftHandOperand), getGeneratorEntries(rightHandOperand), options);
  8824. }
  8825. /*!
  8826. * Determine if the given object has an @@iterator function.
  8827. *
  8828. * @param {Object} target
  8829. * @return {Boolean} `true` if the object has an @@iterator function.
  8830. */
  8831. function hasIteratorFunction(target) {
  8832. return typeof Symbol !== 'undefined' &&
  8833. typeof target === 'object' &&
  8834. typeof Symbol.iterator !== 'undefined' &&
  8835. typeof target[Symbol.iterator] === 'function';
  8836. }
  8837. /*!
  8838. * Gets all iterator entries from the given Object. If the Object has no @@iterator function, returns an empty array.
  8839. * This will consume the iterator - which could have side effects depending on the @@iterator implementation.
  8840. *
  8841. * @param {Object} target
  8842. * @returns {Array} an array of entries from the @@iterator function
  8843. */
  8844. function getIteratorEntries(target) {
  8845. if (hasIteratorFunction(target)) {
  8846. try {
  8847. return getGeneratorEntries(target[Symbol.iterator]());
  8848. } catch (iteratorError) {
  8849. return [];
  8850. }
  8851. }
  8852. return [];
  8853. }
  8854. /*!
  8855. * Gets all entries from a Generator. This will consume the generator - which could have side effects.
  8856. *
  8857. * @param {Generator} target
  8858. * @returns {Array} an array of entries from the Generator.
  8859. */
  8860. function getGeneratorEntries(generator) {
  8861. var generatorResult = generator.next();
  8862. var accumulator = [ generatorResult.value ];
  8863. while (generatorResult.done === false) {
  8864. generatorResult = generator.next();
  8865. accumulator.push(generatorResult.value);
  8866. }
  8867. return accumulator;
  8868. }
  8869. /*!
  8870. * Gets all own and inherited enumerable keys from a target.
  8871. *
  8872. * @param {Object} target
  8873. * @returns {Array} an array of own and inherited enumerable keys from the target.
  8874. */
  8875. function getEnumerableKeys(target) {
  8876. var keys = [];
  8877. for (var key in target) {
  8878. keys.push(key);
  8879. }
  8880. return keys;
  8881. }
  8882. function getEnumerableSymbols(target) {
  8883. var keys = [];
  8884. var allKeys = Object.getOwnPropertySymbols(target);
  8885. for (var i = 0; i < allKeys.length; i += 1) {
  8886. var key = allKeys[i];
  8887. if (Object.getOwnPropertyDescriptor(target, key).enumerable) {
  8888. keys.push(key);
  8889. }
  8890. }
  8891. return keys;
  8892. }
  8893. /*!
  8894. * Determines if two objects have matching values, given a set of keys. Defers to deepEqual for the equality check of
  8895. * each key. If any value of the given key is not equal, the function will return false (early).
  8896. *
  8897. * @param {Mixed} leftHandOperand
  8898. * @param {Mixed} rightHandOperand
  8899. * @param {Array} keys An array of keys to compare the values of leftHandOperand and rightHandOperand against
  8900. * @param {Object} [options] (Optional)
  8901. * @return {Boolean} result
  8902. */
  8903. function keysEqual(leftHandOperand, rightHandOperand, keys, options) {
  8904. var length = keys.length;
  8905. if (length === 0) {
  8906. return true;
  8907. }
  8908. for (var i = 0; i < length; i += 1) {
  8909. if (deepEqual(leftHandOperand[keys[i]], rightHandOperand[keys[i]], options) === false) {
  8910. return false;
  8911. }
  8912. }
  8913. return true;
  8914. }
  8915. /*!
  8916. * Recursively check the equality of two Objects. Once basic sameness has been established it will defer to `deepEqual`
  8917. * for each enumerable key in the object.
  8918. *
  8919. * @param {Mixed} leftHandOperand
  8920. * @param {Mixed} rightHandOperand
  8921. * @param {Object} [options] (Optional)
  8922. * @return {Boolean} result
  8923. */
  8924. function objectEqual(leftHandOperand, rightHandOperand, options) {
  8925. var leftHandKeys = getEnumerableKeys(leftHandOperand);
  8926. var rightHandKeys = getEnumerableKeys(rightHandOperand);
  8927. var leftHandSymbols = getEnumerableSymbols(leftHandOperand);
  8928. var rightHandSymbols = getEnumerableSymbols(rightHandOperand);
  8929. leftHandKeys = leftHandKeys.concat(leftHandSymbols);
  8930. rightHandKeys = rightHandKeys.concat(rightHandSymbols);
  8931. if (leftHandKeys.length && leftHandKeys.length === rightHandKeys.length) {
  8932. if (iterableEqual(mapSymbols(leftHandKeys).sort(), mapSymbols(rightHandKeys).sort()) === false) {
  8933. return false;
  8934. }
  8935. return keysEqual(leftHandOperand, rightHandOperand, leftHandKeys, options);
  8936. }
  8937. var leftHandEntries = getIteratorEntries(leftHandOperand);
  8938. var rightHandEntries = getIteratorEntries(rightHandOperand);
  8939. if (leftHandEntries.length && leftHandEntries.length === rightHandEntries.length) {
  8940. leftHandEntries.sort();
  8941. rightHandEntries.sort();
  8942. return iterableEqual(leftHandEntries, rightHandEntries, options);
  8943. }
  8944. if (leftHandKeys.length === 0 &&
  8945. leftHandEntries.length === 0 &&
  8946. rightHandKeys.length === 0 &&
  8947. rightHandEntries.length === 0) {
  8948. return true;
  8949. }
  8950. return false;
  8951. }
  8952. /*!
  8953. * Returns true if the argument is a primitive.
  8954. *
  8955. * This intentionally returns true for all objects that can be compared by reference,
  8956. * including functions and symbols.
  8957. *
  8958. * @param {Mixed} value
  8959. * @return {Boolean} result
  8960. */
  8961. function isPrimitive(value) {
  8962. return value === null || typeof value !== 'object';
  8963. }
  8964. function mapSymbols(arr) {
  8965. return arr.map(function mapSymbol(entry) {
  8966. if (typeof entry === 'symbol') {
  8967. return entry.toString();
  8968. }
  8969. return entry;
  8970. });
  8971. }
  8972. },{"type-detect":39}],36:[function(require,module,exports){
  8973. 'use strict';
  8974. /* !
  8975. * Chai - getFuncName utility
  8976. * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
  8977. * MIT Licensed
  8978. */
  8979. /**
  8980. * ### .getFuncName(constructorFn)
  8981. *
  8982. * Returns the name of a function.
  8983. * When a non-function instance is passed, returns `null`.
  8984. * This also includes a polyfill function if `aFunc.name` is not defined.
  8985. *
  8986. * @name getFuncName
  8987. * @param {Function} funct
  8988. * @namespace Utils
  8989. * @api public
  8990. */
  8991. var toString = Function.prototype.toString;
  8992. var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
  8993. var maxFunctionSourceLength = 512;
  8994. function getFuncName(aFunc) {
  8995. if (typeof aFunc !== 'function') {
  8996. return null;
  8997. }
  8998. var name = '';
  8999. if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
  9000. // eslint-disable-next-line prefer-reflect
  9001. var functionSource = toString.call(aFunc);
  9002. // To avoid unconstrained resource consumption due to pathalogically large function names,
  9003. // we limit the available return value to be less than 512 characters.
  9004. if (functionSource.indexOf('(') > maxFunctionSourceLength) {
  9005. return name;
  9006. }
  9007. // Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
  9008. var match = functionSource.match(functionNameMatch);
  9009. if (match) {
  9010. name = match[1];
  9011. }
  9012. } else {
  9013. // If we've got a `name` property we just use it
  9014. name = aFunc.name;
  9015. }
  9016. return name;
  9017. }
  9018. module.exports = getFuncName;
  9019. },{}],37:[function(require,module,exports){
  9020. (function (global, factory) {
  9021. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  9022. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  9023. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.loupe = {}));
  9024. }(this, (function (exports) { 'use strict';
  9025. function _typeof(obj) {
  9026. "@babel/helpers - typeof";
  9027. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  9028. _typeof = function (obj) {
  9029. return typeof obj;
  9030. };
  9031. } else {
  9032. _typeof = function (obj) {
  9033. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  9034. };
  9035. }
  9036. return _typeof(obj);
  9037. }
  9038. function _slicedToArray(arr, i) {
  9039. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
  9040. }
  9041. function _arrayWithHoles(arr) {
  9042. if (Array.isArray(arr)) return arr;
  9043. }
  9044. function _iterableToArrayLimit(arr, i) {
  9045. if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  9046. var _arr = [];
  9047. var _n = true;
  9048. var _d = false;
  9049. var _e = undefined;
  9050. try {
  9051. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  9052. _arr.push(_s.value);
  9053. if (i && _arr.length === i) break;
  9054. }
  9055. } catch (err) {
  9056. _d = true;
  9057. _e = err;
  9058. } finally {
  9059. try {
  9060. if (!_n && _i["return"] != null) _i["return"]();
  9061. } finally {
  9062. if (_d) throw _e;
  9063. }
  9064. }
  9065. return _arr;
  9066. }
  9067. function _unsupportedIterableToArray(o, minLen) {
  9068. if (!o) return;
  9069. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  9070. var n = Object.prototype.toString.call(o).slice(8, -1);
  9071. if (n === "Object" && o.constructor) n = o.constructor.name;
  9072. if (n === "Map" || n === "Set") return Array.from(o);
  9073. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  9074. }
  9075. function _arrayLikeToArray(arr, len) {
  9076. if (len == null || len > arr.length) len = arr.length;
  9077. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  9078. return arr2;
  9079. }
  9080. function _nonIterableRest() {
  9081. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  9082. }
  9083. var ansiColors = {
  9084. bold: ['1', '22'],
  9085. dim: ['2', '22'],
  9086. italic: ['3', '23'],
  9087. underline: ['4', '24'],
  9088. // 5 & 6 are blinking
  9089. inverse: ['7', '27'],
  9090. hidden: ['8', '28'],
  9091. strike: ['9', '29'],
  9092. // 10-20 are fonts
  9093. // 21-29 are resets for 1-9
  9094. black: ['30', '39'],
  9095. red: ['31', '39'],
  9096. green: ['32', '39'],
  9097. yellow: ['33', '39'],
  9098. blue: ['34', '39'],
  9099. magenta: ['35', '39'],
  9100. cyan: ['36', '39'],
  9101. white: ['37', '39'],
  9102. brightblack: ['30;1', '39'],
  9103. brightred: ['31;1', '39'],
  9104. brightgreen: ['32;1', '39'],
  9105. brightyellow: ['33;1', '39'],
  9106. brightblue: ['34;1', '39'],
  9107. brightmagenta: ['35;1', '39'],
  9108. brightcyan: ['36;1', '39'],
  9109. brightwhite: ['37;1', '39'],
  9110. grey: ['90', '39']
  9111. };
  9112. var styles = {
  9113. special: 'cyan',
  9114. number: 'yellow',
  9115. bigint: 'yellow',
  9116. boolean: 'yellow',
  9117. undefined: 'grey',
  9118. null: 'bold',
  9119. string: 'green',
  9120. symbol: 'green',
  9121. date: 'magenta',
  9122. regexp: 'red'
  9123. };
  9124. var truncator = '…';
  9125. function colorise(value, styleType) {
  9126. var color = ansiColors[styles[styleType]] || ansiColors[styleType];
  9127. if (!color) {
  9128. return String(value);
  9129. }
  9130. return "\x1B[".concat(color[0], "m").concat(String(value), "\x1B[").concat(color[1], "m");
  9131. }
  9132. function normaliseOptions() {
  9133. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  9134. _ref$showHidden = _ref.showHidden,
  9135. showHidden = _ref$showHidden === void 0 ? false : _ref$showHidden,
  9136. _ref$depth = _ref.depth,
  9137. depth = _ref$depth === void 0 ? 2 : _ref$depth,
  9138. _ref$colors = _ref.colors,
  9139. colors = _ref$colors === void 0 ? false : _ref$colors,
  9140. _ref$customInspect = _ref.customInspect,
  9141. customInspect = _ref$customInspect === void 0 ? true : _ref$customInspect,
  9142. _ref$showProxy = _ref.showProxy,
  9143. showProxy = _ref$showProxy === void 0 ? false : _ref$showProxy,
  9144. _ref$maxArrayLength = _ref.maxArrayLength,
  9145. maxArrayLength = _ref$maxArrayLength === void 0 ? Infinity : _ref$maxArrayLength,
  9146. _ref$breakLength = _ref.breakLength,
  9147. breakLength = _ref$breakLength === void 0 ? Infinity : _ref$breakLength,
  9148. _ref$seen = _ref.seen,
  9149. seen = _ref$seen === void 0 ? [] : _ref$seen,
  9150. _ref$truncate = _ref.truncate,
  9151. truncate = _ref$truncate === void 0 ? Infinity : _ref$truncate,
  9152. _ref$stylize = _ref.stylize,
  9153. stylize = _ref$stylize === void 0 ? String : _ref$stylize;
  9154. var options = {
  9155. showHidden: Boolean(showHidden),
  9156. depth: Number(depth),
  9157. colors: Boolean(colors),
  9158. customInspect: Boolean(customInspect),
  9159. showProxy: Boolean(showProxy),
  9160. maxArrayLength: Number(maxArrayLength),
  9161. breakLength: Number(breakLength),
  9162. truncate: Number(truncate),
  9163. seen: seen,
  9164. stylize: stylize
  9165. };
  9166. if (options.colors) {
  9167. options.stylize = colorise;
  9168. }
  9169. return options;
  9170. }
  9171. function truncate(string, length) {
  9172. var tail = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : truncator;
  9173. string = String(string);
  9174. var tailLength = tail.length;
  9175. var stringLength = string.length;
  9176. if (tailLength > length && stringLength > tailLength) {
  9177. return tail;
  9178. }
  9179. if (stringLength > length && stringLength > tailLength) {
  9180. return "".concat(string.slice(0, length - tailLength)).concat(tail);
  9181. }
  9182. return string;
  9183. } // eslint-disable-next-line complexity
  9184. function inspectList(list, options, inspectItem) {
  9185. var separator = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ', ';
  9186. inspectItem = inspectItem || options.inspect;
  9187. var size = list.length;
  9188. if (size === 0) return '';
  9189. var originalLength = options.truncate;
  9190. var output = '';
  9191. var peek = '';
  9192. var truncated = '';
  9193. for (var i = 0; i < size; i += 1) {
  9194. var last = i + 1 === list.length;
  9195. var secondToLast = i + 2 === list.length;
  9196. truncated = "".concat(truncator, "(").concat(list.length - i, ")");
  9197. var value = list[i]; // If there is more than one remaining we need to account for a separator of `, `
  9198. options.truncate = originalLength - output.length - (last ? 0 : separator.length);
  9199. var string = peek || inspectItem(value, options) + (last ? '' : separator);
  9200. var nextLength = output.length + string.length;
  9201. var truncatedLength = nextLength + truncated.length; // If this is the last element, and adding it would
  9202. // take us over length, but adding the truncator wouldn't - then break now
  9203. if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) {
  9204. break;
  9205. } // If this isn't the last or second to last element to scan,
  9206. // but the string is already over length then break here
  9207. if (!last && !secondToLast && truncatedLength > originalLength) {
  9208. break;
  9209. } // Peek at the next string to determine if we should
  9210. // break early before adding this item to the output
  9211. peek = last ? '' : inspectItem(list[i + 1], options) + (secondToLast ? '' : separator); // If we have one element left, but this element and
  9212. // the next takes over length, the break early
  9213. if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) {
  9214. break;
  9215. }
  9216. output += string; // If the next element takes us to length -
  9217. // but there are more after that, then we should truncate now
  9218. if (!last && !secondToLast && nextLength + peek.length >= originalLength) {
  9219. truncated = "".concat(truncator, "(").concat(list.length - i - 1, ")");
  9220. break;
  9221. }
  9222. truncated = '';
  9223. }
  9224. return "".concat(output).concat(truncated);
  9225. }
  9226. function quoteComplexKey(key) {
  9227. if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) {
  9228. return key;
  9229. }
  9230. return JSON.stringify(key).replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
  9231. }
  9232. function inspectProperty(_ref2, options) {
  9233. var _ref3 = _slicedToArray(_ref2, 2),
  9234. key = _ref3[0],
  9235. value = _ref3[1];
  9236. options.truncate -= 2;
  9237. if (typeof key === 'string') {
  9238. key = quoteComplexKey(key);
  9239. } else if (typeof key !== 'number') {
  9240. key = "[".concat(options.inspect(key, options), "]");
  9241. }
  9242. options.truncate -= key.length;
  9243. value = options.inspect(value, options);
  9244. return "".concat(key, ": ").concat(value);
  9245. }
  9246. function inspectArray(array, options) {
  9247. // Object.keys will always output the Array indices first, so we can slice by
  9248. // `array.length` to get non-index properties
  9249. var nonIndexProperties = Object.keys(array).slice(array.length);
  9250. if (!array.length && !nonIndexProperties.length) return '[]';
  9251. options.truncate -= 4;
  9252. var listContents = inspectList(array, options);
  9253. options.truncate -= listContents.length;
  9254. var propertyContents = '';
  9255. if (nonIndexProperties.length) {
  9256. propertyContents = inspectList(nonIndexProperties.map(function (key) {
  9257. return [key, array[key]];
  9258. }), options, inspectProperty);
  9259. }
  9260. return "[ ".concat(listContents).concat(propertyContents ? ", ".concat(propertyContents) : '', " ]");
  9261. }
  9262. /* !
  9263. * Chai - getFuncName utility
  9264. * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
  9265. * MIT Licensed
  9266. */
  9267. /**
  9268. * ### .getFuncName(constructorFn)
  9269. *
  9270. * Returns the name of a function.
  9271. * When a non-function instance is passed, returns `null`.
  9272. * This also includes a polyfill function if `aFunc.name` is not defined.
  9273. *
  9274. * @name getFuncName
  9275. * @param {Function} funct
  9276. * @namespace Utils
  9277. * @api public
  9278. */
  9279. var toString = Function.prototype.toString;
  9280. var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
  9281. function getFuncName(aFunc) {
  9282. if (typeof aFunc !== 'function') {
  9283. return null;
  9284. }
  9285. var name = '';
  9286. if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
  9287. // Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
  9288. var match = toString.call(aFunc).match(functionNameMatch);
  9289. if (match) {
  9290. name = match[1];
  9291. }
  9292. } else {
  9293. // If we've got a `name` property we just use it
  9294. name = aFunc.name;
  9295. }
  9296. return name;
  9297. }
  9298. var getFuncName_1 = getFuncName;
  9299. var getArrayName = function getArrayName(array) {
  9300. // We need to special case Node.js' Buffers, which report to be Uint8Array
  9301. if (typeof Buffer === 'function' && array instanceof Buffer) {
  9302. return 'Buffer';
  9303. }
  9304. if (array[Symbol.toStringTag]) {
  9305. return array[Symbol.toStringTag];
  9306. }
  9307. return getFuncName_1(array.constructor);
  9308. };
  9309. function inspectTypedArray(array, options) {
  9310. var name = getArrayName(array);
  9311. options.truncate -= name.length + 4; // Object.keys will always output the Array indices first, so we can slice by
  9312. // `array.length` to get non-index properties
  9313. var nonIndexProperties = Object.keys(array).slice(array.length);
  9314. if (!array.length && !nonIndexProperties.length) return "".concat(name, "[]"); // As we know TypedArrays only contain Unsigned Integers, we can skip inspecting each one and simply
  9315. // stylise the toString() value of them
  9316. var output = '';
  9317. for (var i = 0; i < array.length; i++) {
  9318. var string = "".concat(options.stylize(truncate(array[i], options.truncate), 'number')).concat(i === array.length - 1 ? '' : ', ');
  9319. options.truncate -= string.length;
  9320. if (array[i] !== array.length && options.truncate <= 3) {
  9321. output += "".concat(truncator, "(").concat(array.length - array[i] + 1, ")");
  9322. break;
  9323. }
  9324. output += string;
  9325. }
  9326. var propertyContents = '';
  9327. if (nonIndexProperties.length) {
  9328. propertyContents = inspectList(nonIndexProperties.map(function (key) {
  9329. return [key, array[key]];
  9330. }), options, inspectProperty);
  9331. }
  9332. return "".concat(name, "[ ").concat(output).concat(propertyContents ? ", ".concat(propertyContents) : '', " ]");
  9333. }
  9334. function inspectDate(dateObject, options) {
  9335. var stringRepresentation = dateObject.toJSON();
  9336. if (stringRepresentation === null) {
  9337. return 'Invalid Date';
  9338. }
  9339. var split = stringRepresentation.split('T');
  9340. var date = split[0]; // If we need to - truncate the time portion, but never the date
  9341. return options.stylize("".concat(date, "T").concat(truncate(split[1], options.truncate - date.length - 1)), 'date');
  9342. }
  9343. function inspectFunction(func, options) {
  9344. var name = getFuncName_1(func);
  9345. if (!name) {
  9346. return options.stylize('[Function]', 'special');
  9347. }
  9348. return options.stylize("[Function ".concat(truncate(name, options.truncate - 11), "]"), 'special');
  9349. }
  9350. function inspectMapEntry(_ref, options) {
  9351. var _ref2 = _slicedToArray(_ref, 2),
  9352. key = _ref2[0],
  9353. value = _ref2[1];
  9354. options.truncate -= 4;
  9355. key = options.inspect(key, options);
  9356. options.truncate -= key.length;
  9357. value = options.inspect(value, options);
  9358. return "".concat(key, " => ").concat(value);
  9359. } // IE11 doesn't support `map.entries()`
  9360. function mapToEntries(map) {
  9361. var entries = [];
  9362. map.forEach(function (value, key) {
  9363. entries.push([key, value]);
  9364. });
  9365. return entries;
  9366. }
  9367. function inspectMap(map, options) {
  9368. var size = map.size - 1;
  9369. if (size <= 0) {
  9370. return 'Map{}';
  9371. }
  9372. options.truncate -= 7;
  9373. return "Map{ ".concat(inspectList(mapToEntries(map), options, inspectMapEntry), " }");
  9374. }
  9375. var isNaN = Number.isNaN || function (i) {
  9376. return i !== i;
  9377. }; // eslint-disable-line no-self-compare
  9378. function inspectNumber(number, options) {
  9379. if (isNaN(number)) {
  9380. return options.stylize('NaN', 'number');
  9381. }
  9382. if (number === Infinity) {
  9383. return options.stylize('Infinity', 'number');
  9384. }
  9385. if (number === -Infinity) {
  9386. return options.stylize('-Infinity', 'number');
  9387. }
  9388. if (number === 0) {
  9389. return options.stylize(1 / number === Infinity ? '+0' : '-0', 'number');
  9390. }
  9391. return options.stylize(truncate(number, options.truncate), 'number');
  9392. }
  9393. function inspectBigInt(number, options) {
  9394. var nums = truncate(number.toString(), options.truncate - 1);
  9395. if (nums !== truncator) nums += 'n';
  9396. return options.stylize(nums, 'bigint');
  9397. }
  9398. function inspectRegExp(value, options) {
  9399. var flags = value.toString().split('/')[2];
  9400. var sourceLength = options.truncate - (2 + flags.length);
  9401. var source = value.source;
  9402. return options.stylize("/".concat(truncate(source, sourceLength), "/").concat(flags), 'regexp');
  9403. }
  9404. function arrayFromSet(set) {
  9405. var values = [];
  9406. set.forEach(function (value) {
  9407. values.push(value);
  9408. });
  9409. return values;
  9410. }
  9411. function inspectSet(set, options) {
  9412. if (set.size === 0) return 'Set{}';
  9413. options.truncate -= 7;
  9414. return "Set{ ".concat(inspectList(arrayFromSet(set), options), " }");
  9415. }
  9416. var stringEscapeChars = new RegExp("['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5" + "\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]", 'g');
  9417. var escapeCharacters = {
  9418. '\b': '\\b',
  9419. '\t': '\\t',
  9420. '\n': '\\n',
  9421. '\f': '\\f',
  9422. '\r': '\\r',
  9423. "'": "\\'",
  9424. '\\': '\\\\'
  9425. };
  9426. var hex = 16;
  9427. var unicodeLength = 4;
  9428. function escape(char) {
  9429. return escapeCharacters[char] || "\\u".concat("0000".concat(char.charCodeAt(0).toString(hex)).slice(-unicodeLength));
  9430. }
  9431. function inspectString(string, options) {
  9432. if (stringEscapeChars.test(string)) {
  9433. string = string.replace(stringEscapeChars, escape);
  9434. }
  9435. return options.stylize("'".concat(truncate(string, options.truncate - 2), "'"), 'string');
  9436. }
  9437. function inspectSymbol(value) {
  9438. if ('description' in Symbol.prototype) {
  9439. return value.description ? "Symbol(".concat(value.description, ")") : 'Symbol()';
  9440. }
  9441. return value.toString();
  9442. }
  9443. var getPromiseValue = function getPromiseValue() {
  9444. return 'Promise{…}';
  9445. };
  9446. try {
  9447. var _process$binding = process.binding('util'),
  9448. getPromiseDetails = _process$binding.getPromiseDetails,
  9449. kPending = _process$binding.kPending,
  9450. kRejected = _process$binding.kRejected;
  9451. if (Array.isArray(getPromiseDetails(Promise.resolve()))) {
  9452. getPromiseValue = function getPromiseValue(value, options) {
  9453. var _getPromiseDetails = getPromiseDetails(value),
  9454. _getPromiseDetails2 = _slicedToArray(_getPromiseDetails, 2),
  9455. state = _getPromiseDetails2[0],
  9456. innerValue = _getPromiseDetails2[1];
  9457. if (state === kPending) {
  9458. return 'Promise{<pending>}';
  9459. }
  9460. return "Promise".concat(state === kRejected ? '!' : '', "{").concat(options.inspect(innerValue, options), "}");
  9461. };
  9462. }
  9463. } catch (notNode) {
  9464. /* ignore */
  9465. }
  9466. var inspectPromise = getPromiseValue;
  9467. function inspectObject(object, options) {
  9468. var properties = Object.getOwnPropertyNames(object);
  9469. var symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : [];
  9470. if (properties.length === 0 && symbols.length === 0) {
  9471. return '{}';
  9472. }
  9473. options.truncate -= 4;
  9474. options.seen = options.seen || [];
  9475. if (options.seen.indexOf(object) >= 0) {
  9476. return '[Circular]';
  9477. }
  9478. options.seen.push(object);
  9479. var propertyContents = inspectList(properties.map(function (key) {
  9480. return [key, object[key]];
  9481. }), options, inspectProperty);
  9482. var symbolContents = inspectList(symbols.map(function (key) {
  9483. return [key, object[key]];
  9484. }), options, inspectProperty);
  9485. options.seen.pop();
  9486. var sep = '';
  9487. if (propertyContents && symbolContents) {
  9488. sep = ', ';
  9489. }
  9490. return "{ ".concat(propertyContents).concat(sep).concat(symbolContents, " }");
  9491. }
  9492. var toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag ? Symbol.toStringTag : false;
  9493. function inspectClass(value, options) {
  9494. var name = '';
  9495. if (toStringTag && toStringTag in value) {
  9496. name = value[toStringTag];
  9497. }
  9498. name = name || getFuncName_1(value.constructor); // Babel transforms anonymous classes to the name `_class`
  9499. if (!name || name === '_class') {
  9500. name = '<Anonymous Class>';
  9501. }
  9502. options.truncate -= name.length;
  9503. return "".concat(name).concat(inspectObject(value, options));
  9504. }
  9505. function inspectArguments(args, options) {
  9506. if (args.length === 0) return 'Arguments[]';
  9507. options.truncate -= 13;
  9508. return "Arguments[ ".concat(inspectList(args, options), " ]");
  9509. }
  9510. var errorKeys = ['stack', 'line', 'column', 'name', 'message', 'fileName', 'lineNumber', 'columnNumber', 'number', 'description'];
  9511. function inspectObject$1(error, options) {
  9512. var properties = Object.getOwnPropertyNames(error).filter(function (key) {
  9513. return errorKeys.indexOf(key) === -1;
  9514. });
  9515. var name = error.name;
  9516. options.truncate -= name.length;
  9517. var message = '';
  9518. if (typeof error.message === 'string') {
  9519. message = truncate(error.message, options.truncate);
  9520. } else {
  9521. properties.unshift('message');
  9522. }
  9523. message = message ? ": ".concat(message) : '';
  9524. options.truncate -= message.length + 5;
  9525. var propertyContents = inspectList(properties.map(function (key) {
  9526. return [key, error[key]];
  9527. }), options, inspectProperty);
  9528. return "".concat(name).concat(message).concat(propertyContents ? " { ".concat(propertyContents, " }") : '');
  9529. }
  9530. function inspectAttribute(_ref, options) {
  9531. var _ref2 = _slicedToArray(_ref, 2),
  9532. key = _ref2[0],
  9533. value = _ref2[1];
  9534. options.truncate -= 3;
  9535. if (!value) {
  9536. return "".concat(options.stylize(key, 'yellow'));
  9537. }
  9538. return "".concat(options.stylize(key, 'yellow'), "=").concat(options.stylize("\"".concat(value, "\""), 'string'));
  9539. }
  9540. function inspectHTMLCollection(collection, options) {
  9541. // eslint-disable-next-line no-use-before-define
  9542. return inspectList(collection, options, inspectHTML, '\n');
  9543. }
  9544. function inspectHTML(element, options) {
  9545. var properties = element.getAttributeNames();
  9546. var name = element.tagName.toLowerCase();
  9547. var head = options.stylize("<".concat(name), 'special');
  9548. var headClose = options.stylize(">", 'special');
  9549. var tail = options.stylize("</".concat(name, ">"), 'special');
  9550. options.truncate -= name.length * 2 + 5;
  9551. var propertyContents = '';
  9552. if (properties.length > 0) {
  9553. propertyContents += ' ';
  9554. propertyContents += inspectList(properties.map(function (key) {
  9555. return [key, element.getAttribute(key)];
  9556. }), options, inspectAttribute, ' ');
  9557. }
  9558. options.truncate -= propertyContents.length;
  9559. var truncate = options.truncate;
  9560. var children = inspectHTMLCollection(element.children, options);
  9561. if (children && children.length > truncate) {
  9562. children = "".concat(truncator, "(").concat(element.children.length, ")");
  9563. }
  9564. return "".concat(head).concat(propertyContents).concat(headClose).concat(children).concat(tail);
  9565. }
  9566. var symbolsSupported = typeof Symbol === 'function' && typeof Symbol.for === 'function';
  9567. var chaiInspect = symbolsSupported ? Symbol.for('chai/inspect') : '@@chai/inspect';
  9568. var nodeInspect = false;
  9569. try {
  9570. // eslint-disable-next-line global-require
  9571. var nodeUtil = require('util');
  9572. nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false;
  9573. } catch (noNodeInspect) {
  9574. nodeInspect = false;
  9575. }
  9576. function FakeMap() {
  9577. // eslint-disable-next-line prefer-template
  9578. this.key = 'chai/loupe__' + Math.random() + Date.now();
  9579. }
  9580. FakeMap.prototype = {
  9581. // eslint-disable-next-line object-shorthand
  9582. get: function get(key) {
  9583. return key[this.key];
  9584. },
  9585. // eslint-disable-next-line object-shorthand
  9586. has: function has(key) {
  9587. return this.key in key;
  9588. },
  9589. // eslint-disable-next-line object-shorthand
  9590. set: function set(key, value) {
  9591. if (Object.isExtensible(key)) {
  9592. Object.defineProperty(key, this.key, {
  9593. // eslint-disable-next-line object-shorthand
  9594. value: value,
  9595. configurable: true
  9596. });
  9597. }
  9598. }
  9599. };
  9600. var constructorMap = new (typeof WeakMap === 'function' ? WeakMap : FakeMap)();
  9601. var stringTagMap = {};
  9602. var baseTypesMap = {
  9603. undefined: function undefined$1(value, options) {
  9604. return options.stylize('undefined', 'undefined');
  9605. },
  9606. null: function _null(value, options) {
  9607. return options.stylize(null, 'null');
  9608. },
  9609. boolean: function boolean(value, options) {
  9610. return options.stylize(value, 'boolean');
  9611. },
  9612. Boolean: function Boolean(value, options) {
  9613. return options.stylize(value, 'boolean');
  9614. },
  9615. number: inspectNumber,
  9616. Number: inspectNumber,
  9617. bigint: inspectBigInt,
  9618. BigInt: inspectBigInt,
  9619. string: inspectString,
  9620. String: inspectString,
  9621. function: inspectFunction,
  9622. Function: inspectFunction,
  9623. symbol: inspectSymbol,
  9624. // A Symbol polyfill will return `Symbol` not `symbol` from typedetect
  9625. Symbol: inspectSymbol,
  9626. Array: inspectArray,
  9627. Date: inspectDate,
  9628. Map: inspectMap,
  9629. Set: inspectSet,
  9630. RegExp: inspectRegExp,
  9631. Promise: inspectPromise,
  9632. // WeakSet, WeakMap are totally opaque to us
  9633. WeakSet: function WeakSet(value, options) {
  9634. return options.stylize('WeakSet{…}', 'special');
  9635. },
  9636. WeakMap: function WeakMap(value, options) {
  9637. return options.stylize('WeakMap{…}', 'special');
  9638. },
  9639. Arguments: inspectArguments,
  9640. Int8Array: inspectTypedArray,
  9641. Uint8Array: inspectTypedArray,
  9642. Uint8ClampedArray: inspectTypedArray,
  9643. Int16Array: inspectTypedArray,
  9644. Uint16Array: inspectTypedArray,
  9645. Int32Array: inspectTypedArray,
  9646. Uint32Array: inspectTypedArray,
  9647. Float32Array: inspectTypedArray,
  9648. Float64Array: inspectTypedArray,
  9649. Generator: function Generator() {
  9650. return '';
  9651. },
  9652. DataView: function DataView() {
  9653. return '';
  9654. },
  9655. ArrayBuffer: function ArrayBuffer() {
  9656. return '';
  9657. },
  9658. Error: inspectObject$1,
  9659. HTMLCollection: inspectHTMLCollection,
  9660. NodeList: inspectHTMLCollection
  9661. }; // eslint-disable-next-line complexity
  9662. var inspectCustom = function inspectCustom(value, options, type) {
  9663. if (chaiInspect in value && typeof value[chaiInspect] === 'function') {
  9664. return value[chaiInspect](options);
  9665. }
  9666. if (nodeInspect && nodeInspect in value && typeof value[nodeInspect] === 'function') {
  9667. return value[nodeInspect](options.depth, options);
  9668. }
  9669. if ('inspect' in value && typeof value.inspect === 'function') {
  9670. return value.inspect(options.depth, options);
  9671. }
  9672. if ('constructor' in value && constructorMap.has(value.constructor)) {
  9673. return constructorMap.get(value.constructor)(value, options);
  9674. }
  9675. if (stringTagMap[type]) {
  9676. return stringTagMap[type](value, options);
  9677. }
  9678. return '';
  9679. };
  9680. var toString$1 = Object.prototype.toString; // eslint-disable-next-line complexity
  9681. function inspect(value, options) {
  9682. options = normaliseOptions(options);
  9683. options.inspect = inspect;
  9684. var _options = options,
  9685. customInspect = _options.customInspect;
  9686. var type = value === null ? 'null' : _typeof(value);
  9687. if (type === 'object') {
  9688. type = toString$1.call(value).slice(8, -1);
  9689. } // If it is a base value that we already support, then use Loupe's inspector
  9690. if (baseTypesMap[type]) {
  9691. return baseTypesMap[type](value, options);
  9692. } // If `options.customInspect` is set to true then try to use the custom inspector
  9693. if (customInspect && value) {
  9694. var output = inspectCustom(value, options, type);
  9695. if (output) {
  9696. if (typeof output === 'string') return output;
  9697. return inspect(output, options);
  9698. }
  9699. }
  9700. var proto = value ? Object.getPrototypeOf(value) : false; // If it's a plain Object then use Loupe's inspector
  9701. if (proto === Object.prototype || proto === null) {
  9702. return inspectObject(value, options);
  9703. } // Specifically account for HTMLElements
  9704. // eslint-disable-next-line no-undef
  9705. if (value && typeof HTMLElement === 'function' && value instanceof HTMLElement) {
  9706. return inspectHTML(value, options);
  9707. }
  9708. if ('constructor' in value) {
  9709. // If it is a class, inspect it like an object but add the constructor name
  9710. if (value.constructor !== Object) {
  9711. return inspectClass(value, options);
  9712. } // If it is an object with an anonymous prototype, display it as an object.
  9713. return inspectObject(value, options);
  9714. } // last chance to check if it's an object
  9715. if (value === Object(value)) {
  9716. return inspectObject(value, options);
  9717. } // We have run out of options! Just stringify the value
  9718. return options.stylize(String(value), type);
  9719. }
  9720. function registerConstructor(constructor, inspector) {
  9721. if (constructorMap.has(constructor)) {
  9722. return false;
  9723. }
  9724. constructorMap.set(constructor, inspector);
  9725. return true;
  9726. }
  9727. function registerStringTag(stringTag, inspector) {
  9728. if (stringTag in stringTagMap) {
  9729. return false;
  9730. }
  9731. stringTagMap[stringTag] = inspector;
  9732. return true;
  9733. }
  9734. var custom = chaiInspect;
  9735. exports.custom = custom;
  9736. exports.default = inspect;
  9737. exports.inspect = inspect;
  9738. exports.registerConstructor = registerConstructor;
  9739. exports.registerStringTag = registerStringTag;
  9740. Object.defineProperty(exports, '__esModule', { value: true });
  9741. })));
  9742. },{"util":undefined}],38:[function(require,module,exports){
  9743. 'use strict';
  9744. /* !
  9745. * Chai - pathval utility
  9746. * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com>
  9747. * @see https://github.com/logicalparadox/filtr
  9748. * MIT Licensed
  9749. */
  9750. /**
  9751. * ### .hasProperty(object, name)
  9752. *
  9753. * This allows checking whether an object has own
  9754. * or inherited from prototype chain named property.
  9755. *
  9756. * Basically does the same thing as the `in`
  9757. * operator but works properly with null/undefined values
  9758. * and other primitives.
  9759. *
  9760. * var obj = {
  9761. * arr: ['a', 'b', 'c']
  9762. * , str: 'Hello'
  9763. * }
  9764. *
  9765. * The following would be the results.
  9766. *
  9767. * hasProperty(obj, 'str'); // true
  9768. * hasProperty(obj, 'constructor'); // true
  9769. * hasProperty(obj, 'bar'); // false
  9770. *
  9771. * hasProperty(obj.str, 'length'); // true
  9772. * hasProperty(obj.str, 1); // true
  9773. * hasProperty(obj.str, 5); // false
  9774. *
  9775. * hasProperty(obj.arr, 'length'); // true
  9776. * hasProperty(obj.arr, 2); // true
  9777. * hasProperty(obj.arr, 3); // false
  9778. *
  9779. * @param {Object} object
  9780. * @param {String|Symbol} name
  9781. * @returns {Boolean} whether it exists
  9782. * @namespace Utils
  9783. * @name hasProperty
  9784. * @api public
  9785. */
  9786. function hasProperty(obj, name) {
  9787. if (typeof obj === 'undefined' || obj === null) {
  9788. return false;
  9789. }
  9790. // The `in` operator does not work with primitives.
  9791. return name in Object(obj);
  9792. }
  9793. /* !
  9794. * ## parsePath(path)
  9795. *
  9796. * Helper function used to parse string object
  9797. * paths. Use in conjunction with `internalGetPathValue`.
  9798. *
  9799. * var parsed = parsePath('myobject.property.subprop');
  9800. *
  9801. * ### Paths:
  9802. *
  9803. * * Can be infinitely deep and nested.
  9804. * * Arrays are also valid using the formal `myobject.document[3].property`.
  9805. * * Literal dots and brackets (not delimiter) must be backslash-escaped.
  9806. *
  9807. * @param {String} path
  9808. * @returns {Object} parsed
  9809. * @api private
  9810. */
  9811. function parsePath(path) {
  9812. var str = path.replace(/([^\\])\[/g, '$1.[');
  9813. var parts = str.match(/(\\\.|[^.]+?)+/g);
  9814. return parts.map(function mapMatches(value) {
  9815. if (
  9816. value === 'constructor' ||
  9817. value === '__proto__' ||
  9818. value === 'prototype'
  9819. ) {
  9820. return {};
  9821. }
  9822. var regexp = /^\[(\d+)\]$/;
  9823. var mArr = regexp.exec(value);
  9824. var parsed = null;
  9825. if (mArr) {
  9826. parsed = { i: parseFloat(mArr[1]) };
  9827. } else {
  9828. parsed = { p: value.replace(/\\([.[\]])/g, '$1') };
  9829. }
  9830. return parsed;
  9831. });
  9832. }
  9833. /* !
  9834. * ## internalGetPathValue(obj, parsed[, pathDepth])
  9835. *
  9836. * Helper companion function for `.parsePath` that returns
  9837. * the value located at the parsed address.
  9838. *
  9839. * var value = getPathValue(obj, parsed);
  9840. *
  9841. * @param {Object} object to search against
  9842. * @param {Object} parsed definition from `parsePath`.
  9843. * @param {Number} depth (nesting level) of the property we want to retrieve
  9844. * @returns {Object|Undefined} value
  9845. * @api private
  9846. */
  9847. function internalGetPathValue(obj, parsed, pathDepth) {
  9848. var temporaryValue = obj;
  9849. var res = null;
  9850. pathDepth = typeof pathDepth === 'undefined' ? parsed.length : pathDepth;
  9851. for (var i = 0; i < pathDepth; i++) {
  9852. var part = parsed[i];
  9853. if (temporaryValue) {
  9854. if (typeof part.p === 'undefined') {
  9855. temporaryValue = temporaryValue[part.i];
  9856. } else {
  9857. temporaryValue = temporaryValue[part.p];
  9858. }
  9859. if (i === pathDepth - 1) {
  9860. res = temporaryValue;
  9861. }
  9862. }
  9863. }
  9864. return res;
  9865. }
  9866. /* !
  9867. * ## internalSetPathValue(obj, value, parsed)
  9868. *
  9869. * Companion function for `parsePath` that sets
  9870. * the value located at a parsed address.
  9871. *
  9872. * internalSetPathValue(obj, 'value', parsed);
  9873. *
  9874. * @param {Object} object to search and define on
  9875. * @param {*} value to use upon set
  9876. * @param {Object} parsed definition from `parsePath`
  9877. * @api private
  9878. */
  9879. function internalSetPathValue(obj, val, parsed) {
  9880. var tempObj = obj;
  9881. var pathDepth = parsed.length;
  9882. var part = null;
  9883. // Here we iterate through every part of the path
  9884. for (var i = 0; i < pathDepth; i++) {
  9885. var propName = null;
  9886. var propVal = null;
  9887. part = parsed[i];
  9888. // If it's the last part of the path, we set the 'propName' value with the property name
  9889. if (i === pathDepth - 1) {
  9890. propName = typeof part.p === 'undefined' ? part.i : part.p;
  9891. // Now we set the property with the name held by 'propName' on object with the desired val
  9892. tempObj[propName] = val;
  9893. } else if (typeof part.p !== 'undefined' && tempObj[part.p]) {
  9894. tempObj = tempObj[part.p];
  9895. } else if (typeof part.i !== 'undefined' && tempObj[part.i]) {
  9896. tempObj = tempObj[part.i];
  9897. } else {
  9898. // If the obj doesn't have the property we create one with that name to define it
  9899. var next = parsed[i + 1];
  9900. // Here we set the name of the property which will be defined
  9901. propName = typeof part.p === 'undefined' ? part.i : part.p;
  9902. // Here we decide if this property will be an array or a new object
  9903. propVal = typeof next.p === 'undefined' ? [] : {};
  9904. tempObj[propName] = propVal;
  9905. tempObj = tempObj[propName];
  9906. }
  9907. }
  9908. }
  9909. /**
  9910. * ### .getPathInfo(object, path)
  9911. *
  9912. * This allows the retrieval of property info in an
  9913. * object given a string path.
  9914. *
  9915. * The path info consists of an object with the
  9916. * following properties:
  9917. *
  9918. * * parent - The parent object of the property referenced by `path`
  9919. * * name - The name of the final property, a number if it was an array indexer
  9920. * * value - The value of the property, if it exists, otherwise `undefined`
  9921. * * exists - Whether the property exists or not
  9922. *
  9923. * @param {Object} object
  9924. * @param {String} path
  9925. * @returns {Object} info
  9926. * @namespace Utils
  9927. * @name getPathInfo
  9928. * @api public
  9929. */
  9930. function getPathInfo(obj, path) {
  9931. var parsed = parsePath(path);
  9932. var last = parsed[parsed.length - 1];
  9933. var info = {
  9934. parent:
  9935. parsed.length > 1 ?
  9936. internalGetPathValue(obj, parsed, parsed.length - 1) :
  9937. obj,
  9938. name: last.p || last.i,
  9939. value: internalGetPathValue(obj, parsed),
  9940. };
  9941. info.exists = hasProperty(info.parent, info.name);
  9942. return info;
  9943. }
  9944. /**
  9945. * ### .getPathValue(object, path)
  9946. *
  9947. * This allows the retrieval of values in an
  9948. * object given a string path.
  9949. *
  9950. * var obj = {
  9951. * prop1: {
  9952. * arr: ['a', 'b', 'c']
  9953. * , str: 'Hello'
  9954. * }
  9955. * , prop2: {
  9956. * arr: [ { nested: 'Universe' } ]
  9957. * , str: 'Hello again!'
  9958. * }
  9959. * }
  9960. *
  9961. * The following would be the results.
  9962. *
  9963. * getPathValue(obj, 'prop1.str'); // Hello
  9964. * getPathValue(obj, 'prop1.att[2]'); // b
  9965. * getPathValue(obj, 'prop2.arr[0].nested'); // Universe
  9966. *
  9967. * @param {Object} object
  9968. * @param {String} path
  9969. * @returns {Object} value or `undefined`
  9970. * @namespace Utils
  9971. * @name getPathValue
  9972. * @api public
  9973. */
  9974. function getPathValue(obj, path) {
  9975. var info = getPathInfo(obj, path);
  9976. return info.value;
  9977. }
  9978. /**
  9979. * ### .setPathValue(object, path, value)
  9980. *
  9981. * Define the value in an object at a given string path.
  9982. *
  9983. * ```js
  9984. * var obj = {
  9985. * prop1: {
  9986. * arr: ['a', 'b', 'c']
  9987. * , str: 'Hello'
  9988. * }
  9989. * , prop2: {
  9990. * arr: [ { nested: 'Universe' } ]
  9991. * , str: 'Hello again!'
  9992. * }
  9993. * };
  9994. * ```
  9995. *
  9996. * The following would be acceptable.
  9997. *
  9998. * ```js
  9999. * var properties = require('tea-properties');
  10000. * properties.set(obj, 'prop1.str', 'Hello Universe!');
  10001. * properties.set(obj, 'prop1.arr[2]', 'B');
  10002. * properties.set(obj, 'prop2.arr[0].nested.value', { hello: 'universe' });
  10003. * ```
  10004. *
  10005. * @param {Object} object
  10006. * @param {String} path
  10007. * @param {Mixed} value
  10008. * @api private
  10009. */
  10010. function setPathValue(obj, path, val) {
  10011. var parsed = parsePath(path);
  10012. internalSetPathValue(obj, val, parsed);
  10013. return obj;
  10014. }
  10015. module.exports = {
  10016. hasProperty: hasProperty,
  10017. getPathInfo: getPathInfo,
  10018. getPathValue: getPathValue,
  10019. setPathValue: setPathValue,
  10020. };
  10021. },{}],39:[function(require,module,exports){
  10022. (function (global, factory) {
  10023. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  10024. typeof define === 'function' && define.amd ? define(factory) :
  10025. (global.typeDetect = factory());
  10026. }(this, (function () { 'use strict';
  10027. /* !
  10028. * type-detect
  10029. * Copyright(c) 2013 jake luer <jake@alogicalparadox.com>
  10030. * MIT Licensed
  10031. */
  10032. var promiseExists = typeof Promise === 'function';
  10033. /* eslint-disable no-undef */
  10034. var globalObject = typeof self === 'object' ? self : global; // eslint-disable-line id-blacklist
  10035. var symbolExists = typeof Symbol !== 'undefined';
  10036. var mapExists = typeof Map !== 'undefined';
  10037. var setExists = typeof Set !== 'undefined';
  10038. var weakMapExists = typeof WeakMap !== 'undefined';
  10039. var weakSetExists = typeof WeakSet !== 'undefined';
  10040. var dataViewExists = typeof DataView !== 'undefined';
  10041. var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined';
  10042. var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined';
  10043. var setEntriesExists = setExists && typeof Set.prototype.entries === 'function';
  10044. var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function';
  10045. var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries());
  10046. var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries());
  10047. var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function';
  10048. var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]());
  10049. var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function';
  10050. var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]());
  10051. var toStringLeftSliceLength = 8;
  10052. var toStringRightSliceLength = -1;
  10053. /**
  10054. * ### typeOf (obj)
  10055. *
  10056. * Uses `Object.prototype.toString` to determine the type of an object,
  10057. * normalising behaviour across engine versions & well optimised.
  10058. *
  10059. * @param {Mixed} object
  10060. * @return {String} object type
  10061. * @api public
  10062. */
  10063. function typeDetect(obj) {
  10064. /* ! Speed optimisation
  10065. * Pre:
  10066. * string literal x 3,039,035 ops/sec ±1.62% (78 runs sampled)
  10067. * boolean literal x 1,424,138 ops/sec ±4.54% (75 runs sampled)
  10068. * number literal x 1,653,153 ops/sec ±1.91% (82 runs sampled)
  10069. * undefined x 9,978,660 ops/sec ±1.92% (75 runs sampled)
  10070. * function x 2,556,769 ops/sec ±1.73% (77 runs sampled)
  10071. * Post:
  10072. * string literal x 38,564,796 ops/sec ±1.15% (79 runs sampled)
  10073. * boolean literal x 31,148,940 ops/sec ±1.10% (79 runs sampled)
  10074. * number literal x 32,679,330 ops/sec ±1.90% (78 runs sampled)
  10075. * undefined x 32,363,368 ops/sec ±1.07% (82 runs sampled)
  10076. * function x 31,296,870 ops/sec ±0.96% (83 runs sampled)
  10077. */
  10078. var typeofObj = typeof obj;
  10079. if (typeofObj !== 'object') {
  10080. return typeofObj;
  10081. }
  10082. /* ! Speed optimisation
  10083. * Pre:
  10084. * null x 28,645,765 ops/sec ±1.17% (82 runs sampled)
  10085. * Post:
  10086. * null x 36,428,962 ops/sec ±1.37% (84 runs sampled)
  10087. */
  10088. if (obj === null) {
  10089. return 'null';
  10090. }
  10091. /* ! Spec Conformance
  10092. * Test: `Object.prototype.toString.call(window)``
  10093. * - Node === "[object global]"
  10094. * - Chrome === "[object global]"
  10095. * - Firefox === "[object Window]"
  10096. * - PhantomJS === "[object Window]"
  10097. * - Safari === "[object Window]"
  10098. * - IE 11 === "[object Window]"
  10099. * - IE Edge === "[object Window]"
  10100. * Test: `Object.prototype.toString.call(this)``
  10101. * - Chrome Worker === "[object global]"
  10102. * - Firefox Worker === "[object DedicatedWorkerGlobalScope]"
  10103. * - Safari Worker === "[object DedicatedWorkerGlobalScope]"
  10104. * - IE 11 Worker === "[object WorkerGlobalScope]"
  10105. * - IE Edge Worker === "[object WorkerGlobalScope]"
  10106. */
  10107. if (obj === globalObject) {
  10108. return 'global';
  10109. }
  10110. /* ! Speed optimisation
  10111. * Pre:
  10112. * array literal x 2,888,352 ops/sec ±0.67% (82 runs sampled)
  10113. * Post:
  10114. * array literal x 22,479,650 ops/sec ±0.96% (81 runs sampled)
  10115. */
  10116. if (
  10117. Array.isArray(obj) &&
  10118. (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))
  10119. ) {
  10120. return 'Array';
  10121. }
  10122. // Not caching existence of `window` and related properties due to potential
  10123. // for `window` to be unset before tests in quasi-browser environments.
  10124. if (typeof window === 'object' && window !== null) {
  10125. /* ! Spec Conformance
  10126. * (https://html.spec.whatwg.org/multipage/browsers.html#location)
  10127. * WhatWG HTML$7.7.3 - The `Location` interface
  10128. * Test: `Object.prototype.toString.call(window.location)``
  10129. * - IE <=11 === "[object Object]"
  10130. * - IE Edge <=13 === "[object Object]"
  10131. */
  10132. if (typeof window.location === 'object' && obj === window.location) {
  10133. return 'Location';
  10134. }
  10135. /* ! Spec Conformance
  10136. * (https://html.spec.whatwg.org/#document)
  10137. * WhatWG HTML$3.1.1 - The `Document` object
  10138. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  10139. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268)
  10140. * which suggests that browsers should use HTMLTableCellElement for
  10141. * both TD and TH elements. WhatWG separates these.
  10142. * WhatWG HTML states:
  10143. * > For historical reasons, Window objects must also have a
  10144. * > writable, configurable, non-enumerable property named
  10145. * > HTMLDocument whose value is the Document interface object.
  10146. * Test: `Object.prototype.toString.call(document)``
  10147. * - Chrome === "[object HTMLDocument]"
  10148. * - Firefox === "[object HTMLDocument]"
  10149. * - Safari === "[object HTMLDocument]"
  10150. * - IE <=10 === "[object Document]"
  10151. * - IE 11 === "[object HTMLDocument]"
  10152. * - IE Edge <=13 === "[object HTMLDocument]"
  10153. */
  10154. if (typeof window.document === 'object' && obj === window.document) {
  10155. return 'Document';
  10156. }
  10157. if (typeof window.navigator === 'object') {
  10158. /* ! Spec Conformance
  10159. * (https://html.spec.whatwg.org/multipage/webappapis.html#mimetypearray)
  10160. * WhatWG HTML$8.6.1.5 - Plugins - Interface MimeTypeArray
  10161. * Test: `Object.prototype.toString.call(navigator.mimeTypes)``
  10162. * - IE <=10 === "[object MSMimeTypesCollection]"
  10163. */
  10164. if (typeof window.navigator.mimeTypes === 'object' &&
  10165. obj === window.navigator.mimeTypes) {
  10166. return 'MimeTypeArray';
  10167. }
  10168. /* ! Spec Conformance
  10169. * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
  10170. * WhatWG HTML$8.6.1.5 - Plugins - Interface PluginArray
  10171. * Test: `Object.prototype.toString.call(navigator.plugins)``
  10172. * - IE <=10 === "[object MSPluginsCollection]"
  10173. */
  10174. if (typeof window.navigator.plugins === 'object' &&
  10175. obj === window.navigator.plugins) {
  10176. return 'PluginArray';
  10177. }
  10178. }
  10179. if ((typeof window.HTMLElement === 'function' ||
  10180. typeof window.HTMLElement === 'object') &&
  10181. obj instanceof window.HTMLElement) {
  10182. /* ! Spec Conformance
  10183. * (https://html.spec.whatwg.org/multipage/webappapis.html#pluginarray)
  10184. * WhatWG HTML$4.4.4 - The `blockquote` element - Interface `HTMLQuoteElement`
  10185. * Test: `Object.prototype.toString.call(document.createElement('blockquote'))``
  10186. * - IE <=10 === "[object HTMLBlockElement]"
  10187. */
  10188. if (obj.tagName === 'BLOCKQUOTE') {
  10189. return 'HTMLQuoteElement';
  10190. }
  10191. /* ! Spec Conformance
  10192. * (https://html.spec.whatwg.org/#htmltabledatacellelement)
  10193. * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableDataCellElement`
  10194. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  10195. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
  10196. * which suggests that browsers should use HTMLTableCellElement for
  10197. * both TD and TH elements. WhatWG separates these.
  10198. * Test: Object.prototype.toString.call(document.createElement('td'))
  10199. * - Chrome === "[object HTMLTableCellElement]"
  10200. * - Firefox === "[object HTMLTableCellElement]"
  10201. * - Safari === "[object HTMLTableCellElement]"
  10202. */
  10203. if (obj.tagName === 'TD') {
  10204. return 'HTMLTableDataCellElement';
  10205. }
  10206. /* ! Spec Conformance
  10207. * (https://html.spec.whatwg.org/#htmltableheadercellelement)
  10208. * WhatWG HTML$4.9.9 - The `td` element - Interface `HTMLTableHeaderCellElement`
  10209. * Note: Most browsers currently adher to the W3C DOM Level 2 spec
  10210. * (https://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-82915075)
  10211. * which suggests that browsers should use HTMLTableCellElement for
  10212. * both TD and TH elements. WhatWG separates these.
  10213. * Test: Object.prototype.toString.call(document.createElement('th'))
  10214. * - Chrome === "[object HTMLTableCellElement]"
  10215. * - Firefox === "[object HTMLTableCellElement]"
  10216. * - Safari === "[object HTMLTableCellElement]"
  10217. */
  10218. if (obj.tagName === 'TH') {
  10219. return 'HTMLTableHeaderCellElement';
  10220. }
  10221. }
  10222. }
  10223. /* ! Speed optimisation
  10224. * Pre:
  10225. * Float64Array x 625,644 ops/sec ±1.58% (80 runs sampled)
  10226. * Float32Array x 1,279,852 ops/sec ±2.91% (77 runs sampled)
  10227. * Uint32Array x 1,178,185 ops/sec ±1.95% (83 runs sampled)
  10228. * Uint16Array x 1,008,380 ops/sec ±2.25% (80 runs sampled)
  10229. * Uint8Array x 1,128,040 ops/sec ±2.11% (81 runs sampled)
  10230. * Int32Array x 1,170,119 ops/sec ±2.88% (80 runs sampled)
  10231. * Int16Array x 1,176,348 ops/sec ±5.79% (86 runs sampled)
  10232. * Int8Array x 1,058,707 ops/sec ±4.94% (77 runs sampled)
  10233. * Uint8ClampedArray x 1,110,633 ops/sec ±4.20% (80 runs sampled)
  10234. * Post:
  10235. * Float64Array x 7,105,671 ops/sec ±13.47% (64 runs sampled)
  10236. * Float32Array x 5,887,912 ops/sec ±1.46% (82 runs sampled)
  10237. * Uint32Array x 6,491,661 ops/sec ±1.76% (79 runs sampled)
  10238. * Uint16Array x 6,559,795 ops/sec ±1.67% (82 runs sampled)
  10239. * Uint8Array x 6,463,966 ops/sec ±1.43% (85 runs sampled)
  10240. * Int32Array x 5,641,841 ops/sec ±3.49% (81 runs sampled)
  10241. * Int16Array x 6,583,511 ops/sec ±1.98% (80 runs sampled)
  10242. * Int8Array x 6,606,078 ops/sec ±1.74% (81 runs sampled)
  10243. * Uint8ClampedArray x 6,602,224 ops/sec ±1.77% (83 runs sampled)
  10244. */
  10245. var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]);
  10246. if (typeof stringTag === 'string') {
  10247. return stringTag;
  10248. }
  10249. var objPrototype = Object.getPrototypeOf(obj);
  10250. /* ! Speed optimisation
  10251. * Pre:
  10252. * regex literal x 1,772,385 ops/sec ±1.85% (77 runs sampled)
  10253. * regex constructor x 2,143,634 ops/sec ±2.46% (78 runs sampled)
  10254. * Post:
  10255. * regex literal x 3,928,009 ops/sec ±0.65% (78 runs sampled)
  10256. * regex constructor x 3,931,108 ops/sec ±0.58% (84 runs sampled)
  10257. */
  10258. if (objPrototype === RegExp.prototype) {
  10259. return 'RegExp';
  10260. }
  10261. /* ! Speed optimisation
  10262. * Pre:
  10263. * date x 2,130,074 ops/sec ±4.42% (68 runs sampled)
  10264. * Post:
  10265. * date x 3,953,779 ops/sec ±1.35% (77 runs sampled)
  10266. */
  10267. if (objPrototype === Date.prototype) {
  10268. return 'Date';
  10269. }
  10270. /* ! Spec Conformance
  10271. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise.prototype-@@tostringtag)
  10272. * ES6$25.4.5.4 - Promise.prototype[@@toStringTag] should be "Promise":
  10273. * Test: `Object.prototype.toString.call(Promise.resolve())``
  10274. * - Chrome <=47 === "[object Object]"
  10275. * - Edge <=20 === "[object Object]"
  10276. * - Firefox 29-Latest === "[object Promise]"
  10277. * - Safari 7.1-Latest === "[object Promise]"
  10278. */
  10279. if (promiseExists && objPrototype === Promise.prototype) {
  10280. return 'Promise';
  10281. }
  10282. /* ! Speed optimisation
  10283. * Pre:
  10284. * set x 2,222,186 ops/sec ±1.31% (82 runs sampled)
  10285. * Post:
  10286. * set x 4,545,879 ops/sec ±1.13% (83 runs sampled)
  10287. */
  10288. if (setExists && objPrototype === Set.prototype) {
  10289. return 'Set';
  10290. }
  10291. /* ! Speed optimisation
  10292. * Pre:
  10293. * map x 2,396,842 ops/sec ±1.59% (81 runs sampled)
  10294. * Post:
  10295. * map x 4,183,945 ops/sec ±6.59% (82 runs sampled)
  10296. */
  10297. if (mapExists && objPrototype === Map.prototype) {
  10298. return 'Map';
  10299. }
  10300. /* ! Speed optimisation
  10301. * Pre:
  10302. * weakset x 1,323,220 ops/sec ±2.17% (76 runs sampled)
  10303. * Post:
  10304. * weakset x 4,237,510 ops/sec ±2.01% (77 runs sampled)
  10305. */
  10306. if (weakSetExists && objPrototype === WeakSet.prototype) {
  10307. return 'WeakSet';
  10308. }
  10309. /* ! Speed optimisation
  10310. * Pre:
  10311. * weakmap x 1,500,260 ops/sec ±2.02% (78 runs sampled)
  10312. * Post:
  10313. * weakmap x 3,881,384 ops/sec ±1.45% (82 runs sampled)
  10314. */
  10315. if (weakMapExists && objPrototype === WeakMap.prototype) {
  10316. return 'WeakMap';
  10317. }
  10318. /* ! Spec Conformance
  10319. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-dataview.prototype-@@tostringtag)
  10320. * ES6$24.2.4.21 - DataView.prototype[@@toStringTag] should be "DataView":
  10321. * Test: `Object.prototype.toString.call(new DataView(new ArrayBuffer(1)))``
  10322. * - Edge <=13 === "[object Object]"
  10323. */
  10324. if (dataViewExists && objPrototype === DataView.prototype) {
  10325. return 'DataView';
  10326. }
  10327. /* ! Spec Conformance
  10328. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%mapiteratorprototype%-@@tostringtag)
  10329. * ES6$23.1.5.2.2 - %MapIteratorPrototype%[@@toStringTag] should be "Map Iterator":
  10330. * Test: `Object.prototype.toString.call(new Map().entries())``
  10331. * - Edge <=13 === "[object Object]"
  10332. */
  10333. if (mapExists && objPrototype === mapIteratorPrototype) {
  10334. return 'Map Iterator';
  10335. }
  10336. /* ! Spec Conformance
  10337. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%setiteratorprototype%-@@tostringtag)
  10338. * ES6$23.2.5.2.2 - %SetIteratorPrototype%[@@toStringTag] should be "Set Iterator":
  10339. * Test: `Object.prototype.toString.call(new Set().entries())``
  10340. * - Edge <=13 === "[object Object]"
  10341. */
  10342. if (setExists && objPrototype === setIteratorPrototype) {
  10343. return 'Set Iterator';
  10344. }
  10345. /* ! Spec Conformance
  10346. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%-@@tostringtag)
  10347. * ES6$22.1.5.2.2 - %ArrayIteratorPrototype%[@@toStringTag] should be "Array Iterator":
  10348. * Test: `Object.prototype.toString.call([][Symbol.iterator]())``
  10349. * - Edge <=13 === "[object Object]"
  10350. */
  10351. if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) {
  10352. return 'Array Iterator';
  10353. }
  10354. /* ! Spec Conformance
  10355. * (http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%stringiteratorprototype%-@@tostringtag)
  10356. * ES6$21.1.5.2.2 - %StringIteratorPrototype%[@@toStringTag] should be "String Iterator":
  10357. * Test: `Object.prototype.toString.call(''[Symbol.iterator]())``
  10358. * - Edge <=13 === "[object Object]"
  10359. */
  10360. if (stringIteratorExists && objPrototype === stringIteratorPrototype) {
  10361. return 'String Iterator';
  10362. }
  10363. /* ! Speed optimisation
  10364. * Pre:
  10365. * object from null x 2,424,320 ops/sec ±1.67% (76 runs sampled)
  10366. * Post:
  10367. * object from null x 5,838,000 ops/sec ±0.99% (84 runs sampled)
  10368. */
  10369. if (objPrototype === null) {
  10370. return 'Object';
  10371. }
  10372. return Object
  10373. .prototype
  10374. .toString
  10375. .call(obj)
  10376. .slice(toStringLeftSliceLength, toStringRightSliceLength);
  10377. }
  10378. return typeDetect;
  10379. })));
  10380. },{}]},{},[1])(1)
  10381. });