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': 'bob', 'bar': 'alice'})

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

describe('onChange()', () => {
  it('delete foo inside store', () => {
    useErrorMount.onChange('event')
    expect(store.state.form.violations).toStrictEqual({'bar': 'alice'})
  })

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