Skip to content

Commit

Permalink
add test case for ratioToNumber function
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed May 2, 2024
1 parent 001391b commit 18c2045
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function AspectRatioGroup( {
);
}

function ratioToNumber( str ) {
export function ratioToNumber( str ) {
// TODO: support two-value aspect ratio?
// https://css-tricks.com/almanac/properties/a/aspect-ratio/#aa-it-can-take-two-values
const [ a, b, ...rest ] = str.split( '/' ).map( Number );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Internal dependencies
*/
import { ratioToNumber } from '../';

test( 'ratioToNumber', () => {
expect( ratioToNumber( '1/1' ) ).toBe( 1 );
expect( ratioToNumber( '1' ) ).toBe( 1 );
expect( ratioToNumber( '11/11' ) ).toBe( 1 );
expect( ratioToNumber( '16/9' ) ).toBe( 16 / 9 );
expect( ratioToNumber( '4/3' ) ).toBe( 4 / 3 );
expect( ratioToNumber( '3/2' ) ).toBe( 3 / 2 );
expect( ratioToNumber( '2/1' ) ).toBe( 2 );
expect( ratioToNumber( '1/2' ) ).toBe( 1 / 2 );
expect( ratioToNumber( '2/3' ) ).toBe( 2 / 3 );
expect( ratioToNumber( '3/4' ) ).toBe( 3 / 4 );
expect( ratioToNumber( '9/16' ) ).toBe( 9 / 16 );
expect( ratioToNumber( '1/16' ) ).toBe( 1 / 16 );
expect( ratioToNumber( '16/1' ) ).toBe( 16 );
expect( ratioToNumber( '1/9' ) ).toBe( 1 / 9 );
expect( ratioToNumber( 'auto' ) ).toBe( NaN );
} );

0 comments on commit 18c2045

Please sign in to comment.