Forms.spec.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Vue from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import CoreuiVue from '@coreui/vue'
  4. import Forms from '@/views/base/Forms'
  5. Vue.use(CoreuiVue)
  6. describe('Forms.vue', () => {
  7. // use mount. So the method applied to child components can be tested
  8. const wrapper = mount(Forms)
  9. it('has a name', () => {
  10. expect(Forms.name).toBe('Forms')
  11. })
  12. it('is Forms', () => {
  13. expect(wrapper.findComponent(Forms)).toBeTruthy()
  14. })
  15. // render random chackboxes
  16. // test('renders correctly', () => {
  17. // const wrapper = shallowMount(Forms)
  18. // expect(wrapper.element).toMatchSnapshot()
  19. // })
  20. // the test action is in Forms.vue, with valid & invalid input
  21. // so just render it, it will executed
  22. it('should execute validator() on mount', (done) => {
  23. expect(wrapper).toBeDefined()
  24. done()
  25. })
  26. // simulate input to make it invalid. This will test <CInput :is-valid="validator" />
  27. it('should not pass validator()', (done) => {
  28. // need to find best selector for the input, this one from rendered HTML
  29. const input = wrapper.findAll('input').at(71)
  30. input.setValue('Hai')
  31. wrapper.vm.$nextTick(() => {
  32. expect(input.classes()).toContain('is-invalid')
  33. // use callback, because its error when using async await
  34. done()
  35. })
  36. })
  37. it('should pass validator()', (done) => {
  38. const input = wrapper.find('div > div:nth-child(3) > div:nth-child(2) > div > div > form > div:nth-child(2) > input')
  39. input.setValue('Hello World')
  40. wrapper.vm.$nextTick(() => {
  41. expect(input.classes()).toContain('is-valid')
  42. done()
  43. })
  44. })
  45. })