Commit 887dd2b1 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'xanf-vtu-30-set-methods' into 'master'

Add nextTick to setMethods calls in Jest

Closes #191457

See merge request gitlab-org/gitlab!22318
parents 62c35c04 f2a3c80d
...@@ -59,6 +59,7 @@ describe('collapsible registry container', () => { ...@@ -59,6 +59,7 @@ describe('collapsible registry container', () => {
beforeEach(() => { beforeEach(() => {
const fetchList = jest.fn(); const fetchList = jest.fn();
wrapper.setMethods({ fetchList }); wrapper.setMethods({ fetchList });
return wrapper.vm.$nextTick();
}); });
const expectIsClosed = () => { const expectIsClosed = () => {
......
...@@ -123,17 +123,17 @@ describe('table registry', () => { ...@@ -123,17 +123,17 @@ describe('table registry', () => {
it('should delete multiple items when multiple items are selected', done => { it('should delete multiple items when multiple items are selected', done => {
const multiDeleteItems = jest.fn().mockResolvedValue(); const multiDeleteItems = jest.fn().mockResolvedValue();
wrapper.setMethods({ multiDeleteItems }); wrapper.setMethods({ multiDeleteItems });
const selectAll = findSelectAllCheckbox();
selectAll.trigger('click');
Vue.nextTick(() => { Vue.nextTick(() => {
const deleteBtn = findDeleteButton(); const selectAll = findSelectAllCheckbox();
expect(wrapper.vm.selectedItems).toEqual([0, 1]); selectAll.trigger('click');
expect(deleteBtn.attributes('disabled')).toEqual(undefined);
wrapper.setData({ itemsToBeDeleted: [...wrapper.vm.selectedItems] });
wrapper.vm.handleMultipleDelete();
Vue.nextTick(() => { Vue.nextTick(() => {
const deleteBtn = findDeleteButton();
expect(wrapper.vm.selectedItems).toEqual([0, 1]);
expect(deleteBtn.attributes('disabled')).toEqual(undefined);
wrapper.setData({ itemsToBeDeleted: [...wrapper.vm.selectedItems] });
wrapper.vm.handleMultipleDelete();
expect(wrapper.vm.selectedItems).toEqual([]); expect(wrapper.vm.selectedItems).toEqual([]);
expect(wrapper.vm.itemsToBeDeleted).toEqual([]); expect(wrapper.vm.itemsToBeDeleted).toEqual([]);
expect(wrapper.vm.multiDeleteItems).toHaveBeenCalledWith({ expect(wrapper.vm.multiDeleteItems).toHaveBeenCalledWith({
...@@ -179,10 +179,12 @@ describe('table registry', () => { ...@@ -179,10 +179,12 @@ describe('table registry', () => {
const deleteSingleItem = jest.fn(); const deleteSingleItem = jest.fn();
const deleteItem = jest.fn().mockResolvedValue(); const deleteItem = jest.fn().mockResolvedValue();
wrapper.setMethods({ deleteSingleItem, deleteItem }); wrapper.setMethods({ deleteSingleItem, deleteItem });
deleteBtns.at(0).trigger('click'); return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.deleteSingleItem).toHaveBeenCalledWith(0); deleteBtns.at(0).trigger('click');
wrapper.vm.handleSingleDelete(1); expect(wrapper.vm.deleteSingleItem).toHaveBeenCalledWith(0);
expect(wrapper.vm.deleteItem).toHaveBeenCalledWith(1); wrapper.vm.handleSingleDelete(1);
expect(wrapper.vm.deleteItem).toHaveBeenCalledWith(1);
});
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment