diff --git a/client/app/utils/__tests__/index.test.js b/client/app/utils/__tests__/index.test.js new file mode 100644 index 0000000000..34ee222b75 --- /dev/null +++ b/client/app/utils/__tests__/index.test.js @@ -0,0 +1,20 @@ +import Utils from '../index'; + +describe('Utils', () => { + describe('randomString ', () => { + it('should return random string', () => { + expect(typeof Utils.randomString()).toBe('string'); + }); + }); + + describe('getPusher', () => { + it('should return null if window.Pusher is not defined', () => { + expect(Utils.getPusher()).toBe(null); + }); + it('should return new window.Pusher if window.Pusher is defined', () => { + window.Pusher = jest.fn(); + const pusher = Utils.getPusher(); + expect(pusher).toBeInstanceOf(window.Pusher); + }); + }); +}); diff --git a/client/app/utils/index.js b/client/app/utils/index.js index 57a75d18e7..c6e3275d1e 100644 --- a/client/app/utils/index.js +++ b/client/app/utils/index.js @@ -3,12 +3,8 @@ import axios from 'axios'; import renderHTML from 'react-render-html'; import { sanitize } from 'dompurify'; -const randomString = (): string => Math.random() - .toString(36) - .substring(2, 15) - + Math.random() - .toString(36) - .substring(2, 15); +const randomString = (): string => Math.random().toString(36).substring(2, 15) + + Math.random().toString(36).substring(2, 15); const setCsrfToken = (): void => { const tokenDom = document.querySelector('meta[name=csrf-token]');