methods.spec.js 729 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import Vue from 'vue'
  2. describe('Options methods', () => {
  3. it('should have correct context', () => {
  4. const vm = new Vue({
  5. data: {
  6. a: 1
  7. },
  8. methods: {
  9. plus () {
  10. this.a++
  11. }
  12. }
  13. })
  14. vm.plus()
  15. expect(vm.a).toBe(2)
  16. })
  17. it('should warn undefined methods', () => {
  18. new Vue({
  19. methods: {
  20. hello: undefined
  21. }
  22. })
  23. expect(`method "hello" has an undefined value in the component definition`).toHaveBeenWarned()
  24. })
  25. it('should warn overriding builtin methods', () => {
  26. new Vue({
  27. methods: {
  28. $emit () {
  29. }
  30. }
  31. })
  32. expect(`Avoid overriding Vue's internal method "$emit".`).toHaveBeenWarned()
  33. })
  34. })