@@ -14,38 +14,59 @@ describe("utils", () => {
1414 } ) ;
1515
1616 describe ( "getBranchNameFromRef" , ( ) => {
17+ // We want to assert that the props are properly set in
18+ // the union of the return type
19+ interface BranchNameResultUnion {
20+ branchName ?: string ;
21+ isTag : boolean ;
22+ ref : string ;
23+ }
24+
1725 it ( "should return the branch name for a valid branch ref" , ( ) => {
1826 const branchName = "cool_feature" ;
1927 const ref = `/refs/heads/${ branchName } ` ;
20- const branch = getBranchName ( ref ) ;
28+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
2129
22- expect ( branch ) . toStrictEqual ( branchName ) ;
30+ expect ( branch . isTag ) . toStrictEqual ( false ) ;
31+ expect ( branch . branchName ) . toStrictEqual ( branchName ) ;
32+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
2333 } ) ;
2434
2535 it ( "should return the branch name for a valid branch ref without a leading slash" , ( ) => {
2636 const branchName = "cool_feature" ;
2737 const ref = `refs/heads/${ branchName } ` ;
28- const branch = getBranchName ( ref ) ;
38+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
2939
30- expect ( branch ) . toStrictEqual ( branchName ) ;
40+ expect ( branch . isTag ) . toStrictEqual ( false ) ;
41+ expect ( branch . branchName ) . toStrictEqual ( branchName ) ;
42+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
3143 } ) ;
3244
3345 it ( "should return undefined for an invalid branch ref" , ( ) => {
34- const branch = getBranchName ( "refs/heads/" ) ;
46+ const ref = "refs/heads/" ;
47+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
3548
36- expect ( branch ) . toBeUndefined ( ) ;
49+ expect ( branch . isTag ) . toStrictEqual ( false ) ;
50+ expect ( branch . branchName ) . toBeUndefined ( ) ;
51+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
3752 } ) ;
3853
39- it ( "should return undefined if the ref is for a tag" , ( ) => {
40- const branch = getBranchName ( "refs/tags/v1.0.1" ) ;
54+ it ( "should return isTag true if the ref is for a tag" , ( ) => {
55+ const ref = "refs/tags/v1.0.1" ;
56+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
4157
42- expect ( branch ) . toBeUndefined ( ) ;
58+ expect ( branch . isTag ) . toStrictEqual ( true ) ;
59+ expect ( branch . branchName ) . toBeUndefined ( ) ;
60+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
4361 } ) ;
4462
45- it ( "should return undefined if the ref is for an invalid tag" , ( ) => {
46- const branch = getBranchName ( "refs/tags/" ) ;
63+ it ( "should return isTag true if the ref is for an invalid tag" , ( ) => {
64+ const ref = "refs/tags/" ;
65+ const branch = getBranchName ( ref ) as BranchNameResultUnion ;
4766
48- expect ( branch ) . toBeUndefined ( ) ;
67+ expect ( branch . isTag ) . toStrictEqual ( true ) ;
68+ expect ( branch . branchName ) . toBeUndefined ( ) ;
69+ expect ( branch . ref ) . toStrictEqual ( ref ) ;
4970 } ) ;
5071 } ) ;
5172} ) ;
0 commit comments