-
Notifications
You must be signed in to change notification settings - Fork 755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added tests for randomString and getPusher #2181
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9d85388
added tests for randomString and getPusher
6da4fd6
Merge branch 'ifmeorg:main' into tests/issue#2128
saminarp f34c0c6
eslint fixes
15db97b
eslint modifications
d062391
index.js line break fix: eslint
eb59c78
eslint runs successfully
b73134d
fix:Utils test - usage of imports
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { randomString, getPusher } = require('../index'); | ||
|
||
describe('Utils', () => { | ||
describe('randomString ', () => { | ||
it('should return random string', () => { | ||
expect(typeof randomString()).toBe('string'); | ||
}); | ||
}); | ||
|
||
describe('getPusher', () => { | ||
it('should return null if window.Pusher is not defined', () => { | ||
const pusher = getPusher(); | ||
expect(pusher).toBe(null); | ||
}); | ||
it('should return new window.Pusher if window.Pusher is defined', () => { | ||
window.Pusher = jest.fn(); | ||
const pusher = getPusher(); | ||
expect(pusher).toBeInstanceOf(window.Pusher); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,18 @@ 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); | ||
export const randomString = (): string => Math.random().toString(36).substring(2, 15) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary to export these functions individually in order to be able to test them. You should be able to import the |
||
+ Math.random().toString(36).substring(2, 15); | ||
|
||
const setCsrfToken = (): void => { | ||
export const setCsrfToken = (): void => { | ||
const tokenDom = document.querySelector('meta[name=csrf-token]'); | ||
if (tokenDom) { | ||
const csrfToken = tokenDom.getAttribute('content'); | ||
axios.defaults.headers.common['X-CSRF-Token'] = csrfToken; | ||
} | ||
}; | ||
|
||
const getPusher = (): Object | null => { | ||
export const getPusher = (): Object | null => { | ||
if (window.Pusher) { | ||
const metaPusherKey = Array.from( | ||
window.document.getElementsByTagName('meta'), | ||
|
@@ -33,7 +29,7 @@ const getPusher = (): Object | null => { | |
return null; | ||
}; | ||
|
||
const renderContent = (content: string | any): any => { | ||
export const renderContent = (content: string | any): any => { | ||
if (typeof content === 'string') { | ||
return renderHTML(sanitize(content)); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use imports here instead, I recommend just pulling in the Utils object instead of adding new exports for each function.
Then you can call
Utils.randomString()
andUtils.getPusher()
.