Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add typeof assertion #762

Merged
merged 4 commits into from Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vitest/src/index.ts
Expand Up @@ -97,6 +97,7 @@ declare global {
toBeUndefined(): void
toBeNull(): void
toBeDefined(): void
toBeTypeOf(expected: 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined'): void
toBeInstanceOf<E>(expected: E): void
toBeCalledTimes(times: number): void
toHaveLength(length: number): void
Expand Down
12 changes: 12 additions & 0 deletions packages/vitest/src/integrations/chai/jest-expect.ts
Expand Up @@ -227,6 +227,18 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {

return this.not.be.undefined
})
def('toBeTypeOf', function(obj: 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined') {
const equal = typeof this._obj === obj
const actual = typeof this._obj
const expected = obj
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
return this.assert(
equal,
'expected #{this} to be type of #{exp}',
'expected #{this} not to be type of #{exp}',
expected,
actual,
)
})
def('toBeInstanceOf', function(obj: any) {
return this.instanceOf(obj)
})
Expand Down