import {useError} from "~/composables/form/useError";
import {createStore} from "~/tests/unit/Helpers";
import {form as formModule} from "~/tests/unit/fixture/state/profile";
import {AnyStore} from "~/types/interfaces";
let store:AnyStore

let useErrorMount:any
const emit = jest.fn()

beforeAll(() => {
  store = createStore()
  store.registerModule('form', formModule)
  store.commit('form/setViolations', ['foo', 'bar'])

  useErrorMount = useError('foo', emit, store)
})

describe('onChange()', () => {
  it('delete foo inside store', () => {
    useErrorMount.onChange('bob')
    expect(store.state.form.violations).toHaveLength(1)
  })

  it('emit is called', () => {
    useErrorMount.onChange('bob')
    expect(emit).toHaveBeenCalled
  })
})
