Skip to content

Commit

Permalink
fix(getFacetStats): remove error (algolia/algoliasearch-helper-js#721)
Browse files Browse the repository at this point in the history
* fix(getFacetStats): remove error

This now should also return `undefined` without warning, like algolia/algoliasearch-helper-js#720

* chore: fix test
  • Loading branch information
Haroenv committed Nov 18, 2019
1 parent 7e6ed73 commit 8ba6fc8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/algoliasearch-helper/src/SearchResults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ SearchResults.prototype.getFacetStats = function(attribute) {
return getFacetStatsIfAvailable(this.disjunctiveFacets, attribute);
}

throw new Error(attribute + ' is not present in `facets` or `disjunctiveFacets`');
return undefined;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
var SearchResults = require('../../../src/SearchResults');
var SearchParameters = require('../../../src/SearchParameters');

var bind = require('lodash/bind');

var response = {
'results': [{
'page': 0,
Expand Down Expand Up @@ -43,8 +41,8 @@ test('getFacetStats(facetName) returns stats for any facet or disjunctiveFacet',
});
var result = new SearchResults(searchParams, response.results);

expect(bind(result.getFacetStats, result, 'city')).toThrowError(Error);
expect(result.getFacetStats('country')).toBe(undefined);
expect(result.getFacetStats('city')).toBeUndefined();
expect(result.getFacetStats('country')).toBeUndefined();
expect(result.getFacetStats('age')).toEqual(response.results[0].facets_stats.age);
expect(result.getFacetStats('price')).toEqual(response.results[0].facets_stats.price);
});
Expand Down

0 comments on commit 8ba6fc8

Please sign in to comment.