Skip to content

Commit

Permalink
feat: Add env to turn off fireEvent.update warning (#181)
Browse files Browse the repository at this point in the history
* add env to turn off warning: `VTL_SKIP_WARN_EVENT_UPDATE`
  • Loading branch information
JeromeDeLeon committed Nov 22, 2020
1 parent 8ddeac6 commit 4376e64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/__tests__/fire-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_SKIP_WARN_EVENT_UPDATE = 'true'
const {getByTestId} = render({
template: `<input type="text" data-testid=test-input></input>`,
})

await fireEvent.input(getByTestId('test-input'), {target: {value: 'hello'}})
await fireEvent.change(getByTestId('test-input'), {target: {value: 'hello'}})

expect(console.warn).not.toHaveBeenCalled()
})
5 changes: 4 additions & 1 deletion src/vue-testing-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ const changeOrInputEventCalledDirectly = (eventValue, eventKey) =>

Object.keys(dtlFireEvent).forEach(key => {
fireEvent[key] = async (...args) => {
if (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.`,
)
Expand Down

0 comments on commit 4376e64

Please sign in to comment.