Skip to content

Commit

Permalink
Fixed test typings
Browse files Browse the repository at this point in the history
  • Loading branch information
nandi95 authored and lmiller1990 committed Feb 12, 2021
1 parent 7c8caf7 commit fec4b46
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/createDomEvent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-expect-error No DefinitelyTyped package exists
// @ts-ignore No DefinitelyTyped package exists
import eventTypes from 'dom-event-types'

interface TriggerOptions {
Expand Down
6 changes: 3 additions & 3 deletions src/vueWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ export class VueWrapper<T extends ComponentPublicInstance> {
classes(): string[]
classes(className: string): boolean
classes(className?: string): string[] | boolean {
return new DOMWrapper(this.element).classes(className)
return new DOMWrapper(this.element).classes(className!)
}

attributes(): { [key: string]: string }
attributes(key: string): string
attributes(key?: string): { [key: string]: string } | string {
return new DOMWrapper(this.element).attributes(key)
return new DOMWrapper(this.element).attributes(key!)
}

exists() {
return true
}

emitted<T = unknown>(): undefined | Record<string, T[]>
emitted<T = unknown>(): Record<string, T[]>
emitted<T = unknown>(eventName?: string): undefined | T[]
emitted<T = unknown>(
eventName?: string
Expand Down
10 changes: 5 additions & 5 deletions tests/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h, inject } from 'vue'
import { ComponentPublicInstance, h, inject } from 'vue'
import { config, mount } from '../src'
import Hello from './components/Hello.vue'

Expand Down Expand Up @@ -114,7 +114,7 @@ describe('config', () => {
describe('provide', () => {
const Comp = {
setup() {
const theme = inject('theme')
const theme = inject<string>('theme')
return () => h('div', theme)
}
}
Expand Down Expand Up @@ -163,14 +163,14 @@ describe('config', () => {
expect(createdHook).toHaveBeenCalledTimes(2)
})

it('concats with locally defined mixins', () => {
it('concat with locally defined mixins', () => {
config.global.mixins = [mixin]
const localHook = jest.fn()
const localMixin = {
created() {
localHook(this.$options.name)
localHook(this.$options!.name)
}
}
} as Partial<ComponentPublicInstance>

mount(Component, {
global: {
Expand Down
12 changes: 6 additions & 6 deletions tests/emit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('emitted', () => {
name: 'Parent',
setup(props, { emit }) {
return () =>
h(Child, { onHello: (...events) => emit('parent', ...events) })
h(Child, { onHello: (...events: any[]) => emit('parent', ...events) })
}
})
const wrapper = mount(Parent)
Expand Down Expand Up @@ -130,10 +130,10 @@ describe('emitted', () => {
expect(wrapper.emitted('hello')).toEqual(undefined)

wrapper.find('button').trigger('click')
expect(wrapper.emitted('hello')[0]).toEqual(['foo', 'bar'])
expect((wrapper.emitted('hello') as unknown[])[0]).toEqual(['foo', 'bar'])

wrapper.find('button').trigger('click')
expect(wrapper.emitted('hello')[1]).toEqual(['foo', 'bar'])
expect((wrapper.emitted('hello') as unknown[])[1]).toEqual(['foo', 'bar'])

expect(wrapper.emitted('hello')).toHaveLength(2)
})
Expand All @@ -157,7 +157,7 @@ describe('emitted', () => {

wrapper.find('h1').trigger('click')
expect(wrapper.emitted('hello')).toHaveLength(1)
expect(wrapper.emitted('hello')[0]).toEqual(['foo', 'bar'])
expect((wrapper.emitted('hello') as unknown[])[0]).toEqual(['foo', 'bar'])
})

it('captures events emitted by class-style components', () => {
Expand All @@ -175,12 +175,12 @@ describe('emitted', () => {

wrapper.find('h1').trigger('click')
expect(wrapper.emitted('hello')).toHaveLength(1)
expect(wrapper.emitted('hello')[0]).toEqual(['foo', 'bar'])
expect((wrapper.emitted('hello') as unknown[])[0]).toEqual(['foo', 'bar'])
})

it('captures an event emitted in setup', () => {
const Comp = {
setup(_, { emit }) {
setup(_: Record<string, any>, { emit }: { emit: SetupContext['emit'] }) {
emit('foo')
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/features/async-components.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { defineAsyncComponent, defineComponent, h, AppConfig } from 'vue'

import { mount, flushPromises } from '../../src'
import { ComponentPublicInstance } from '@vue/runtime-core'

const config: AppConfig = {
optionMergeStrategies: {},
globalProperties: {},
isCustomElement: (tag: string) => false,
performance: false,
errorHandler: (error: Error) => {
if (error.message.match(/Async component failed to load./)) {
errorHandler: (error: unknown) => {
if ((error as Error).message.match(/Async component failed to load./)) {
return
}
throw error
}
}

Expand Down
7 changes: 4 additions & 3 deletions tests/functionalComponents.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from '../src'
import { h } from 'vue'
import { h, Slots } from 'vue'
import Hello from './components/Hello.vue'

describe('functionalComponents', () => {
Expand All @@ -17,7 +17,8 @@ describe('functionalComponents', () => {
})

it('renders the slots of a functional component', () => {
const Foo = (props, { slots }) => h('div', { class: 'foo' }, slots)
const Foo = (props: Record<string, any>, { slots }: { slots: Slots }) =>
h('div', { class: 'foo' }, slots)

const wrapper = mount(Foo, {
slots: {
Expand All @@ -29,7 +30,7 @@ describe('functionalComponents', () => {
})

it('asserts classes', () => {
const Foo = (props, { slots }) => h('div', { class: 'foo' }, slots)
const Foo = () => h('div', { class: 'foo' })

const wrapper = mount(Foo, {
attrs: {
Expand Down
2 changes: 2 additions & 0 deletions tests/isVisible.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ describe('isVisible', () => {
`,
methods: {
add() {
// @ts-expect-error
this.items.push(2)
},
remove() {
// @ts-expect-error
this.items.splice(1) // back to [1]
}
},
Expand Down
2 changes: 1 addition & 1 deletion tests/lifecycle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('lifecycles', () => {
expect(onUnmountFn).not.toHaveBeenCalled()

const removeChildSpy = jest.spyOn(
wrapper.element.parentElement,
wrapper.element.parentElement!,
'removeChild'
)

Expand Down
4 changes: 2 additions & 2 deletions tests/mountingOptions/attachTo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('options.attachTo', () => {
})

const root = document.getElementById('root')
const rendered = document.getElementById('attach-to')
const rendered = document.getElementById('attach-to')!
expect(wrapper.vm.$el.parentNode).not.toBeNull()
expect(root).not.toBeNull()
expect(rendered).not.toBeNull()
Expand All @@ -36,7 +36,7 @@ describe('options.attachTo', () => {
})

const root = document.getElementById('root')
const rendered = document.getElementById('attach-to')
const rendered = document.getElementById('attach-to')!
expect(wrapper.vm.$el.parentNode).not.toBeNull()
expect(root).not.toBeNull()
expect(rendered).not.toBeNull()
Expand Down
3 changes: 2 additions & 1 deletion tests/mountingOptions/data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe('mounting options: data', () => {
bar: 'bar'
}
},
render() {
render(): Function {
// @ts-expect-error
return h('div', `Foo is ${this.foo} bar is ${this.bar}`)
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/mountingOptions/global.plugins.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('mounting options: plugins', () => {
const installed = jest.fn()

class Plugin {
static install(_app: App, ...options) {
static install(_app: App, ...options: any[]) {
installed(...options)
}
}
Expand Down Expand Up @@ -62,7 +62,7 @@ test('installs plugins with and without options', () => {

const installedWithOptions = jest.fn()
class PluginWithOptions {
static install(_app: App, ...args) {
static install(_app: App, ...args: any[]) {
installedWithOptions(...args)
}
}
Expand Down
7 changes: 5 additions & 2 deletions tests/mountingOptions/mocks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ describe('mocks', () => {
</div>
`,
computed: {
url() {
url(): string {
// @ts-expect-error
return `/posts/${this.$route.params.id}`
},
id() {
id(): number {
// @ts-expect-error
return this.$route.params.id
}
},
methods: {
submit() {
// @ts-expect-error
this.$router.push(`/posts/${this.id}`)
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mountingOptions/slots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('slots', () => {
named: namedString
}
})
expect(wrapper.vm.$slots.default()[0].children).toBe(defaultString)
expect(wrapper.vm.$slots.default!()[0].children).toBe(defaultString)
expect(wrapper.find('.default').text()).toBe(defaultString)
expect(wrapper.find('.named').text()).toBe(namedString)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/mountingOptions/stubs.global.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('mounting options: stubs', () => {
})

it('stubs a functional component by its variable declaration name', () => {
const FunctionalFoo = (props) => h('p', props, 'Foo Text')
const FunctionalFoo = (props: any) => h('p', props, 'Foo Text')

const Component = {
template: '<div><foo/></div>',
Expand Down
1 change: 1 addition & 0 deletions tests/setData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('setData', () => {
myObject: {
immediate: true,
handler() {
// @ts-expect-error
this.watchCounter += 1
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/setProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('setProps', () => {
},
watch: {
foo(val: string) {
// @ts-expect-error
this.bar = val
}
},
Expand Down
5 changes: 3 additions & 2 deletions tests/trigger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent, h, ref } from 'vue'

import { mount } from '../src'
import { keyCodesByKeyName } from '../src/createDomEvent'
import { keyCodesByKeyName, KeyNameArray } from '../src/createDomEvent'

describe('trigger', () => {
describe('on click', () => {
Expand Down Expand Up @@ -233,7 +233,8 @@ describe('trigger', () => {
const wrapper = mount(Component, {})

for (const keyName in keyCodesByKeyName) {
const keyCode = keyCodesByKeyName[keyName]
const keyCode =
keyCodesByKeyName[keyName as keyof typeof keyCodesByKeyName]
wrapper.trigger(`keydown.${keyName}`)

const calls = keydownHandler.mock.calls
Expand Down

0 comments on commit fec4b46

Please sign in to comment.