How to use @testing-library/preact - 2 common examples

To help you get started, we’ve selected a few @testing-library/preact 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 downshift-js / downshift / other / misc-tests / __tests__ / preact.js View on Github external
test('getInputProps composes onChange with onInput', () => {
  const onChange = jest.fn()
  const onInput = jest.fn()
  const Input = jest.fn(props =&gt; <input>)
  const {ui} = setup({
    children({getInputProps}) {
      return (
        <div>
          <input>
        </div>
      )
    },
  })
  render(ui)
  expect(Input).toHaveBeenCalledTimes(1)
  const [[firstArg]] = Input.mock.calls
  expect(firstArg).toMatchObject({
    onInput: expect.any(Function),
  })
  expect(firstArg.onChange).toBeUndefined()
  const fakeEvent = {defaultPrevented: false, target: {value: ''}}
  firstArg.onInput(fakeEvent)
  expect(onChange).toHaveBeenCalledTimes(1)
  expect(onChange).toHaveBeenCalledWith(fakeEvent)
  expect(onInput).toHaveBeenCalledTimes(1)
  expect(onInput).toHaveBeenCalledWith(fakeEvent)
})
github downshift-js / downshift / other / misc-tests / __tests__ / preact.js View on Github external
test('works with preact', () =&gt; {
  const childrenSpy = jest.fn(({getInputProps, getItemProps}) =&gt; (
    <div>
      <input>
      <div>
        <div>foo</div>
        <div>bar</div>
      </div>
    </div>
  ))
  const ui = {childrenSpy}
  render(ui)
  expect(childrenSpy).toHaveBeenCalledWith(
    expect.objectContaining({
      isOpen: false,
      highlightedIndex: null,
      selectedItem: null,
      inputValue: '',
    }),
  )
})

@testing-library/preact

Simple and complete Preact DOM testing utilities that encourage good testing practices.

MIT
Latest version published 1 year ago

Package Health Score

76 / 100
Full package analysis

Popular @testing-library/preact functions