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,6 +123,8 @@ describe('table registry', () => { ...@@ -123,6 +123,8 @@ 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 });
Vue.nextTick(() => {
const selectAll = findSelectAllCheckbox(); const selectAll = findSelectAllCheckbox();
selectAll.trigger('click'); selectAll.trigger('click');
...@@ -132,8 +134,6 @@ describe('table registry', () => { ...@@ -132,8 +134,6 @@ describe('table registry', () => {
expect(deleteBtn.attributes('disabled')).toEqual(undefined); expect(deleteBtn.attributes('disabled')).toEqual(undefined);
wrapper.setData({ itemsToBeDeleted: [...wrapper.vm.selectedItems] }); wrapper.setData({ itemsToBeDeleted: [...wrapper.vm.selectedItems] });
wrapper.vm.handleMultipleDelete(); wrapper.vm.handleMultipleDelete();
Vue.nextTick(() => {
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,12 +179,14 @@ describe('table registry', () => { ...@@ -179,12 +179,14 @@ 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 });
return wrapper.vm.$nextTick().then(() => {
deleteBtns.at(0).trigger('click'); deleteBtns.at(0).trigger('click');
expect(wrapper.vm.deleteSingleItem).toHaveBeenCalledWith(0); expect(wrapper.vm.deleteSingleItem).toHaveBeenCalledWith(0);
wrapper.vm.handleSingleDelete(1); wrapper.vm.handleSingleDelete(1);
expect(wrapper.vm.deleteItem).toHaveBeenCalledWith(1); expect(wrapper.vm.deleteItem).toHaveBeenCalledWith(1);
}); });
}); });
});
describe('modal event handlers', () => { describe('modal event handlers', () => {
beforeEach(() => { beforeEach(() => {
......
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