diff --git a/src/__tests__/store.js b/src/__tests__/store.js index d8d8b905c..bcd12f89b 100644 --- a/src/__tests__/store.js +++ b/src/__tests__/store.js @@ -116,6 +116,27 @@ describe('Store', () => { expect(store.page).toEqual(2); }); + test('can retrieve userData if it exists', () => { + const store = createStore(); + store._helper = { + lastResults: { + userData: ['a value'], + }, + }; + + expect(store.userData).toEqual(['a value']); + }); + + test('returns undefined as userData if no last response is available', () => { + const store = createStore(); + expect(store.userData).toEqual(undefined); + }); + + test('returns undefined if not userData is part of the last response', () => { + const store = createStore(); + expect(store.userData).toEqual(undefined); + }); + test('should add "vue-instantsearch" User Agent to the client with the current version', () => { const addAlgoliaAgent = jest.fn(); const client = { diff --git a/src/store.js b/src/store.js index b9a18190e..dac25d03a 100644 --- a/src/store.js +++ b/src/store.js @@ -194,6 +194,14 @@ export class Store { return this._helper.lastResults.nbPages; } + get userData() { + if (!this._helper.lastResults) { + return undefined; + } + + return this._helper.lastResults.userData; + } + get totalResults() { if (!this._helper.lastResults) { return 0;