<commit_before>import Autocomplete from '@/components/Autocomplete'
import {shallow} from '@vue/test-utils'
import sinon from 'sinon'
import fetchMock from 'jest-fetch-mock'

global.fetch = fetchMock

describe('Search Results - Resource', () => {
  let wrapper
  beforeEach(() => {
    wrapper = shallow(Autocomplete, {
      propsData: {
        source: 'localhost',
        resultsProperty: 'data'
      }
    })
  })

  it('should debounce a resource search', () => {
    wrapper.setData({
      display: 'abc'
    })
    const clock = sinon.useFakeTimers()
    const spy = jest.spyOn(wrapper.vm, 'request')
    wrapper.vm.search()
    expect(spy).toHaveBeenCalledTimes(0)
    clock.tick(500)
    wrapper.update()
    expect(spy).toHaveBeenCalledTimes(1)
  })

  it('should not search without display data', () => {
    const spy = jest.spyOn(wrapper.vm, 'resourceSearch')
    expect(spy).toHaveBeenCalledTimes(0)
  })

  it('should show no results', () => {
    fetch.mockResponse(JSON.stringify({data: []}))
    wrapper.vm.request('localhost').then(() => {
      expect(wrapper.vm.results).toHaveLength(0)
      expect(wrapper.emitted().noResults).toBeTruthy()
      expect(wrapper.find('.autocomplete__no-results')).toBeDefined()
      expect(wrapper.find('.autocomplete__no-results').text()).toEqual('Nothing found.')
    })<commit_msg>handle promise rejection<commit_after>import Autocomplete from '@/components/Autocomplete'
import {shallow} from '@vue/test-utils'
import sinon from 'sinon'
import fetchMock from 'jest-fetch-mock'

global.fetch = fetchMock

describe('Search Results - Resource', () => {
  let wrapper
  beforeEach(() => {
    wrapper = shallow(Autocomplete, {
      propsData: {
        source: 'localhost',
        resultsProperty: 'data'
      }
    })
  })

  it('should debounce a resource search', () => {
    wrapper.setData({
      display: 'abc'
    })
    const clock = sinon.useFakeTimers()
    const spy = jest.spyOn(wrapper.vm, 'request')
    wrapper.vm.search()
    expect(spy).toHaveBeenCalledTimes(0)
    clock.tick(500)
    wrapper.update()
    expect(spy).toHaveBeenCalledTimes(1)
  })

  it('should not search without display data', () => {
    const spy = jest.spyOn(wrapper.vm, 'resourceSearch')
    expect(spy).toHaveBeenCalledTimes(0)
  })

  it('should show no results', () => {
    fetch.mockResponse(JSON.stringify({data: []}))
    wrapper.vm.request('localhost').then(() => {
      expect(wrapper.vm.results).toHaveLength(0)
      expect(wrapper.emitted().noResults).toBeTruthy()
      expect(wrapper.find('.autocomplete__no-results')).toBeDefined()
      expect(wrapper.find('.autocomplete__no-results').text()).toEqual('Nothing found.')
    }).catch(() => {})
{'fraction_non_alphanumeric': 0.1603391079985256, 'fraction_numerical': 0.005160339107998526, 'mean_word_length': 3.6472602739726026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '3516194', 'n_tokens_mistral': 856, 'n_tokens_neox': 841, 'n_words': 149}