All files / platform/core/src/utils guid.test.js

0% Statements 0/24
100% Branches 0/0
0% Functions 0/12
0% Lines 0/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                                             
import guid from './guid';
 
describe('guid', () => {
  Math.random = jest.fn(() => 0.4677647565236618);
  const guidValue = guid();
 
  afterAll(() => {
    jest.clearAllMocks();
  });
 
  test('should return 77bf77bf-77bf-77bf-77bf-77bf77bf77bf when the random value is fixed on 0.4677647565236618', () => {
    expect(guidValue).toBe('77bf77bf-77bf-77bf-77bf-77bf77bf77bf');
  });
 
  test('should always return a guid of size 36', () => {
    expect(guidValue.length).toBe(36);
  });
 
  test('should always return a guid with five sequences', () => {
    expect(guidValue.split('-').length).toBe(5);
  });
 
  test('should always return a guid with four dashes', () => {
    expect(guidValue.split('-').length - 1).toBe(4);
  });
 
  test('should return the first sequence with length of eigth', () => {
    expect(guidValue.split('-')[0].length).toBe(8);
  });
 
  test('should return the second sequence with length of four', () => {
    expect(guidValue.split('-')[1].length).toBe(4);
  });
 
  test('should return the third sequence with length of four', () => {
    expect(guidValue.split('-')[2].length).toBe(4);
  });
 
  test('should return the fourth sequence with length of four', () => {
    expect(guidValue.split('-')[3].length).toBe(4);
  });
 
  test('should return the last sequence with length of twelve', () => {
    expect(guidValue.split('-')[4].length).toBe(12);
  });
});