methods.spec.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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('Method "hello" has type "object" in the component definition').toHaveBeenWarned()
  26. })
  27. it('should warn methods conflicting with data', () => {
  28. new Vue({
  29. data: {
  30. foo: 1
  31. },
  32. methods: {
  33. foo () {}
  34. }
  35. })
  36. expect(`Method "foo" has already been defined as a data property`).toHaveBeenWarned()
  37. })
  38. it('should warn methods conflicting with internal methods', () => {
  39. new Vue({
  40. methods: {
  41. _update () {}
  42. }
  43. })
  44. expect(`Method "_update" conflicts with an existing Vue instance method`).toHaveBeenWarned()
  45. })
  46. })