<commit_before>import { usePropsValue } from '../use-props-value'
import { renderHook, act } from 'testing'

describe('usePropsValue', () => {
  test('onChange should not call when next value not change in uncontrolled mode', () => {
    const onChange = jest.fn()
    const { result } = renderHook(() =>
      usePropsValue({
        value: undefined,
        defaultValue: '',
        onChange,
      })
    )

    act(() => result.current[1]('1'))
    expect(onChange).toBeCalledTimes(1)
    act(() => result.current[1]('1'))
    expect(onChange).toBeCalledTimes(1)
  })

  test('onChange should not call when next value not change in controlled mode', () => {
    const onChange = jest.fn()
    const { result } = renderHook(usePropsValue, {
      initialProps: { value: '1', defaultValue: '', onChange },
    })
    act(() => result.current[1]('1'))
    expect(onChange).toBeCalledTimes(0)
  })

  test('onChange should call when `forceTrigger` is true', () => {
    const onChange = jest.fn()
    const { result } = renderHook(usePropsValue, {
      initialProps: { value: '1', defaultValue: '', onChange },
    })
    act(() => result.current[1]('1', true))
    expect(onChange).toBeCalledTimes(1)
  })
})<commit_msg>test: update test about `usePropsValue`<commit_after>import { usePropsValue } from '../use-props-value'
import { renderHook, act } from 'testing'

describe('usePropsValue', () => {
  test('onChange should not call when next value not change in uncontrolled mode', () => {
    const onChange = jest.fn()
    const { result } = renderHook(() =>
      usePropsValue({
        value: undefined,
        defaultValue: '',
        onChange,
      })
    )

    const setState = result.current[1]
    act(() => setState('1'))
    expect(onChange).toBeCalledTimes(1)
    act(() => setState('1'))
    expect(onChange).toBeCalledTimes(1)
  })

  test('onChange should not call when next value not change in controlled mode', () => {
    const onChange = jest.fn()
    const { result } = renderHook(usePropsValue, {
      initialProps: { value: '1', defaultValue: '', onChange },
    })
    const setState = result.current[1]
    act(() => setState('1'))
    expect(onChange).toBeCalledTimes(0)
  })

  test('onChange should call when `forceTrigger` is true', () => {
    const onChange = jest.fn()
    const { result } = renderHook(usePropsValue, {
      initialProps: { value: '1', defaultValue: '', onChange },
    })
    const setState = result.current[1]
    act(() => setState('1', true))
    expect(onChange).toBeCalledTimes(1)
  })

  test('inner value should always be the same with outer value', () => {
    const { result, rerender } = renderHook(usePropsValue, {
      initialProps: { value: '0', defaultValue: '' },
    })
    for (let i = 0; i < 3; i++) {
      rerender({
        value: i.toString(),
        defaultValue: '',
      })
      expect(result.current[0]).toBe(i.toString())
    }
  })
})
{'fraction_non_alphanumeric': 0.16530054644808742, 'fraction_numerical': 0.01058743169398907, 'mean_word_length': 3.1311706629055007, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7377824', 'n_tokens_mistral': 888, 'n_tokens_neox': 890, 'n_words': 217}