methods.spec.js 866 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import Vue from 'vue'
  2. import testObjectOption from '../../../helpers/test-object-option'
  3. describe('Options methods', () => {
  4. it('should have correct context', () => {
  5. const vm = new Vue({
  6. data: {
  7. a: 1
  8. },
  9. methods: {
  10. plus () {
  11. this.a++
  12. }
  13. }
  14. })
  15. vm.plus()
  16. expect(vm.a).toBe(2)
  17. })
  18. testObjectOption('methods')
  19. it('should warn undefined methods', () => {
  20. new Vue({
  21. methods: {
  22. hello: undefined
  23. }
  24. })
  25. expect(`method "hello" has an undefined value 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. })