useForm.spec.ts 997 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { createStore } from '~/tests/unit/Helpers'
  2. import { form } from '~/tests/unit/fixture/state/profile'
  3. import { $useForm, UseForm } from '~/use/form/useForm'
  4. import { AnyStore } from '~/types/interfaces'
  5. let store: AnyStore
  6. beforeAll(() => {
  7. store = createStore()
  8. store.registerModule('form', form)
  9. })
  10. function setup(){
  11. return $useForm()
  12. }
  13. describe('markFormAsDirty()', () => {
  14. it('should call addEventListener one time', async () => {
  15. const spy = jest.spyOn(UseForm.prototype as any, 'addEventListener')
  16. spy.mockImplementation(() => {})
  17. const { markFormAsDirty } = setup()
  18. markFormAsDirty()
  19. expect(spy).toHaveBeenCalled()
  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 { markFormAsNotDirty } = $useForm()
  27. markFormAsNotDirty()
  28. expect(spy).toHaveBeenCalled()
  29. })
  30. })