jest
  .dontMock('../services/component-cache')

componentCache = require('../services/component-cache')

element = {}

describe 'componentCache', ->

  beforeEach ->
    componentCache.clear()

  it 'returns nothing if instances have not been saved', ->
    expect(componentCache.get(element)).toEqual(undefined)

  it 'fetches instances that have already been saved', ->
    constructor = jest.genMockFn()

    componentCache.set(element, constructor)
    instance = constructor.mock.instances[0]

    expect(componentCache.get(element)).toEqual(instance)
    expect(componentCache.get(element)).toEqual(componentCache.get(element))

  it 'returns the instances when cache is set', ->
    constructor = jest.genMockFn()

    expect(
      componentCache.set(element, constructor)
    ).toEqual(
      constructor.mock.instances[0]
    )
