chai-angular is a collection of small utilities that help testing Angular apps with Chai.
Calling it a collection is a strong word, since it only contains one utility. Hopefully it will stay that way — the more things work out of the box between Angular and Chai, the better!
resourceEql
resourceEql compares Angular resources with plain objects.
Let's say the Angular controller mycontroller
contains this code:
var User = ;$scopeuser = User;
A typical test for this controller would be:
var $scope = {}; $httpBackend;;$httpBackend; $scopeusershoulddeep;
However, this test fails because $scope.user
is not a plain old Javascript object, but an Angular resource, and Chai's deep equality sees them as different.
To make the test pass, install the chai-angular plugin, then replace deep.equal
with deep.resource.equal
:
$scopeusershoulddeepresource;
The usual Chai syntactic variants are also available:
$scopeusershould; todeepresource;to; assert;assert;
Installation
$ npm install chai-angular --save-dev
Karma
Usage withIn karma.conf.js
, add to files
the path to chai-angular.js
:
module { config;};
You can then immediately start using chai-angular assertions in your tests.