@@ -4,6 +4,18 @@ import { globalConfig, testConfig } from './config/defaultConfigs';
44import functionToString from './helpers/functionToString' ;
55import freezeImage from './freezeImage' ;
66import { sanitiseGlobalConfiguration } from './sanitiser' ;
7+ import jestMatchers from './utils/jestMatchers' ;
8+ import compareImage from './compareImage' ;
9+
10+ const mockMatcher = jest . fn ( ( ) => ( {
11+ message : 'message' ,
12+ pass : true ,
13+ } ) ) ;
14+
15+ jestMatchers . toNotError = mockMatcher ;
16+ jestMatchers . toMatchImageSnapshot = mockMatcher ;
17+
18+ jest . mock ( './compareImage' ) ;
719
820const tabMocks = {
921 goto : jest . fn ( ) ,
@@ -53,7 +65,10 @@ describe('Page', () => {
5365 afterEach ( ( ) => {
5466 puppeteer . launch . mockClear ( ) ;
5567 mockLog . mockClear ( ) ;
68+ mockErr . mockClear ( ) ;
5669 functionToString . mockClear ( ) ;
70+ mockMatcher . mockClear ( ) ;
71+ compareImage . mockClear ( ) ;
5772 page . error = false ;
5873 } ) ;
5974 beforeEach ( ( ) => {
@@ -159,6 +174,27 @@ describe('Page', () => {
159174 expect ( mockErr ) . toHaveBeenCalledTimes ( 0 ) ;
160175 } ) ;
161176 } ) ;
177+ describe ( '_evaluateResult' , ( ) => {
178+ it ( 'it calls toNotError if error happens in any steps when in jest mode' , async ( ) => {
179+ page . error = new Error ( 'Error happened' ) ;
180+ const result = await page . _evaluateResult ( ) ;
181+ expect ( jestMatchers . toNotError ) . toHaveBeenCalled ( ) ;
182+ expect ( result ) . toEqual ( false ) ;
183+ } ) ;
184+ it ( 'it wont calls toMatchImageSnapshot when in jest mode and compareImage throws' , async ( ) => {
185+ const result = await page . _evaluateResult ( ) ;
186+ expect ( compareImage ) . toHaveBeenCalled ( ) ;
187+ expect ( jestMatchers . toMatchImageSnapshot ) . not . toHaveBeenCalled ( ) ;
188+ expect ( result ) . toEqual ( false ) ;
189+ } ) ;
190+ it ( 'it calls toMatchImageSnapshot when in jest mode' , async ( ) => {
191+ compareImage . mockReturnValueOnce ( { matched : true } ) ;
192+ const result = await page . _evaluateResult ( ) ;
193+ expect ( compareImage ) . toHaveBeenCalled ( ) ;
194+ expect ( jestMatchers . toMatchImageSnapshot ) . toHaveBeenCalled ( ) ;
195+ expect ( result ) . toEqual ( true ) ;
196+ } ) ;
197+ } ) ;
162198 describe ( 'FreezeImage' , ( ) => {
163199 beforeEach ( ( ) => {
164200 tabMocks . evaluate . mockClear ( ) ;
0 commit comments