-
Couldn't load subscription status.
- Fork 39
[MOB-12186] add-tests-for-iterableutil #709
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,227 @@ | ||||||
| import { IterableUtil } from './IterableUtil'; | ||||||
|
|
||||||
| /** | ||||||
| * Tests for IterableUtil class. | ||||||
| * | ||||||
| * Note: The current implementation of readBoolean has a limitation - it doesn't actually | ||||||
| * validate that the value is a boolean. It returns any truthy value as-is, or false for falsy values. | ||||||
| * This behavior is tested below, but the implementation may need to be updated to properly | ||||||
| * validate boolean types as suggested in the TODO comment in the source code. | ||||||
| */ | ||||||
| describe('IterableUtil', () => { | ||||||
| describe('readBoolean', () => { | ||||||
| it('should return true when the key exists and value is true', () => { | ||||||
| // GIVEN a dictionary with a true boolean value | ||||||
| const dict = { testKey: true }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return true | ||||||
| expect(result).toBe(true); | ||||||
| }); | ||||||
|
|
||||||
| it('should return false when the key exists and value is false', () => { | ||||||
| // GIVEN a dictionary with a false boolean value | ||||||
| const dict = { testKey: false }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return false | ||||||
| expect(result).toBe(false); | ||||||
| }); | ||||||
|
|
||||||
| it('should return false when the key does not exist', () => { | ||||||
| // GIVEN a dictionary without the key | ||||||
| const dict = { otherKey: true }; | ||||||
|
|
||||||
| // WHEN reading a non-existent key | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return false | ||||||
| expect(result).toBe(false); | ||||||
| }); | ||||||
|
|
||||||
| it('should return false when the key exists but value is undefined', () => { | ||||||
| // GIVEN a dictionary with undefined value | ||||||
| const dict = { testKey: undefined }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return false | ||||||
| expect(result).toBe(false); | ||||||
| }); | ||||||
|
|
||||||
| it('should return false when the key exists but value is null', () => { | ||||||
| // GIVEN a dictionary with null value | ||||||
| const dict = { testKey: null }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return false | ||||||
| expect(result).toBe(false); | ||||||
| }); | ||||||
|
|
||||||
| it('should return false when the key exists but value is 0', () => { | ||||||
| // GIVEN a dictionary with 0 value | ||||||
| const dict = { testKey: 0 }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return false | ||||||
| expect(result).toBe(false); | ||||||
| }); | ||||||
|
|
||||||
| it('should return false when the key exists but value is empty string', () => { | ||||||
| // GIVEN a dictionary with empty string value | ||||||
| const dict = { testKey: '' }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return false | ||||||
| expect(result).toBe(false); | ||||||
| }); | ||||||
|
|
||||||
| it('should return false when the key exists but value is NaN', () => { | ||||||
| // GIVEN a dictionary with NaN value | ||||||
| const dict = { testKey: NaN }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return false | ||||||
| expect(result).toBe(false); | ||||||
| }); | ||||||
|
|
||||||
| // TODO: Verify that we want this to return a string instead of a boolean | ||||||
| it('should return truthy string as boolean when key exists', () => { | ||||||
| // GIVEN a dictionary with truthy string value | ||||||
| const dict = { testKey: 'true' }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return the string cast to boolean (truthy) | ||||||
| expect(result).toBe('true'); | ||||||
| }); | ||||||
|
|
||||||
| // TODO: Verify that we want this to return a number instead of a boolean | ||||||
| it('should return truthy number as boolean when key exists', () => { | ||||||
| // GIVEN a dictionary with truthy number value | ||||||
| const dict = { testKey: 1 }; | ||||||
|
|
||||||
| // WHEN reading the boolean value | ||||||
| const result = IterableUtil.readBoolean(dict, 'testKey'); | ||||||
|
|
||||||
| // THEN it should return the number cast to boolean (truthy) | ||||||
|
||||||
| // THEN it should return the number cast to boolean (truthy) | |
| // THEN it should return the original number value (since it is truthy) |
Copilot
AI
Oct 10, 2025
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.
The comment describes the object as being 'cast to boolean (truthy)' but the test expects the original object value, not a boolean. The comment should clarify that truthy values are returned as-is, not cast to boolean.
Copilot
AI
Oct 10, 2025
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.
The comment describes the array as being 'cast to boolean (truthy)' but the test expects the original array value, not a boolean. The comment should clarify that truthy values are returned as-is, not cast to boolean.
| // THEN it should return the array cast to boolean (truthy) | |
| // THEN it should return the array value as-is (since arrays are truthy) |
Copilot
AI
Oct 10, 2025
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.
The comment describes the function as being 'cast to boolean (truthy)' but the test expects the original function value, not a boolean. The comment should clarify that truthy values are returned as-is, not cast to boolean.
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.
The comment describes the string as being 'cast to boolean (truthy)' but the test expects the original string value 'true', not a boolean. The comment should clarify that truthy values are returned as-is, not cast to boolean.