-
Notifications
You must be signed in to change notification settings - Fork 783
test(text-helper): add test for emojifyText, abbreviateNumber #568
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
Conversation
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.
Hey @ibotdotout thanks for your PR, can you please:
- Remove nested
describe
s emojifyText
should be tested in another way, we should mock theemoji
package and then check if we calledemoji.emojify
with the right params. Right now, ifemoji
changes one of its contents this test will break.- Please add
const
to each constant/variable for example,expected = ...
should beconst expected = ....
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.
Looks good! Just a couple small changes.
Also @alejandronanez – I talked about this in Gitter, but I think nested describes
are fine in this context.
|
||
describe('Text Helper', () => { | ||
describe('emojifyText', () => { | ||
it('should get correctly display :caffee: with emoji', () => { |
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.
:caffee:
=> :coffee:
😉
describe('emojifyText', () => { | ||
it('should get correctly display :caffee: with emoji', () => { | ||
expected = 'I need more ☕️'; | ||
result = emojifyText('I need more :coffee:'); |
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.
Declare these with const
.
it('should get 1 when give 1', () => { | ||
input = 1; | ||
expected = 1; | ||
result = abbreviateNumber(input); |
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.
Declare these with const
.
it('should get 1k when give 1000', () => { | ||
input = 1000; | ||
expected = '1k'; | ||
result = abbreviateNumber(input); |
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.
Declare these with const
.
input = 1100; | ||
expected = '1.1k'; | ||
result = abbreviateNumber(input); | ||
expect(result).toEqual(expected); |
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.
Declare these with const
.
expected = '1.1k'; | ||
result = abbreviateNumber(input); | ||
expect(result).toEqual(expected); | ||
}); |
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.
I would also add a test for something huge and random like 96234
, which should equal 96.2k
I think.
- mock emojifyText instead direct test output - insert const for variables - add huge and random 96234 -> 96.2k
Changes Unknown when pulling c54a9cc on ibotdotout:utility-tests into ** on gitpoint:master**. |
thank you @alejandronanez @andrewda for your reviewed. I improve
|
@ibotdotout coluld you add a new line before |
Changes Unknown when pulling 0a4ef41 on ibotdotout:utility-tests into ** on gitpoint:master**. |
describe('emojifyText', () => { | ||
it('should call correcly with text params', () => { | ||
const emojify = sinon.spy(emoji, 'emojify'); | ||
const input = 'I need more :coffee'; |
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.
Is there not at the end :
?
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.
Can you please remove sinon and use jest instead? You can do spies and mocks with jest out of the box.
Thanks!!!
Changes Unknown when pulling c7af126 on ibotdotout:utility-tests into ** on gitpoint:master**. |
@alejandronanez already change to use jest for spy with |
Changes Unknown when pulling 90467ea on ibotdotout:utility-tests into ** on gitpoint:master**. |
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.
One more little wording change then 👍
}); | ||
|
||
describe('abbreviateNumber', () => { | ||
it('should get 1 when give 1', () => { |
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.
Change this to: 'should return 1 when given 1'
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should get 1k when give 1000', () => { |
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.
Apply same pattern as above
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should get 1.1k when give 1100', () => { |
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.
^
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should get 96.2k when give 96234', () => { |
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.
^
describe('Text Helper', () => { | ||
describe('emojifyText', () => { | ||
it('should call correcly with text params', () => { | ||
const emojify = jest.spyOn(emoji, 'emojify'); |
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.
💯
Changes Unknown when pulling fd2b6a6 on ibotdotout:utility-tests into ** on gitpoint:master**. |
#518