From 6b5151a5ea4e293d7544ef75c379a6f4d7f260b3 Mon Sep 17 00:00:00 2001 From: Jefry Dewangga Date: Wed, 12 Feb 2020 01:55:02 +0700 Subject: [PATCH] feat: mirror all pre tag events (#58) Fix #24 --- src/components/Editor.vue | 1 + tests/unit/Editor.spec.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/components/Editor.vue b/src/components/Editor.vue index 2289ff6..8874514 100644 --- a/src/components/Editor.vue +++ b/src/components/Editor.vue @@ -34,6 +34,7 @@ autocomplete="off" autocorrect="off" data-gramm="false" + v-on="$listeners" > diff --git a/tests/unit/Editor.spec.js b/tests/unit/Editor.spec.js index cad9010..25fdb8e 100644 --- a/tests/unit/Editor.spec.js +++ b/tests/unit/Editor.spec.js @@ -102,6 +102,31 @@ describe("Editor.vue", () => { expect(mockHandler).toHaveBeenCalled(); }); + it("emits all pre events", () => { + const mockHandler = jest.fn(); + const compiled = compileToFunctions( + '
' + ); + const wrapper = mount(compiled, { + data: () => ({ + code: "test" + }), + stubs: { + Editor + }, + methods: { + eventHandler: mockHandler + } + }); + const $pre = wrapper.find("pre"); + + $pre.element.dispatchEvent(new Event("focus")); + $pre.element.dispatchEvent(new Event("blur")); + $pre.element.dispatchEvent(new Event("input")); + + expect(mockHandler).toHaveBeenCalledTimes(3); + }); + it("renders with null value", () => { const code = null; const wrapper = mount(Editor, {