-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This offers proper typings for the props given in the mounting options.
- Loading branch information
Showing
4 changed files
with
109 additions
and
22 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,87 @@ | ||
import { expectType } from 'tsd' | ||
import { expectError, expectType } from 'tsd' | ||
import { defineComponent } from 'vue' | ||
import { mount } from '../src' | ||
|
||
const App = defineComponent({ | ||
const AppWithDefine = defineComponent({ | ||
props: { | ||
a: String | ||
a: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
template: '' | ||
}) | ||
|
||
let wrapper = mount(App) | ||
// accept props | ||
let wrapper = mount(AppWithDefine, { | ||
props: { a: 'Hello' } | ||
}) | ||
// vm is properly typed | ||
expectType<string>(wrapper.vm.a) | ||
|
||
const AppWithoutDefine = { | ||
// can receive extra props | ||
mount(AppWithDefine, { | ||
props: { a: 'Hello', b: 2 } | ||
}) | ||
|
||
// wrong prop type should not compile | ||
expectError( | ||
mount(AppWithDefine, { | ||
props: { a: 2 } | ||
}) | ||
) | ||
|
||
const AppWithProps = { | ||
props: { | ||
a: String | ||
a: { | ||
type: String, | ||
required: true | ||
} | ||
}, | ||
template: '' | ||
} | ||
|
||
wrapper = mount(AppWithoutDefine) | ||
// accept props | ||
wrapper = mount(AppWithProps, { | ||
props: { a: 'Hello' } | ||
}) | ||
// vm is properly typed | ||
expectType<string>(wrapper.vm.a) | ||
|
||
// can receive extra props | ||
mount(AppWithProps, { | ||
props: { a: 'Hello', b: 2 } | ||
}) | ||
|
||
// wrong prop type should not compile | ||
expectError( | ||
mount(AppWithProps, { | ||
props: { a: 2 } | ||
}) | ||
) | ||
|
||
const AppWithArrayProps = { | ||
props: ['a'], | ||
template: '' | ||
} | ||
|
||
// accept props | ||
wrapper = mount(AppWithArrayProps, { | ||
props: { a: 'Hello' } | ||
}) | ||
// vm is properly typed | ||
expectType<string>(wrapper.vm.a) | ||
|
||
// can receive extra props | ||
mount(AppWithArrayProps, { | ||
props: { a: 'Hello', b: 2 } | ||
}) | ||
|
||
const AppWithoutProps = { | ||
template: '' | ||
} | ||
|
||
// can receive extra props | ||
wrapper = mount(AppWithoutProps, { | ||
props: { b: 'Hello' } | ||
}) |
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