You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

  1. import { shallowMount } from '@vue/test-utils'
  2. import Vue from 'vue'
  3. import Vuetify from 'vuetify'
  4. import ProjectCreationForm from '@/components/organisms/ProjectCreationForm'
  5. Vue.use(Vuetify)
  6. describe('ProjectCreationForm', () => {
  7. const factory = (propsData) => {
  8. return shallowMount(ProjectCreationForm, {
  9. propsData: {
  10. ...propsData
  11. }
  12. })
  13. }
  14. const createProject = () => { }
  15. const projectTypes = []
  16. test('can receive props', () => {
  17. const wrapper = factory({ createProject, projectTypes })
  18. expect(wrapper.props()).toEqual({ createProject, projectTypes })
  19. })
  20. test('emit close event', () => {
  21. const wrapper = factory({ createProject, projectTypes })
  22. wrapper.vm.cancel()
  23. expect(wrapper.emitted('close')).toBeTruthy()
  24. })
  25. test('emit close event when form is valid', () => {
  26. const wrapper = factory({ createProject, projectTypes })
  27. wrapper.setMethods({
  28. validate: jest.fn(() => true),
  29. reset: jest.fn()
  30. })
  31. wrapper.vm.create()
  32. expect(wrapper.emitted('close')).toBeTruthy()
  33. })
  34. test('do not emit close event when form is invalid', () => {
  35. const wrapper = factory({ createProject, projectTypes })
  36. wrapper.setMethods({
  37. validate: jest.fn(() => false),
  38. reset: jest.fn()
  39. })
  40. wrapper.vm.create()
  41. expect(wrapper.emitted('close')).toBeFalsy()
  42. })
  43. test('raise warning when passing no props', () => {
  44. const spy = jest.spyOn(console, 'error')
  45. spy.mockImplementation()
  46. expect(spy).toBeCalledWith(
  47. expect.stringContaining('[Vue warn]: Missing required prop')
  48. )
  49. spy.mockRestore()
  50. })
  51. })