useForm.spec.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import {createStore, initLocalVue, mountComposition} from '~/tests/unit/Helpers'
  2. import { form } from '~/tests/unit/fixture/state/profile'
  3. import { $useForm, UseForm } from '~/composables/form/useForm'
  4. import { AnyStore } from '~/types/interfaces'
  5. let store: AnyStore
  6. beforeAll(() => {
  7. store = createStore()
  8. store.registerModule('form', form)
  9. initLocalVue({store: store})
  10. })
  11. describe('markFormAsDirty()', () => {
  12. it('should call addEventListener one time', async () => {
  13. const spy = jest.spyOn(UseForm.prototype as any, 'addEventListener')
  14. spy.mockImplementation(() => {})
  15. const component = mountComposition(() => {
  16. const {markFormAsDirty} = $useForm();
  17. markFormAsDirty()
  18. expect(spy).toHaveBeenCalled()
  19. });
  20. })
  21. })
  22. describe('markAsNotDirty()', () => {
  23. it('should call clearEventListener one time', async () => {
  24. const spy = jest.spyOn(UseForm.prototype as any, 'clearEventListener')
  25. spy.mockImplementation(() => {})
  26. const component = mountComposition(() => {
  27. const { markFormAsNotDirty } = $useForm()
  28. markFormAsNotDirty()
  29. expect(spy).toHaveBeenCalled()
  30. });
  31. })
  32. })