Skip to content

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

Merged
merged 6 commits into from
Oct 25, 2017
Merged

test(text-helper): add test for emojifyText, abbreviateNumber #568

merged 6 commits into from
Oct 25, 2017

Conversation

ibotdotout
Copy link
Contributor

Copy link
Member

@alejandronanez alejandronanez left a 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 describes
  • emojifyText should be tested in another way, we should mock the emoji package and then check if we called emoji.emojify with the right params. Right now, if emoji changes one of its contents this test will break.
  • Please add const to each constant/variable for example, expected = ... should be const expected = ....

Copy link
Member

@andrewda andrewda left a 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', () => {
Copy link
Member

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:');
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
});
Copy link
Member

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
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling c54a9cc on ibotdotout:utility-tests into ** on gitpoint:master**.

@ibotdotout
Copy link
Contributor Author

thank you @alejandronanez @andrewda for your reviewed.

I improve

  • mock emojifyText instead direct test output, I not sure with sinon.spy that it correct ?
  • insert const to variables
  • add huge and random 96234 -> 96.2k

@lex111
Copy link
Member

lex111 commented Oct 24, 2017

@ibotdotout coluld you add a new line before expect?

@coveralls
Copy link

Coverage Status

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';
Copy link
Member

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 :?

Copy link
Member

@alejandronanez alejandronanez left a 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!!!

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling c7af126 on ibotdotout:utility-tests into ** on gitpoint:master**.

@ibotdotout
Copy link
Contributor Author

@alejandronanez already change to use jest for spy with jest.spyOn.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 90467ea on ibotdotout:utility-tests into ** on gitpoint:master**.

Copy link
Member

@andrewda andrewda left a 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', () => {
Copy link
Member

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', () => {
Copy link
Member

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', () => {
Copy link
Member

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', () => {
Copy link
Member

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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling fd2b6a6 on ibotdotout:utility-tests into ** on gitpoint:master**.

@andrewda andrewda merged commit 0cd67ba into gitpoint:master Oct 25, 2017
@andrewda andrewda mentioned this pull request Oct 25, 2017
63 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants