From 8d86fc0f628c970b5d8ce26824451c9b4a974200 Mon Sep 17 00:00:00 2001 From: JeromeDeLeon Date: Sun, 22 Nov 2020 20:01:05 +0800 Subject: [PATCH 1/3] add env to turn off warning --- src/__tests__/fire-event.js | 12 ++++++++++++ src/vue-testing-library.js | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/__tests__/fire-event.js b/src/__tests__/fire-event.js index 221ca549..b9dd757b 100644 --- a/src/__tests__/fire-event.js +++ b/src/__tests__/fire-event.js @@ -229,3 +229,15 @@ test('fireEvent.update does not crash if non-input element is passed in', async `) expect(console.warn).not.toHaveBeenCalled() }) + +test('fireEvent change/input should not throw warning when env is set', async () => { + process.env.VTL_WARN_EVENT_UPDATE = 'false' + const {getByTestId} = render({ + template: ``, + }) + + await fireEvent.input(getByTestId('test-input'), { target: { value: 'hello' } }) + await fireEvent.change(getByTestId('test-input'), { target: { value: 'hello' } }) + + expect(console.warn).not.toHaveBeenCalled(); +}); diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index def669ed..d7930c51 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -117,7 +117,7 @@ const changeOrInputEventCalledDirectly = (eventValue, eventKey) => Object.keys(dtlFireEvent).forEach(key => { fireEvent[key] = async (...args) => { - if (changeOrInputEventCalledDirectly(args[1], key)) { + if (process.env.VTL_WARN_EVENT_UPDATE === 'true' && changeOrInputEventCalledDirectly(args[1], key)) { console.warn( `Using "fireEvent.${key} may lead to unexpected results. Please use fireEvent.update() instead.`, ) @@ -188,5 +188,9 @@ if (typeof afterEach === 'function' && !process.env.VTL_SKIP_AUTO_CLEANUP) { }) } +if (!process.env.VTL_WARN_EVENT_UPDATE) { + process.env.VTL_WARN_EVENT_UPDATE = 'true'; +} + export * from '@testing-library/dom' export {cleanup, render, fireEvent} From 7fc7af31272f68191f1184eb27b6137e23b28022 Mon Sep 17 00:00:00 2001 From: JeromeDeLeon Date: Sun, 22 Nov 2020 20:05:06 +0800 Subject: [PATCH 2/3] rename env --- src/__tests__/fire-event.js | 2 +- src/vue-testing-library.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/__tests__/fire-event.js b/src/__tests__/fire-event.js index b9dd757b..d52b5e4d 100644 --- a/src/__tests__/fire-event.js +++ b/src/__tests__/fire-event.js @@ -231,7 +231,7 @@ test('fireEvent.update does not crash if non-input element is passed in', async }) test('fireEvent change/input should not throw warning when env is set', async () => { - process.env.VTL_WARN_EVENT_UPDATE = 'false' + process.env.WARN_EVENT_UPDATE = 'false' const {getByTestId} = render({ template: ``, }) diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index d7930c51..d9099970 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -117,7 +117,7 @@ const changeOrInputEventCalledDirectly = (eventValue, eventKey) => Object.keys(dtlFireEvent).forEach(key => { fireEvent[key] = async (...args) => { - if (process.env.VTL_WARN_EVENT_UPDATE === 'true' && changeOrInputEventCalledDirectly(args[1], key)) { + if (process.env.WARN_EVENT_UPDATE === 'true' && changeOrInputEventCalledDirectly(args[1], key)) { console.warn( `Using "fireEvent.${key} may lead to unexpected results. Please use fireEvent.update() instead.`, ) @@ -188,8 +188,8 @@ if (typeof afterEach === 'function' && !process.env.VTL_SKIP_AUTO_CLEANUP) { }) } -if (!process.env.VTL_WARN_EVENT_UPDATE) { - process.env.VTL_WARN_EVENT_UPDATE = 'true'; +if (!process.env.WARN_EVENT_UPDATE) { + process.env.WARN_EVENT_UPDATE = 'true'; } export * from '@testing-library/dom' From a535fd424d5b765d9da5c93dc9c6372a3f2bef60 Mon Sep 17 00:00:00 2001 From: JeromeDeLeon Date: Sun, 22 Nov 2020 23:18:01 +0800 Subject: [PATCH 3/3] negate env variable --- src/__tests__/fire-event.js | 10 +++++----- src/vue-testing-library.js | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/__tests__/fire-event.js b/src/__tests__/fire-event.js index d52b5e4d..668ca551 100644 --- a/src/__tests__/fire-event.js +++ b/src/__tests__/fire-event.js @@ -231,13 +231,13 @@ test('fireEvent.update does not crash if non-input element is passed in', async }) test('fireEvent change/input should not throw warning when env is set', async () => { - process.env.WARN_EVENT_UPDATE = 'false' + process.env.VTL_SKIP_WARN_EVENT_UPDATE = 'true' const {getByTestId} = render({ template: ``, }) - await fireEvent.input(getByTestId('test-input'), { target: { value: 'hello' } }) - await fireEvent.change(getByTestId('test-input'), { target: { value: 'hello' } }) + await fireEvent.input(getByTestId('test-input'), {target: {value: 'hello'}}) + await fireEvent.change(getByTestId('test-input'), {target: {value: 'hello'}}) - expect(console.warn).not.toHaveBeenCalled(); -}); + expect(console.warn).not.toHaveBeenCalled() +}) diff --git a/src/vue-testing-library.js b/src/vue-testing-library.js index d9099970..89dcdc04 100644 --- a/src/vue-testing-library.js +++ b/src/vue-testing-library.js @@ -117,7 +117,10 @@ const changeOrInputEventCalledDirectly = (eventValue, eventKey) => Object.keys(dtlFireEvent).forEach(key => { fireEvent[key] = async (...args) => { - if (process.env.WARN_EVENT_UPDATE === 'true' && changeOrInputEventCalledDirectly(args[1], key)) { + if ( + changeOrInputEventCalledDirectly(args[1], key) && + !process.env.VTL_SKIP_WARN_EVENT_UPDATE + ) { console.warn( `Using "fireEvent.${key} may lead to unexpected results. Please use fireEvent.update() instead.`, ) @@ -188,9 +191,5 @@ if (typeof afterEach === 'function' && !process.env.VTL_SKIP_AUTO_CLEANUP) { }) } -if (!process.env.WARN_EVENT_UPDATE) { - process.env.WARN_EVENT_UPDATE = 'true'; -} - export * from '@testing-library/dom' export {cleanup, render, fireEvent}