Skip to content
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

Fix #115: added test cases for sentiment analysis #207

Merged
merged 15 commits into from Nov 15, 2019
39 changes: 39 additions & 0 deletions test/sentiment-analysis.test.js
@@ -0,0 +1,39 @@

const sentimentAnalysis = require('../src/sentiment-analysis');

const expected = {
score: 1,
comparative: 0.1111111111111111,
calculation: [{ allergic: -2 }, { love: 3 }],
tokens: [
'i',
'love',
'cats',
'but',
'i',
'am',
'allergic',
'to',
'them',
],
words: [
'allergic',
'love',
],
positive: [
'love',
],
negative: [
'allergic',
],
};

test('test if sample text does not return the correct object', async () => {
const data = await sentimentAnalysis.run('I like dogs, but my girlfriend is afraid of them');
expect(data).toEqual(expect.not.objectContaining(expected));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you not just compare data to expected with a deep equals here? What does .toEqual(expect.not.objectContaining(expected)) mean? Maybe you're right, but this seems odd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@humphd From what I have read, .toEqual should be used for objects. Regards to expect.not.objectContaining(expected) , I am using this to check if the contents(properties) of the object do not match what we are expecting. This was suggested by @jatinAroraGit and after reading the docs I agreed to his suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, OK, sounds fine. Thanks for educating me.

});

test('test if sample text returns the correct object', async () => {
const data = await sentimentAnalysis.run('I love cats, but I am allergic to them.');
expect(data).toEqual(expect.objectContaining(expected));
});