Giter Site home page Giter Site logo

chai-angular's Introduction

chai-angular Build Status Coverage Status npm

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 = $resource('/user/:id');
$scope.user = User.get({id: 9});

A typical test for this controller would be:

var $scope = {};

$httpBackend.expectGET('/user/9').respond({id: '9', name: 'Roger Zelazny'});
$controller('mycontroller', {$scope: $scope});
$httpBackend.flush();

$scope.user.should.deep.equal({id: '9', name: 'Roger Zelazny'});

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:

$scope.user.should.deep.resource.equal({id: '9', name: 'Roger Zelazny'});

The usual Chai syntactic variants are also available:

$scope.user.should.resourceEql({id: '9', name: 'Roger Zelazny'});

expect($scope.user).to.deep.resource.equal({id: '9', name: 'Roger Zelazny'});
expect($scope.user).to.resourceEql({id: '9', name: 'Roger Zelazny'});

assert.resourceEqual($scope.user, {id: '9', name: 'Roger Zelazny'});
assert.notResourceEqual($scope.user, {id: '10', name: 'Philip K. Dick'});

Installation

$ npm install chai-angular --save-dev

Usage with Karma

In karma.conf.js, add to files the path to chai-angular.js:

module.exports = function(config) {
    config.set({
        basePath : '../',
        files : [
            'node_modules/chai-angular/chai-angular.js',
            ...
        ],
        ...
    });
};

You can then immediately start using chai-angular assertions in your tests.

chai-angular's People

Contributors

peferron avatar 6uliver avatar michael-wolfenden avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.