How to use the @testing-library/react.fireEvent.blur function in @testing-library/react

To help you get started, we’ve selected a few @testing-library/react examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / @testing-library / react_v8.x.x / flow_v0.104.x- / test_react_v8.x.x.js View on Github external
it('should expose fire event helpers', () => {
    fireEvent.copy(htmlEl);
    fireEvent.cut(htmlEl);
    fireEvent.paste(htmlEl);
    fireEvent.compositionEnd(htmlEl);
    fireEvent.compositionStart(htmlEl);
    fireEvent.compositionUpdate(htmlEl);
    fireEvent.keyDown(htmlEl);
    fireEvent.keyPress(htmlEl);
    fireEvent.keyUp(htmlEl);
    fireEvent.focus(htmlEl);
    fireEvent.blur(htmlEl);
    fireEvent.change(htmlEl);
    fireEvent.input(htmlEl);
    fireEvent.invalid(htmlEl);
    fireEvent.submit(htmlEl);
    fireEvent.click(htmlEl);
    fireEvent.contextMenu(htmlEl);
    fireEvent.dblClick(htmlEl);
    fireEvent.doubleClick(htmlEl);
    fireEvent.drag(htmlEl);
    fireEvent.dragEnd(htmlEl);
    fireEvent.dragEnter(htmlEl);
    fireEvent.dragExit(htmlEl);
    fireEvent.dragLeave(htmlEl);
    fireEvent.dragOver(htmlEl);
    fireEvent.dragStart(htmlEl);
    fireEvent.drop(htmlEl);
github downshift-js / downshift / src / __tests__ / downshift.get-input-props.js View on Github external
    blurOnInput: extraEventProps => fireEvent.blur(input, extraEventProps),
  }
github ifiokjr / remirror / @remirror / react / src / components / __tests__ / remirror.spec.tsx View on Github external
const mock = jest.fn((value: InjectedRemirrorProps) => {
      setContent = value.setContent;
      return <div>;
    });
    const { getByLabelText } = render(
      
        {mock}
      ,
    );

    setContent(`<p>${textContent}</p>`, true);
    const editorNode = getByLabelText(label);
    expect(handlers.onChange).toHaveBeenCalledTimes(1);
    expect(handlers.onFirstRender.mock.calls[0][0].getText()).toBe(textContent);

    fireEvent.blur(editorNode);
    expect(handlers.onBlur).toHaveBeenCalledTimes(1);

    fireEvent.focus(editorNode);
    expect(handlers.onFocus).toHaveBeenCalledTimes(1);
  });
</div>
github pluralsight / design-system / packages / datepicker / src / react / __specs__ / index.spec.js View on Github external
it('should call onBlur when onBlur is called for a valid date', () =&gt; {
      const onBlurMock = jest.fn()
      const { getByDisplayValue } = render(
        
      )
      fireEvent.blur(getByDisplayValue('2001'))
      expect(onBlurMock).toHaveBeenCalledTimes(1)
      expect(onBlurMock).toHaveBeenCalledWith('8/14/2001')
    })
github zendeskgarden / react-containers / packages / selection / src / SelectionContainer.spec.tsx View on Github external
it('clears currently focused item', () =&gt; {
        const { getAllByTestId } = render();
        const [item] = getAllByTestId('item');

        fireEvent.focus(item);
        expect(item).toHaveAttribute('data-focused', 'true');

        fireEvent.blur(item);
        expect(item).toHaveAttribute('data-focused', 'false');
      });
    });
github marmelab / react-admin / packages / ra-ui-materialui / src / input / AutocompleteInput / AutocompleteInput.spec.js View on Github external
)}
                /&gt;
            );
            const input = getByLabelText('resources.users.fields.role');
            fireEvent.focus(input);
            fireEvent.change(input, { target: { value: 'a' } });
            expect(queryAllByRole('option').length).toEqual(2);
            fireEvent.blur(input);

            fireEvent.focus(input);
            fireEvent.change(input, { target: { value: 'a' } });
            expect(queryAllByRole('option').length).toEqual(2);
        });
    });
github short-d / short / frontend / src / component / ui / SearchBar.spec.tsx View on Github external
{
            longLink: 'https://github.com/short-d/short/',
            alias: 'short'
          }
        ]}
      />
    );

    const input = getByPlaceholderText(
      'Search short links'
    ) as HTMLInputElement;

    expect(container.querySelector('.suggestions.show')).toBeFalsy();
    fireEvent.focus(input);
    expect(container.querySelector('.suggestions.show')).toBeTruthy();
    fireEvent.blur(input);

    jest.advanceTimersByTime(TOTAL_DURATION);

    expect(container.querySelector('.suggestions.show')).toBeFalsy();
  });
});
github marmelab / react-admin / packages / ra-ui-materialui / src / input / CheckboxGroupInput.spec.tsx View on Github external
<form> (
                        
                    )}
                /&gt;
            );
            const input = queryByLabelText('Angular');
            fireEvent.click(input);
            expect(input.checked).toBe(true);

            fireEvent.blur(input);
            expect(queryByText('ra.validation.error')).not.toBeNull();
        });
    });</form>
github marmelab / react-admin / packages / ra-ui-materialui / src / input / SelectInput.spec.tsx View on Github external
allowEmpty
                            emptyText="Empty"
                            validate={required()}
                        />
                    )}
                />
            );
            const input = getByLabelText('resources.posts.fields.language *');

            const select = getByRole('button');
            fireEvent.click(select);

            const optionAngular = getByText('Angular');
            fireEvent.click(optionAngular);
            fireEvent.blur(input);
            fireEvent.blur(select);

            const optionEmpty = getByText('Empty');
            fireEvent.click(optionEmpty);
            fireEvent.blur(input);
            fireEvent.blur(select);

            const error = getByText('ra.validation.required');
            expect(error).not.toBeNull();
        });
    });
github react-dropzone / react-dropzone / src / index.spec.js View on Github external
)

      const { container } = render(ui)

      const dropzone = container.querySelector('div')

      fireEvent.click(dropzone)
      expect(rootProps.onClick).toHaveBeenCalled()

      fireEvent.focus(dropzone)
      fireEvent.keyDown(dropzone)
      expect(rootProps.onFocus).toHaveBeenCalled()
      expect(rootProps.onKeyDown).toHaveBeenCalled()

      fireEvent.blur(dropzone)
      expect(rootProps.onBlur).toHaveBeenCalled()

      fireEvent.dragEnter(dropzone, event)
      expect(rootProps.onDragEnter).toHaveBeenCalled()

      fireEvent.dragOver(dropzone, event)
      expect(rootProps.onDragOver).toHaveBeenCalled()

      fireEvent.dragLeave(dropzone, event)
      expect(rootProps.onDragLeave).toHaveBeenCalled()

      fireEvent.drop(dropzone, event)
      expect(rootProps.onDrop).toHaveBeenCalled()
    })