Skip to content

Commit ed8a2eb

Browse files
authored
fix(expect): allow function as standard schema (#9099)
1 parent 379185b commit ed8a2eb

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/expect/src/jest-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ export function getObjectSubset(
807807
export function isStandardSchema(obj: any): obj is StandardSchemaV1 {
808808
return (
809809
!!obj
810-
&& typeof obj === 'object'
810+
&& (typeof obj === 'object' || typeof obj === 'function')
811811
&& obj['~standard']
812812
&& typeof obj['~standard'].validate === 'function'
813813
)

test/core/test/expect.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,5 +788,10 @@ describe('Standard Schema', () => {
788788
`)
789789
}
790790
})
791+
792+
test('function', () => {
793+
const stringSchemaFn = Object.assign(() => {}, stringSchema)
794+
expect('hello').toEqual(expect.schemaMatching(stringSchemaFn))
795+
})
791796
})
792797
})

0 commit comments

Comments
 (0)