Skip to content

Commit

Permalink
added tests for randomString and getPusher (#2181)
Browse files Browse the repository at this point in the history
* added tests for randomString and getPusher

* eslint fixes

* eslint modifications

* index.js line break fix: eslint

* eslint runs successfully

* fix:Utils test - usage of imports
  • Loading branch information
saminarp authored Oct 24, 2022
1 parent 6513055 commit 22aa53d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
20 changes: 20 additions & 0 deletions client/app/utils/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
8 changes: 2 additions & 6 deletions client/app/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]');
Expand Down

0 comments on commit 22aa53d

Please sign in to comment.