-
Notifications
You must be signed in to change notification settings - Fork 157
#393 - Feature: pass in the page when emitting the page change event #394
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Since people didn't expect anything in that callback, we can release this as a patch I think
Can you edit the test too? ( vue-instantsearch/src/components/__tests__/pagination.js Lines 93 to 118 in 40c9406
|
@Haroenv Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the tests, I think you changed the wrong test though.
@@ -108,7 +108,7 @@ test('it should emit a "page-change" event when page changes', () => { | |||
|
|||
vm.$mount(); | |||
|
|||
expect(onPageChange).not.toHaveBeenCalled(); | |||
expect(onPageChange).not.toHaveBeenCalledWith('page'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have stayed the same, it's testing that it wasn't called yet
@@ -108,7 +108,7 @@ test('it should emit a "page-change" event when page changes', () => { | |||
|
|||
vm.$mount(); | |||
|
|||
expect(onPageChange).not.toHaveBeenCalled(); | |||
expect(onPageChange).not.toHaveBeenCalledWith('page'); | |||
|
|||
vm.$el | |||
.getElementsByTagName('li')[3] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after these lines add:
expect(onPageChange).toHaveBeenCalledWith(page);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Haroenv How about this:
test('it should emit a "page-change" event when page changes and pass in the page variable', () => {
const searchStore = {
page: 1,
totalPages: 20,
totalResults: 4000,
};
const Component = Vue.extend(Pagination);
const vm = new Component({
propsData: {
searchStore,
},
});
const onPageChange = jest.fn();
vm.$on('page-change', onPageChange);
vm.$mount();
expect(onPageChange).not.toHaveBeenCalled();
vm.$el
.getElementsByTagName('li')[3]
.getElementsByTagName('a')[0]
.click();
expect(onPageChange).toHaveBeenCalledTimes(1);
const page = searchStore.page;
expect(onPageChange).toHaveBeenCalledWith(page);
expect(page).toBe(2);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly what I meant!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks for your contribution. I’ll release this soon
algolia/vue-instantsearch#394) * algolia/vue-instantsearch#393 - Feature: pass in the page when emitting the page change event * updated test * updated tests
fixes #393