methods.spec.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import Vue from 'vue'
  2. import testObjectOption from '../../../helpers/test-object-option'
  3. describe('Options methods', () => {
  4. testObjectOption('methods')
  5. it('should have correct context', () => {
  6. const vm = new Vue({
  7. data: {
  8. a: 1
  9. },
  10. methods: {
  11. plus() {
  12. this.a++
  13. }
  14. }
  15. })
  16. vm.plus()
  17. expect(vm.a).toBe(2)
  18. })
  19. it('should warn methods of not function type', () => {
  20. new Vue({
  21. methods: {
  22. hello: {}
  23. }
  24. })
  25. expect(
  26. 'Method "hello" has type "object" in the component definition'
  27. ).toHaveBeenWarned()
  28. })
  29. it('should warn methods conflicting with data', () => {
  30. new Vue({
  31. data: {
  32. foo: 1
  33. },
  34. methods: {
  35. foo() {}
  36. }
  37. })
  38. expect(
  39. `Method "foo" has already been defined as a data property`
  40. ).toHaveBeenWarned()
  41. })
  42. it('should warn methods conflicting with internal methods', () => {
  43. new Vue({
  44. methods: {
  45. _update() {}
  46. }
  47. })
  48. expect(
  49. `Method "_update" conflicts with an existing Vue instance method`
  50. ).toHaveBeenWarned()
  51. })
  52. })