Browse Source
* Introduce customer jest match to support matchRenderedSnapshot * lint:tsc stop emitingpull/22951/head
Eric Wang
5 years ago
committed by
GitHub
8 changed files with 53 additions and 31 deletions
@ -0,0 +1,21 @@ |
|||
import { render } from 'enzyme'; |
|||
import { ReactElement } from 'react'; |
|||
|
|||
export default function toMatchRenderedSnapshot( |
|||
this: jest.MatcherUtils, |
|||
jsx: ReactElement<unknown>, |
|||
): { message(): string; pass: boolean } { |
|||
try { |
|||
expect(render(jsx)).toMatchSnapshot(); |
|||
|
|||
return { |
|||
message: () => 'expected JSX not to match snapshot', |
|||
pass: true, |
|||
}; |
|||
} catch (e) { |
|||
return { |
|||
message: () => `expected JSX to match snapshot: ${e.message}`, |
|||
pass: false, |
|||
}; |
|||
} |
|||
} |
@ -0,0 +1,5 @@ |
|||
import toMatchRenderedSnapshot from './matchers/rendered-snapshot'; |
|||
|
|||
expect.extend({ |
|||
toMatchRenderedSnapshot, |
|||
}); |
@ -0,0 +1,5 @@ |
|||
declare namespace jest { |
|||
interface Matchers<R> { |
|||
toMatchRenderedSnapshot(): R; |
|||
} |
|||
} |
Loading…
Reference in new issue