vue-test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }
  16. // test property reification
  17. $refs: {
  18. vue: Vue,
  19. element: HTMLInputElement,
  20. vues: Vue[],
  21. elements: HTMLInputElement[]
  22. }
  23. testReification() {
  24. this.$refs.vue.$data;
  25. this.$refs.element.value;
  26. this.$refs.vues[0].$data;
  27. this.$refs.elements[0].value;
  28. }
  29. testMethods() {
  30. this.$mount("#app", false);
  31. this.$forceUpdate();
  32. this.$destroy();
  33. this.$set({}, "key", "value");
  34. this.$delete({}, "key");
  35. this.$watch("a", (val: number, oldVal: number) => {}, {
  36. immediate: true,
  37. deep: false
  38. })();
  39. this.$watch(() => this.a, (val: number) => {});
  40. this.$on("", () => {});
  41. this.$once("", () => {});
  42. this.$off("", () => {});
  43. this.$emit("", 1, 2, 3);
  44. this.$nextTick(function() {
  45. this.$nextTick;
  46. });
  47. this.$nextTick().then(() => {});
  48. this.$createElement("div", {}, "message");
  49. }
  50. static testConfig() {
  51. const { config } = this;
  52. config.silent;
  53. config.optionMergeStrategies;
  54. config.devtools;
  55. config.errorHandler = (err, vm) => {
  56. if (vm instanceof Test) {
  57. vm.testProperties();
  58. vm.testMethods();
  59. }
  60. };
  61. config.keyCodes = { esc: 27 };
  62. }
  63. static testMethods() {
  64. this.extend({
  65. data() {
  66. return {
  67. msg: ""
  68. };
  69. }
  70. });
  71. this.nextTick(() => {});
  72. this.nextTick().then(() => {});
  73. this.set({}, "", "");
  74. this.set([true, false, true], 1, true);
  75. this.delete({}, "");
  76. this.delete([true, false], 0);
  77. this.directive("", {bind() {}});
  78. this.filter("", (value: number) => value);
  79. this.component("", { data: () => ({}) });
  80. this.component("", { functional: true });
  81. this.use;
  82. this.mixin(Test);
  83. this.compile("<div>{{ message }}</div>");
  84. }
  85. }