Skip to content

Commit

Permalink
test: remove global before waitForUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 19, 2022
1 parent 52627b9 commit 63e7d59
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 71 deletions.
42 changes: 21 additions & 21 deletions test/unit/features/component/component-keep-alive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Component keep-alive', () => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [0, 0, 0, 0, 0])
vm.view = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('two')
assertHookCalls(one, [1, 1, 1, 1, 0])
assertHookCalls(two, [1, 1, 1, 0, 0])
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Component keep-alive', () => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [1, 1, 1, 0, 0])
vm.ok = false
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('')
assertHookCalls(one, [1, 1, 1, 1, 0])
assertHookCalls(two, [1, 1, 1, 1, 0])
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Component keep-alive', () => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [1, 1, 1, 0, 0])
vm.ok = false
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('')
assertHookCalls(one, [1, 1, 1, 1, 0])
assertHookCalls(two, [1, 1, 1, 1, 0])
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('Component keep-alive', () => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [0, 0, 0, 0, 0])
vm.view = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('two')
assertHookCalls(one, [1, 1, 1, 1, 0])
assertHookCalls(two, [1, 1, 0, 0, 0])
Expand Down Expand Up @@ -379,7 +379,7 @@ describe('Component keep-alive', () => {
}).$mount()

vm.view = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
assertHookCalls(one, [1, 1, 1, 1, 0])
assertHookCalls(two, [1, 1, 1, 0, 0])
vm.include = 'two'
Expand Down Expand Up @@ -410,7 +410,7 @@ describe('Component keep-alive', () => {
}).$mount()

vm.view = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
assertHookCalls(one, [1, 1, 1, 1, 0])
assertHookCalls(two, [1, 1, 1, 0, 0])
vm.include = 'one'
Expand Down Expand Up @@ -439,7 +439,7 @@ describe('Component keep-alive', () => {
}).$mount()

