Tweak Jest setup file

This commit is contained in:
Pig Fang 2019-11-26 11:44:44 +08:00
parent a43e8036c5
commit 383e20acbd
4 changed files with 26 additions and 11 deletions

View File

@ -194,7 +194,7 @@
"\\.(png|jpg)$": "<rootDir>/resources/assets/tests/__mocks__/file.ts"
},
"setupFilesAfterEnv": [
"<rootDir>/resources/assets/tests/setup.js"
"<rootDir>/resources/assets/tests/setup.ts"
],
"coveragePathIgnorePatterns": [
"/node_modules/",

View File

@ -2,10 +2,9 @@ import Vue from 'vue'
export function trans(key: string, parameters = Object.create(null)): string {
const segments = key.split('.')
let temp = (
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
blessing.i18n || Object.create(null)
) as { [k: string]: string | { [k: string]: string } }
let temp = (blessing.i18n) as {
[k: string]: string | { [k: string]: string }
}
let result = ''
for (const segment of segments) {

View File

@ -8,6 +8,9 @@ interface Window {
trans(key: string, parameters: object): string
blessing: {
base_url: string
site_name: string
version: string
i18n: object
extra: object
}

View File

@ -13,25 +13,36 @@ window.blessing = {
site_name: 'Blessing Skin',
version: '4.0.0',
extra: {},
i18n: {},
}
window.Headers = class extends Map {
class Headers extends Map {
constructor(headers = {}) {
// @ts-ignore
super(Object.entries(headers))
}
}
class Request {
public url: string
window.Request = class {
constructor(url, init) {
public headers: Headers
constructor(url: string, init: RequestInit) {
this.url = url
Object.assign(this, init)
this.headers = new Map(Object.entries(init.headers || {}))
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
this.headers = new Headers(Object.entries(init.headers || {}))
}
}
Object.assign(window, { Headers, Request })
const noop = () => undefined
// eslint-disable-next-line no-console
Object.keys(console).forEach(method => (console[method] = noop))
Object.assign(console, {
log: noop,
info: noop,
warn: noop,
error: noop,
})
Vue.prototype.$t = key => key
@ -56,12 +67,14 @@ Vue.use(Button)
Vue.use(Input)
Vue.use(Radio)
Vue.use(Switch)
// @ts-ignore
Vue.prototype.$message = {
info: jest.fn(),
success: jest.fn(),
warning: jest.fn(),
error: jest.fn(),
}
// @ts-ignore
Vue.prototype.$msgbox = jest.fn()
Vue.prototype.$alert = jest.fn()
Vue.prototype.$confirm = jest.fn()