Skip to content

Commit 8d86fc0

Browse files
committed
add env to turn off warning
1 parent a5bd6cc commit 8d86fc0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/__tests__/fire-event.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,15 @@ test('fireEvent.update does not crash if non-input element is passed in', async
229229
`)
230230
expect(console.warn).not.toHaveBeenCalled()
231231
})
232+
233+
test('fireEvent change/input should not throw warning when env is set', async () => {
234+
process.env.VTL_WARN_EVENT_UPDATE = 'false'
235+
const {getByTestId} = render({
236+
template: `<input type="text" data-testid=test-input></input>`,
237+
})
238+
239+
await fireEvent.input(getByTestId('test-input'), { target: { value: 'hello' } })
240+
await fireEvent.change(getByTestId('test-input'), { target: { value: 'hello' } })
241+
242+
expect(console.warn).not.toHaveBeenCalled();
243+
});

src/vue-testing-library.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const changeOrInputEventCalledDirectly = (eventValue, eventKey) =>
117117

118118
Object.keys(dtlFireEvent).forEach(key => {
119119
fireEvent[key] = async (...args) => {
120-
if (changeOrInputEventCalledDirectly(args[1], key)) {
120+
if (process.env.VTL_WARN_EVENT_UPDATE === 'true' && changeOrInputEventCalledDirectly(args[1], key)) {
121121
console.warn(
122122
`Using "fireEvent.${key} may lead to unexpected results. Please use fireEvent.update() instead.`,
123123
)
@@ -188,5 +188,9 @@ if (typeof afterEach === 'function' && !process.env.VTL_SKIP_AUTO_CLEANUP) {
188188
})
189189
}
190190

191+
if (!process.env.VTL_WARN_EVENT_UPDATE) {
192+
process.env.VTL_WARN_EVENT_UPDATE = 'true';
193+
}
194+
191195
export * from '@testing-library/dom'
192196
export {cleanup, render, fireEvent}

0 commit comments

Comments
 (0)