vm.include = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [0, 0, 0, 0, 0])
vm.view = 'two'
Expand Down Expand Up @@ -468,7 +468,7 @@ describe('Component keep-alive', () => {
assertHookCalls(two, [1, 1, 1, 0, 0])

vm.ok = false
global.waitForUpdate(() => {
waitForUpdate(() => {
assertHookCalls(one, [1, 1, 1, 1, 1])
assertHookCalls(two, [1, 1, 1, 1, 1])
}).then(done)
Expand Down Expand Up @@ -498,7 +498,7 @@ describe('Component keep-alive', () => {

expect(vm.$el.textContent).toBe('one 1')
vm.n++
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('one 2')
vm.view = 'two'
}).then(() => {
Expand Down Expand Up @@ -555,7 +555,7 @@ describe('Component keep-alive', () => {

assertCount([1, 0, 0, 0, 0, 0])
vm.n = 'bb'
global.waitForUpdate(() => {
waitForUpdate(() => {
assertCount([1, 0, 1, 0, 0, 0])
vm.n = 'cc'
}).then(() => {
Expand Down Expand Up @@ -621,7 +621,7 @@ describe('Component keep-alive', () => {

assertCount([1, 0, 0, 0, 0, 0])
vm.n = 'bb'
global.waitForUpdate(() => {
waitForUpdate(() => {
// should prune A because max cache reached
assertCount([1, 1, 1, 0, 0, 0])
vm.n = 'cc'
Expand Down Expand Up @@ -686,7 +686,7 @@ describe('Component keep-alive', () => {
expect(vm.$el.textContent).toBe('foo')
assert(1, 0)
vm.view = false
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('bar')
assert(1, 1)
vm.view = true
Expand Down Expand Up @@ -738,7 +738,7 @@ describe('Component keep-alive', () => {
expect(vm.$el.textContent).toBe('foo')
assert(1, 0)
vm.view = false
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('bar')
assert(1, 1)
vm.view = true
Expand Down Expand Up @@ -773,7 +773,7 @@ describe('Component keep-alive', () => {
}).$mount()
// condition: a render where a previous component is reused
vm.include = ['foo']
global.waitForUpdate(() => {
waitForUpdate(() => {
vm.include = ['']
}).then(() => {
expect(Foo.destroyed).not.toHaveBeenCalled()
Expand Down Expand Up @@ -805,7 +805,7 @@ describe('Component keep-alive', () => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [0, 0, 0, 0, 0])
vm.view = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'<div class="test test-leave test-leave-active">one</div><!---->'
)
Expand Down Expand Up @@ -890,7 +890,7 @@ describe('Component keep-alive', () => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [0, 0, 0, 0, 0])
vm.view = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'<div class="test test-leave test-leave-active">one</div><!---->'
)
Expand Down Expand Up @@ -975,7 +975,7 @@ describe('Component keep-alive', () => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [0, 0, 0, 0, 0])
vm.view = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'<div class="test">one</div>' +
'<div class="test test-enter test-enter-active">two</div>'
Expand Down Expand Up @@ -1066,7 +1066,7 @@ describe('Component keep-alive', () => {
}).$mount(el)
expect(vm.$el.textContent).toBe('one')
vm.view = 'two'
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'<div class="test">one</div>' +
'<div class="test test-enter test-enter-active">two</div>'
Expand Down Expand Up @@ -1134,7 +1134,7 @@ describe('Component keep-alive', () => {
// should not apply transition on initial render by default
expect(vm.$el.innerHTML).toBe('<div class="test">foo</div>')
vm.view = 'bar'
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'<div class="test v-leave v-leave-active">foo</div>' +
'<div class="test test-enter test-enter-active">bar</div>'
Expand Down Expand Up @@ -1210,7 +1210,7 @@ describe('Component keep-alive', () => {
next = () => {
assertHookCalls(one, [1, 1, 1, 0, 0])
assertHookCalls(two, [0, 0, 0, 0, 0])
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(
'<div class="test test-enter test-enter-active">one</div>'
)
Expand Down Expand Up @@ -1274,7 +1274,7 @@ describe('Component keep-alive', () => {
btn.click()
expect(vm.n).toBe(1)
vm.showBtn = false
global.waitForUpdate(() => {
waitForUpdate(() => {
vm.showBtn = true
}).then(() => {
btn.click()
Expand Down
14 changes: 7 additions & 7 deletions test/unit/features/component/component-slot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('Component slot', () => {
}).$mount()
expect(vm.$el.textContent).toBe('12')
vm.a = 2
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('22')
vm.show = false
}).then(() => {
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('Component slot', () => {
}).$mount()
expect(vm.$el.innerHTML).toBe('<div><p>foo</p></div>')
vm.msg = 'bar'
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe('<div><p>bar</p></div>')
}).then(done)
})
Expand All @@ -275,7 +275,7 @@ describe('Component slot', () => {
}).$mount()
expect(vm.$el.innerHTML).toBe('<p>hi</p>')
vm.ok = false
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe('fallback')
vm.ok = true
vm.msg = 'bye'
Expand Down Expand Up @@ -475,7 +475,7 @@ describe('Component slot', () => {
}).$mount()
expect(vm.$el.textContent).toBe('foo1')
vm.$children[0].a = 2
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('foo2')
}).then(done)
})
Expand Down Expand Up @@ -512,7 +512,7 @@ describe('Component slot', () => {

expect(calls).toEqual([1])
vm.$refs.child.ok = false
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(calls).toEqual([1, 2])
vm.$refs.child.ok = true
}).then(() => {
Expand Down Expand Up @@ -550,7 +550,7 @@ describe('Component slot', () => {
}).$mount()
expect(vm.$el.innerHTML).toBe(`<div>1</div> <div>1</div> <pre><div>1</div></pre>`)
vm.n++
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe(`<div>2</div> <div>2</div> <pre><div>2</div></pre>`)
vm.n++
}).then(() => {
Expand Down Expand Up @@ -586,7 +586,7 @@ describe('Component slot', () => {
document.body.appendChild(vm.$el)
expect(vm.$el.textContent).toBe('hi')
vm.$children[0].toggle = false
global.waitForUpdate(() => {
waitForUpdate(() => {
vm.$children[0].toggle = true
}).then(() => {
global.triggerEvent(vm.$el.querySelector('.click'), 'click')
Expand Down
12 changes: 6 additions & 6 deletions test/unit/features/error-handling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Error handling', () => {
].forEach(([type, description]) => {
it(`should recover from promise errors in ${type}`, done => {
createTestInstance(components[`${type}Async`])
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(`Error in ${description} (Promise/async)`).toHaveBeenWarned()
expect(`Error: ${type}`).toHaveBeenWarned()
}).then(done)
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Error handling', () => {
it(`should recover from errors in ${type} hook`, done => {
const vm = createTestInstance(components[type])
vm.ok = false
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(`Error in ${description}`).toHaveBeenWarned()
expect(`Error: ${type}`).toHaveBeenWarned()
}).thenWaitFor(next => {
Expand All @@ -111,7 +111,7 @@ describe('Error handling', () => {
it('should recover from errors in user watcher getter', done => {
const vm = createTestInstance(components.userWatcherGetter)
vm.n++
global.waitForUpdate(() => {
waitForUpdate(() => {
expect(`Error in getter for watcher`).toHaveBeenWarned()
function getErrorMsg () {
try {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('Error handling', () => {
}).$mount()
document.body.appendChild(vm.$el)
global.triggerEvent(vm.$el, 'click')
global.waitForUpdate(() => {
waitForUpdate(() => {
expect('Error in v-on handler (Promise/async)').toHaveBeenWarned()
expect('Error: v-on').toHaveBeenWarned()
document.body.removeChild(vm.$el)
Expand Down Expand Up @@ -435,14 +435,14 @@ function createTestInstance (Comp) {
function assertRootInstanceActive (vm) {
expect(vm.$el.innerHTML).toContain('n:0\n')
vm.n++
return global.waitForUpdate(() => {
return waitForUpdate(() => {
expect(vm.$el.innerHTML).toContain('n:1\n')
})
}

function assertBothInstancesActive (vm) {
vm.n = 0
return global.waitForUpdate(() => {
return waitForUpdate(() => {
expect(vm.$refs.child.$el.innerHTML).toContain('0')
}).thenWaitFor(next => {
assertRootInstanceActive(vm).then(() => {
Expand Down
Loading

0 comments on commit 63e7d59

Please sign in to comment.