Попытка создания юнит-теста с шуткой. Я попробовал нас ts-jest, у меня было много проблем. Попытка вавилон, становится все ближе. На самом деле получил тест на работу. Но потом я столкнулся с этим.
static cachedVendors = [];
^
SyntaxError: Unexpected token =
Файл выглядит следующим образом
//imports up here somewhere
export default class Vendor {
public static cachedVendors: Vendor[] = [];
...more code
}
jest config
const { defaults: tsjPreset } = require("ts-jest/presets");
module.exports = {
...tsjPreset,
transform: {
"^.+\\.[t|j]s?$": "babel-jest",
".*\\.(vue)$": "vue-jest"
},
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1",
"^common/(.*)$": "<rootDir>/src/common/$1",
"^price/(.*)$": "<rootDir>/src/price/$1",
"^eligibility/(.*)$": "<rootDir>/src/eligibility/$1"
}
};
Я удалил ... tsjPreset и получить ту же ошибку.
Мой babel.config. js
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }], "@babel/preset-typescript"],
plugins: [["@babel/plugin-proposal-export-default-from"]]
};
Как я уже сказал, у меня есть еще один файл, на котором я запускаю тест, который выглядит следующим образом
import Vue from "vue";
import { Component, Prop, Inject, Watch } from "vue-property-decorator";
import moment from "moment";
import * as _ from "lodash";
export const DATE_FORMAT = "MM-DD-YYYY";
@Component({
})
export default class PEMDatePicker extends Vue {
@Prop()
label: string;
@Prop()
value: string;
@Prop()
rules: Array<Function>; //https://vuetifyjs.com/en/components/forms#creating-rules
public componentsLabel = "";
public componentsDate = "";
public showPicker = false;
public componentsDateInput: string = moment().format("MM/DD/YYYY");
public mounted() {
this.componentsLabel = this.label ? this.label : "Date";
this.setDate(this.value);
this.$emit('input', this.value);
}
@Watch("value")
public syncModel() {
if (this.componentsDate != this.value) {
this.setDate(this.value);
}
this.componentsDateInput = this.getDate;
}
@Watch("componentsDate")
public syncDates() {
this.componentsDateInput = this.getDate;
this.$emit('input', this.componentsDate);
}
get getDate() {
return this.componentsDate ? moment(this.componentsDate).format("MM/DD/YYYY") : "";
}
public closePicker() {
this.showPicker = false;
//@ts-ignore
this.$refs.input.focus();
}
public handleEnterKey(event) {
this.setDate(event.target.value);
this.showPicker = false;
}
setDate(dateIn) {
this.componentsDate = dateIn && moment(dateIn).isValid() ? moment(dateIn).format("YYYY-MM-DD") : null;
}
}
Этот тест для этого файла успешно выполнен. Так что это переносит машинопись. Но не по указанному файлу c по какой-то причине. Я в растерянности.