<commit_before>import React from 'react'
import test from 'ava'
import { mount } from 'enzyme'
import expect from 'expect'

import withSize from '../src/withSize'

test('append withSize after mounting', () => {
  const Container = withSize()('div')
  const wrapper = mount(<Container />)

  expect(wrapper.find('div').props()).toIncludeKey('DOMSize')
})


test('update offsetToRoot when the window is resized', () => {
  const cwrpSpy = expect.createSpy()

  class FatCat extends React.Component {
    componentWillReceiveProps = cwrpSpy
    render = () => <div style={{ width: this.props.width }} />
  }

  const Container = withSize()(FatCat)

  const wrapper = mount(<Container />)

  // invoke in cdm
  expect(cwrpSpy.calls.length).toEqual(1)

  wrapper.setProps({ width: 100 })
  wrapper.setProps({ width: 200 })

  expect(cwrpSpy.calls.length).toEqual(3)

  wrapper.unmount()

  wrapper.setProps({ width: 300 })

  expect(cwrpSpy.calls.length).toEqual(3)
})<commit_msg>Modify withSize test<commit_after>import React from 'react'
import test from 'ava'
import { mount } from 'enzyme'
import expect from 'expect'

import withSize from '../src/withSize'

test('append DOMSize after mounting', () => {
  const Container = withSize()('div')
  const wrapper = mount(<Container />)

  expect(wrapper.find('div').props()).toIncludeKey('DOMSize')
})


test('invoke the cancel function of the provided throttle when unmount', () => {
  const cancelSpy = expect.createSpy()

  /* eslint no-param-reassign:["error", { "props": false }] */
  const fakeThrottle = func => {
    func.cancel = cancelSpy
    return func
  }

  const Container = withSize(fakeThrottle)('div')
  const wrapper = mount(<Container />)

  wrapper.unmount()

  expect(cancelSpy).toHaveBeenCalled()
})
{'fraction_non_alphanumeric': 0.15053763440860216, 'fraction_numerical': 0.006791171477079796, 'mean_word_length': 4.325301204819277, 'pattern_counts': {'":': 1, '<': 8, '<?xml version=': 0, '>': 14, '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': '2604161', 'n_tokens_mistral': 582, 'n_tokens_neox': 554, 'n_words': 139}