-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move types from DefinitelyTyped to this repository #165
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d1ab9ff
Add required dependencies
afontcu 6e2ce45
Add types
afontcu 1a2822e
Merge branch 'master' into bring-types
afontcu ad510b2
Update readme
afontcu cc07d23
Bump deps and fix build
afontcu 34594eb
Bump eslint to fix node 15
afontcu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// TypeScript Version: 4.0 | ||
|
||
import Vue, {ComponentOptions} from 'vue' | ||
import {ThisTypedMountOptions, VueClass} from '@vue/test-utils' | ||
import {Store, StoreOptions} from 'vuex' | ||
import Router, {RouteConfig} from 'vue-router' | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import {OptionsReceived as PrettyFormatOptions} from 'pretty-format' | ||
import {queries, EventType, BoundFunctions} from '@testing-library/dom' | ||
|
||
// NOTE: fireEvent is overridden below | ||
export * from '@testing-library/dom' | ||
|
||
export interface RenderResult extends BoundFunctions<typeof queries> { | ||
container: HTMLElement | ||
baseElement: HTMLElement | ||
debug: ( | ||
baseElement?: | ||
| HTMLElement | ||
| DocumentFragment | ||
| Array<HTMLElement | DocumentFragment>, | ||
maxLength?: number, | ||
options?: PrettyFormatOptions, | ||
) => void | ||
unmount(): void | ||
isUnmounted(): boolean | ||
html(): string | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
emitted(): {[name: string]: any[][]} | ||
updateProps(props: object): Promise<void> | ||
} | ||
|
||
export interface RenderOptions<V extends Vue, S = {}> | ||
// The props and store options special-cased by Vue Testing Library and NOT passed to mount(). | ||
extends Omit<ThisTypedMountOptions<V>, 'store' | 'props'> { | ||
props?: object | ||
store?: StoreOptions<S> | ||
routes?: RouteConfig[] | ||
container?: HTMLElement | ||
baseElement?: HTMLElement | ||
} | ||
|
||
export type ConfigurationCallback<V extends Vue> = ( | ||
localVue: typeof Vue, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
store: Store<any>, | ||
router: Router, | ||
) => Partial<ThisTypedMountOptions<V>> | void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line productes the following warning with latest config:
not entirely sure I should be worried about this? |
||
|
||
export function render<V extends Vue>( | ||
TestComponent: VueClass<V> | ComponentOptions<V>, | ||
options?: RenderOptions<V>, | ||
configure?: ConfigurationCallback<V>, | ||
): RenderResult | ||
|
||
export type AsyncFireObject = { | ||
[K in EventType]: ( | ||
element: Document | Element | Window, | ||
options?: {}, | ||
) => Promise<void> | ||
} | ||
|
||
export interface VueFireEventObject extends AsyncFireObject { | ||
(element: Document | Element | Window, event: Event): Promise<void> | ||
touch(element: Document | Element | Window): Promise<void> | ||
update(element: HTMLOptionElement): Promise<void> | ||
update( | ||
element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement, | ||
value: string, | ||
): Promise<void> | ||
update(element: HTMLElement, value?: string): Promise<void> | ||
} | ||
|
||
export const fireEvent: VueFireEventObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import Vue from 'vue' | ||
import {render, fireEvent, screen, waitFor} from '@testing-library/vue' | ||
|
||
declare const elem: HTMLElement | ||
|
||
const SomeComponent = Vue.extend({ | ||
name: 'SomeComponent', | ||
props: { | ||
foo: {type: Number, default: 0}, | ||
bar: {type: String, default: '0'}, | ||
}, | ||
}) | ||
|
||
export async function testRender() { | ||
const page = render({template: '<div />'}) | ||
|
||
// single queries | ||
page.getByText('foo') | ||
page.queryByText('foo') | ||
await page.findByText('foo') | ||
|
||
// multiple queries | ||
page.getAllByText('bar') | ||
page.queryAllByText('bar') | ||
await page.findAllByText('bar') | ||
|
||
// helpers | ||
const {container, unmount, debug} = page | ||
|
||
debug(container) | ||
|
||
debug(elem) // $ExpectType void | ||
debug([elem, elem], 100, {highlight: false}) // $ExpectType void | ||
|
||
unmount() | ||
} | ||
|
||
export function testRenderOptions() { | ||
const container = document.createElement('div') | ||
const options = {container} | ||
render({template: 'div'}, options) | ||
} | ||
|
||
export async function testFireEvent() { | ||
const {container} = render({template: 'button'}) | ||
await fireEvent.click(container) | ||
} | ||
|
||
export function testDebug() { | ||
const {debug, getAllByTestId} = render({ | ||
render(h) { | ||
return h('div', [ | ||
h('h1', {attrs: {'data-testId': 'testid'}}, 'hello world'), | ||
h('h2', {attrs: {'data-testId': 'testid'}}, 'hello world'), | ||
]) | ||
}, | ||
}) | ||
|
||
debug(getAllByTestId('testid')) | ||
} | ||
|
||
export async function testScreen() { | ||
render({template: 'button'}) | ||
|
||
await screen.findByRole('button') | ||
} | ||
|
||
export async function testWaitFor() { | ||
const {container} = render({template: 'button'}) | ||
await fireEvent.click(container) | ||
await waitFor(() => {}) | ||
} | ||
|
||
export function testOptions() { | ||
render(SomeComponent, { | ||
// options for new Vue() | ||
name: 'SomeComponent', | ||
methods: { | ||
glorb() { | ||
return 42 | ||
}, | ||
}, | ||
// options for vue-test-utils mount() | ||
slots: { | ||
quux: '<p>Baz</p>', | ||
}, | ||
mocks: { | ||
isThisFake() { | ||
return true | ||
}, | ||
}, | ||
// options for Vue Testing Library render() | ||
container: elem, | ||
baseElement: elem, | ||
props: { | ||
foo: 9, | ||
bar: 'x', | ||
}, | ||
store: { | ||
state: { | ||
foos: [4, 5], | ||
bars: ['a', 'b'], | ||
}, | ||
getters: { | ||
fooCount() { | ||
return this.foos.length | ||
}, | ||
}, | ||
}, | ||
routes: [ | ||
{path: '/', name: 'home', component: SomeComponent}, | ||
{ | ||
path: '/about', | ||
name: 'about', | ||
component: () => Promise.resolve(SomeComponent), | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
export function testConfigCallback() { | ||
const ExamplePlugin: Vue.PluginFunction<never> = () => {} | ||
render(SomeComponent, {}, (localVue, store, router) => { | ||
localVue.use(ExamplePlugin) | ||
store.replaceState({foo: 'bar'}) | ||
router.onError(error => console.log(error.message)) | ||
}) | ||
} | ||
|
||
/* | ||
eslint | ||
testing-library/prefer-explicit-assert: "off", | ||
testing-library/no-wait-for-empty-callback: "off", | ||
testing-library/no-debug: "off", | ||
testing-library/prefer-screen-queries: "off", | ||
@typescript-eslint/unbound-method: "off", | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// this additional tsconfig is required by dtslint | ||
// see: https://github.com/Microsoft/dtslint#typestsconfigjson | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["es6", "dom"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"noEmit": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"@testing-library/vue": ["."] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": ["dtslint/dtslint.json"], | ||
"rules": { | ||
"semicolon": false, | ||
"whitespace": false | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Support for this is now built-in to the latest version of kcd-scripts (actually, eslint-config-kentcdodds, but that's what kcd-scripts uses).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I assumed when I checked the changelogs, but sadly enough eslint-plugin-vue requires us to use
parserOptions.parser
option instead ofparser
, because the latest needs to be used internally to parse Vue files.SFC are cool but come with their own headaches 😅