Skip to content

Commit

Permalink
test: add tests for type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
KaelWD committed May 23, 2018
1 parent 180cbff commit f005828
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ src/util/to-have-been-warned.js
/dist
/es5
/es5-temp
/types/test
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- npm i codecov -g
script:
- yarn run lint
- yarn run test:types
- yarn run test:coverage -i
after_script:
- codecov
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"test:unix": "cross-env NODE_ENV=test jest",
"test:win32": "cross-env NODE_ENV=test jest -i",
"test:coverage": "yarn test --coverage",
"test:types": "tsc -p ./types/test/tsconfig.json",
"lint": "tsc --noEmit --pretty && eslint --ext .js,.ts src",
"preparecommitmsg": "node dev/prepare-commit-message.js",
"commitmsg": "node dev/lint-commit-message.js",
Expand Down
10 changes: 6 additions & 4 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ export interface VuetifyUseOptions {
/** @see https://vuetifyjs.com/style/theme#options */
options?: Partial<VuetifyOptions>
lang?: Partial<Pick<VuetifyLanguage, 'locales' | 'current'>>
rtl?: boolean
}

export interface VuetifyObject extends Vue {
readonly breakpoint: VuetifyBreakpoint
readonly breakpoint: Readonly<VuetifyBreakpoint>
readonly dark: boolean
readonly goTo: <T extends string | number | HTMLElement | Vue>(target: T, options?: VuetifyGoToOptions) => Promise<T>
readonly t: VuetifyLanguage['t']
application: VuetifyApplication
theme: VuetifyTheme | false
theme: VuetifyTheme
icons: VuetifyIcons
lang: VuetifyLanguage
options: VuetifyOptions
goTo: <T extends string | number | HTMLElement | Vue>(target: T, options?: VuetifyGoToOptions) => Promise<T>
t: VuetifyLanguage['t']
rtl: boolean
}

declare module 'vue/types/vue' {
Expand Down
45 changes: 45 additions & 0 deletions types/test/global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Vue from 'vue'

Vue.component('breakpoint', {
created () {
const name: string = this.$vuetify.breakpoint.name
const numbers: number[] = [
this.$vuetify.breakpoint.height,
this.$vuetify.breakpoint.width
]
const booleans: boolean[] = [
this.$vuetify.breakpoint.lg,
this.$vuetify.breakpoint.lgAndDown,
this.$vuetify.breakpoint.lgAndUp,
this.$vuetify.breakpoint.lgOnly,
this.$vuetify.breakpoint.md,
this.$vuetify.breakpoint.mdAndDown,
this.$vuetify.breakpoint.mdAndUp,
this.$vuetify.breakpoint.mdOnly,
this.$vuetify.breakpoint.sm,
this.$vuetify.breakpoint.smAndDown,
this.$vuetify.breakpoint.smAndUp,
this.$vuetify.breakpoint.smOnly,
this.$vuetify.breakpoint.xl,
this.$vuetify.breakpoint.xlOnly,
this.$vuetify.breakpoint.xs,
this.$vuetify.breakpoint.xsOnly
]
}
})

Vue.component('theme', {
created () {
// Can't do this, some components rely on the pre-defined values
// this.$vuetify.theme = { primary: 123 }

Object.assign(this.$vuetify.theme, {
primary: 123
})

this.$vuetify.theme = {
...this.$vuetify.theme,
primary: 132
}
}
})
41 changes: 41 additions & 0 deletions types/test/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Vue from 'vue'
import Vuetify from 'vuetify'

const version: string = Vuetify.version

Vuetify.install(Vue)

Vuetify.install(Vue, {
theme: false
})

Vuetify.install(Vue, {
theme: {
primary: '#123456',
accent: '#123456',
secondary: '#123456',
info: '#123456',
warning: '#123456',
error: '#123456',
success: '#123456',

'something-else': '#123456',
'as-number': 123456
},
iconfont: 'fa',
icons: {
cancel: 'custom icon'
},
rtl: true,
lang: {
locales: {
es: {
noDataText: ''
}
}
},
options: {
themeVariations: ['primary', 'secondary'],
cspNonce: 'asdf123'
}
})
24 changes: 24 additions & 0 deletions types/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"es2015"
],
"module": "commonjs",
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"vuetify": ["../index.d.ts"]
}
},
"files": [
"../index.d.ts",
"../alacarte.d.ts",
"../lang.d.ts",
"plugin.ts",
"global.ts"
],
"compileOnSave": false
}

0 comments on commit f005828

Please sign in to comment.