lundi 29 août 2016

how to expect result form filter in unit test

How to expect for equal result from filter if it array with mocked data (tree). My custom filter takes two parameters, tree and query. If query is 'foo' the result from filter will be:

        {
            nodes: [
                {
                    label: 'foo1'
                },
                {
                    label: 'foo2'
                }
            ],
            label: 'foo'
        }

how to expect any element in array for equal with mocked tree?

My unit test:

describe('customFilter', function () {
'use strict';

var definitionSearch,
    tree;

beforeEach(module('myApp'));

beforeEach(inject(function ($filter) {
    customFilter= $filter('customFilter');

    tree = [
        {
            nodes: [
                {
                    label: 'foo1'
                },
                {
                    label: 'foo2'
                }
            ],
            label: 'foo'
        },
        {
            nodes: [
                {
                    label: 'bar1'
                }
            ],
            label: 'bar'
        }
    ];
}));

it('should find name', function () {
    var query = 'foo'
    expect(customFilter(tree, query)).toEqual(/* what should be here*/);
    //customFilter(tree, query) ===> tree[0]
});
});

Aucun commentaire:

Enregistrer un commentaire