mardi 27 mars 2018

How can I test this angularjs filter?

I found this AngularJS unique filter example online: https://tutorialedge.net/javascript/angularjs/removing-duplicates-from-ng-repeat/

And I'm trying to test it. I'm really close but I'm getting an error that I don't understand why. Any idea what I'm doing wrong?

describe('Unique Filter', function() {
  'use strict';

  var $filter;

  beforeEach(function () {
    module('resource');

    inject(function (_$filter_) {
      $filter = _$filter_;
    });
  });

  it('should only return unique values', function() {
    var list = [
      { 'name' : "ipad" },
      { 'name' : "ipad" },
      { 'name' : "ipad" },
      { 'name' : "ipod" },
      { 'name' : "iMac" },
      { 'name' : "iMac" },
      { 'name' : "iMac" },
      { 'name' : "iPhone" },
      { 'name' : "iWatch" },
      { 'name' : "iWatch" },
      { 'name' : "iWatch" },
      { 'name' : "iPeed" }];

    var resultList = [
      { 'name' : "ipad" },
      { 'name' : "iMac" },
      { 'name' : "iPhone" },
      { 'name' : "iWatch" },
      { 'name' : "iPeed" }];

    var result = $filter('unique');
    expect(result(list)).toBe(resultList);
  });
});

And the error I'm getting is:

PhantomJS 2.1.1 (Linux 0.0.0) Unique Filter should only return unique values FAILED
    Expected [ Object({ name: 'ipad' }) ] to be [ Object({ name: 'ipad' }), Object({ name: 'iMac' }), Object({ name: 'iPhone' }), Object({ name: 'iWatch' }), Object({ name: 'iPeed' }) ].
    test/spec/resource/resource.filter.js:37:30

Aucun commentaire:

Enregistrer un commentaire