This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Unit tests #67
Merged
Merged
Unit tests #67
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d98ca3a
test(getAttribute.test.js): adding unit tests for getAttribute
biharck 4ff10fc
feat(getAuthorizationHeader.test.js): including getAuthorizationHeade…
biharck 78b2950
feat(getName.test.js): adding getName tests
biharck 8bb8d01
feat(getNumber.test.js): adding getNumber.test.js
biharck 2bb3be5
feat(getString.test.js): adding getString.test.js
biharck 4bdfc5a
feat(index.test.js): adding index.test.js file
biharck 9ec7f11
feat(index.test.js): improviments on index test file
biharck 94e9323
feat(getModalities.test.js): adding getModalities tests
biharck 7e35154
feat(index.test.js): emoving call tests since the expect test already…
biharck 58957ea
adding and refactoring absoluteUrl function
biharck e5b1056
adding addServer.test.js
biharck c497001
adding unit tests for guid
biharck 438e592
adding unit tests for index.js
biharck e3248a8
fixing typo in guid.test.js and adding isImage.test.js file
biharck e43ae2f
adding tests for objectPath.js
biharck bfd062f
replacing toBeCalled to toBeCalledWith
biharck 8918c50
Merge branch 'master' into unit-tests
biharck b157816
fixing typo
biharck 91658db
removing beforeEach
biharck e76725c
making the test description and variables clear
biharck 8ec4b54
Clearing all mocks after tests run
biharck c959b12
improving addServer tests
biharck 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 |
---|---|---|
@@ -1,52 +1,42 @@ | ||
import guid from './guid'; | ||
|
||
describe('guid', () => { | ||
beforeEach(() => { | ||
Math.random = jest.fn(() => 0.4677647565236618); | ||
}); | ||
Math.random = jest.fn(() => 0.4677647565236618); | ||
const guidValue = guid(); | ||
|
||
test('should return 77bf77bf-77bf-77bf-77bf-77bf77bf77bf when the random value is fixed on 0.4677647565236618', () => { | ||
const guidValue = guid(); | ||
expect(guidValue).toBe('77bf77bf-77bf-77bf-77bf-77bf77bf77bf'); | ||
}); | ||
|
||
test('should always return a guid of size 36', () => { | ||
const guidValue = guid(); | ||
expect(guidValue.length).toBe(36); | ||
}); | ||
|
||
test('should always return a guid with five sequences', () => { | ||
const guidValue = guid(); | ||
expect(guidValue.split('-').length).toBe(5); | ||
}); | ||
|
||
test('should always return a guid with four dashes', () => { | ||
const guidValue = guid(); | ||
expect(guidValue.split('-').length - 1).toBe(4); | ||
}); | ||
|
||
test('should return the first sequence with length of eigth', () => { | ||
const guidValue = guid(); | ||
expect(guidValue.split('-')[0].length).toBe(8); | ||
}); | ||
|
||
test('should return the second sequence with length of four', () => { | ||
const guidValue = guid(); | ||
expect(guidValue.split('-')[1].length).toBe(4); | ||
}); | ||
|
||
test('should return the third sequence with length of four', () => { | ||
const guidValue = guid(); | ||
expect(guidValue.split('-')[2].length).toBe(4); | ||
}); | ||
|
||
test('should return the fourth sequence with length of four', () => { | ||
const guidValue = guid(); | ||
expect(guidValue.split('-')[3].length).toBe(4); | ||
}); | ||
|
||
test('should return the last sequence with length of twelve', () => { | ||
const guidValue = guid(); | ||
expect(guidValue.split('-')[4].length).toBe(12); | ||
}); | ||
}); |
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.
Will this bleed into a different test suite? Do you need to "undo" this patch after all of these tests have run?
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.
Good point. It won't right now but it is safe to add a
clearAllMocks
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.
@biharck, if you use Math.random somewhere else, I think it would still be a jest.fn? Doesn't clearAllMocks just reset the function so you can see what args are passed?
I think you need to do something like...
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.
For example: jestjs/jest#7136 (comment)
But I think you're right that
Math.random
calls in other test suites would use the baked in implementation, and not the one we override here.