0

I'm trying to perform a very basic unit test on an Angular resource:

describe('coupons.resource', function () {
    var Coupons, $httpBackend;

    beforeEach(function () {
        module('coupons.resource');
        inject(function (_Coupons_, _$httpBackend_) {
            Coupons = _Coupons_;
            $httpBackend = _$httpBackend_;
        });
    });

    it('should return empty array if it receives empty array', function () {
        $httpBackend.expectGET(/admin\/coupons/).respond([]);
        Coupons.query().$promise.then(function (data) {
            console.log(data);
            expect(data).toEqual([]);            
        });

        $httpBackend.flush();        
    });
});

Coupons is a resource. The test above fails with the error:

Expected [] to equal []

The console output confirms that data expected is indeed an empty array. This seems so trivial. What am I doing wrong?

Yaron
  • 1,867
  • 20
  • 16
  • if you see [this](http://stackoverflow.com/questions/15717844/jasmine-js-comparing-arrays) your code should work, can you provide plunkr or js fiddle? – Grundy Sep 25 '15 at 17:05
  • @Grundy, I'm not sure how I would set up a Plunkr or JS Fiddle for a Karma test runner. I've never seen one like that before, have you? Also, I don't believe this is an issue with comparing two arrays. I think this has to do with the asynchronous nature of Angular resources, but I could be wrong. – Yaron Sep 28 '15 at 17:16

0 Answers0