File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 6
6
getDiffForFile ,
7
7
getGitFileList ,
8
8
getRangesForDiff ,
9
+ hasCleanIndex ,
9
10
} from "./git" ;
10
11
import {
11
12
diffFileList ,
@@ -82,6 +83,24 @@ describe("getDiffForFile", () => {
82
83
} ) ;
83
84
} ) ;
84
85
86
+ describe ( "hasCleanIndex" , ( ) => {
87
+ it ( "returns false instead of throwing" , ( ) => {
88
+ jest . mock ( "child_process" ) . resetAllMocks ( ) ;
89
+ mockedChildProcess . execSync . mockImplementationOnce ( ( ) => {
90
+ throw Error ( "mocked error" ) ;
91
+ } ) ;
92
+ expect ( hasCleanIndex ( "" ) ) . toEqual ( false ) ;
93
+ expect ( mockedChildProcess . execSync ) . toHaveBeenCalled ( ) ;
94
+ } ) ;
95
+
96
+ it ( "returns true otherwise" , ( ) => {
97
+ jest . mock ( "child_process" ) . resetAllMocks ( ) ;
98
+ mockedChildProcess . execSync . mockReturnValue ( Buffer . from ( "" ) ) ;
99
+ expect ( hasCleanIndex ( "" ) ) . toEqual ( true ) ;
100
+ expect ( mockedChildProcess . execSync ) . toHaveBeenCalled ( ) ;
101
+ } ) ;
102
+ } ) ;
103
+
85
104
describe ( "getDiffFileList" , ( ) => {
86
105
it ( "should get the list of staged files" , ( ) => {
87
106
jest . mock ( "child_process" ) . resetAllMocks ( ) ;
You can’t perform that action at this time.
0 commit comments