vue-test.ts 1.9 KB

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