-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deactivate alongside keep-alive
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { GlobalEventsImpl as GlobalEvents } from '../src/GlobalEvents' | ||
import { mount } from '@vue/test-utils' | ||
import { defineComponent, KeepAlive, nextTick } from 'vue' | ||
|
||
const TestWrapper = (name: string, fn: Function) => | ||
defineComponent({ | ||
template: ` | ||
<keep-alive> | ||
<GlobalEvents :${name}="fn" v-if="active" /> | ||
</keep-alive> | ||
`, | ||
|
||
components: { KeepAlive, GlobalEvents }, | ||
data: () => ({ active: true }), | ||
methods: { fn }, | ||
}) | ||
|
||
describe('GlobalEvents with KeepAlive', () => { | ||
test('skips events when deactivated', async () => { | ||
const onKeydown = jest.fn() | ||
const wrapper = mount(TestWrapper('onKeydown', onKeydown)) | ||
|
||
wrapper.vm.active = false | ||
await nextTick() | ||
|
||
document.dispatchEvent(new Event('keydown')) | ||
expect(onKeydown).not.toHaveBeenCalled() | ||
|
||
wrapper.vm.active = true | ||
await nextTick() | ||
|
||
expect(onKeydown).not.toHaveBeenCalled() | ||
document.dispatchEvent(new Event('keydown')) | ||
expect(onKeydown).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters