vue-test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import Vue = require("../index");
  2. class Test extends Vue {
  3. a: number;
  4. testProperties() {
  5. this.$data;
  6. this.$el;
  7. this.$options;
  8. this.$parent;
  9. this.$root;
  10. this.$children;
  11. this.$refs;
  12. this.$slots;
  13. this.$isServer;
  14. this.$ssrContext;
  15. this.$vnode;
  16. }
  17. // test property reification
  18. $refs: {
  19. vue: Vue,
  20. element: HTMLInputElement,
  21. vues: Vue[],
  22. elements: HTMLInputElement[]
  23. }
  24. testReification() {
  25. this.$refs.vue.$data;
  26. this.$refs.element.value;
  27. this.$refs.vues[0].$data;
  28. this.$refs.elements[0].value;
  29. }
  30. testMethods() {
  31. this.$mount("#app", false);
  32. this.$forceUpdate();
  33. this.$destroy();
  34. this.$set({}, "key", "value");
  35. this.$delete({}, "key");
  36. this.$watch("a", (val: number, oldVal: number) => {}, {
  37. immediate: true,
  38. deep: false
  39. })();
  40. this.$watch(() => this.a, (val: number) => {});
  41. this.$on("", () => {});
  42. this.$once("", () => {});
  43. this.$off("", () => {});
  44. this.$emit("", 1, 2, 3);
  45. this.$nextTick(function() {
  46. this.$nextTick;
  47. });
  48. this.$nextTick().then(() => {});
  49. this.$createElement("div", {}, "message");
  50. }
  51. static testConfig() {
  52. const { config } = this;
  53. config.silent;
  54. config.optionMergeStrategies;
  55. config.devtools;
  56. config.errorHandler = (err, vm) => {
  57. if (vm instanceof Test) {
  58. vm.testProperties();
  59. vm.testMethods();
  60. }
  61. };
  62. config.warnHandler = (msg, vm) => {
  63. if (vm instanceof Test) {
  64. vm.testProperties();
  65. vm.testMethods();
  66. }
  67. };
  68. config.keyCodes = { esc: 27 };
  69. }
  70. static testMethods() {
  71. this.extend({
  72. data() {
  73. return {
  74. msg: ""
  75. };
  76. }
  77. });
  78. this.nextTick(() => {});
  79. this.nextTick().then(() => {});
  80. this.set({}, "", "");
  81. this.set([true, false, true], 1, true);
  82. this.delete({}, "");
  83. this.delete([true, false], 0);
  84. this.directive("", {bind() {}});
  85. this.filter("", (value: number) => value);
  86. this.component("", { data: () => ({}) });
  87. this.component("", { functional: true, render () {}});
  88. this.use;
  89. this.mixin(Test);
  90. this.compile("<div>{{ message }}</div>");
  91. }
  92. }