utils.test.js 930 B

1234567891011121314151617181920212223242526272829
  1. import { between, sprintf, unit } from '../../src/js/utils/utils';
  2. describe( 'Utility function ', () => {
  3. test( '"between" should trim the first given value by other 2 numbers.', () => {
  4. expect( between( 5, 0, 10 ) ).toBe( 5 );
  5. expect( between( 11, 0, 10 ) ).toBe( 10 );
  6. expect( between( 11, 10, 0 ) ).toBe( 10 );
  7. expect( between( -1, 10, 0 ) ).toBe( 0 );
  8. } );
  9. test( '"sprintf" should replace %s from the first argument with the second one.', () => {
  10. expect( sprintf( '%s, world!', 'Hello' ) ).toBe( 'Hello, world!' );
  11. } );
  12. describe( '"unit" should', () => {
  13. test( 'return the given value itself when the argument is string.', () => {
  14. expect( unit( '1px' ) ).toBe( '1px' );
  15. } );
  16. test( 'append "px" to the given number.', () => {
  17. expect( unit( 1 ) ).toBe( '1px' );
  18. } );
  19. test( 'return an empty string when the given value is falsy.', () => {
  20. expect( unit( 0 ) ).toBe( '' );
  21. } );
  22. } );
  23. } );