-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(formatters): Complex Object Formatter shouldn't throw with null data
- Loading branch information
1 parent
a9680c3
commit 3421465
Showing
2 changed files
with
10 additions
and
4 deletions.
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ import { Column } from '../../interfaces/index'; | |
import { complexObjectFormatter } from '../complexObjectFormatter'; | ||
|
||
describe('the ComplexObject Formatter', () => { | ||
const allRoles = [{ roleId: 0, name: 'Administrator' }, { roleId: 1, name: 'Regular User', empty: {} }]; | ||
const allRoles = [{ roleId: 0, name: 'Administrator' }, { roleId: 1, name: 'Regular User', empty: {}, nullable: null }]; | ||
|
||
const dataset = [ | ||
{ id: 0, firstName: 'John', lastName: 'Smith', email: '[email protected]', role: allRoles[0] }, | ||
|
@@ -16,7 +16,7 @@ describe('the ComplexObject Formatter', () => { | |
}); | ||
|
||
it('should return empty string when no column definition is provided', () => { | ||
const result = complexObjectFormatter(0, 0, 'anything', null as Column, {}, {} as any); | ||
const result = complexObjectFormatter(0, 0, 'anything', null as any, {}, {} as any); | ||
expect(result).toBe(''); | ||
}); | ||
|
||
|
@@ -48,12 +48,18 @@ describe('the ComplexObject Formatter', () => { | |
expect(result).toBe(expectedOutput); | ||
}); | ||
|
||
it('should return an empty string when the value from the complex object when "field" has dot notation and the empty returned from it is an empty object', () => { | ||
it('should return an empty string when the value from the complex object when "field" has dot notation and the property returned from it is an empty object', () => { | ||
const expectedOutput = ''; | ||
const result = complexObjectFormatter(0, 0, 'anything', { field: 'role.empty' } as Column, dataset[1], {} as any); | ||
expect(result).toBe(expectedOutput); | ||
}); | ||
|
||
it('should return an empty string when the value from the complex object when "field" has dot notation and the property returned from it is a null value', () => { | ||
const expectedOutput = ''; | ||
const result = complexObjectFormatter(0, 0, 'anything', { field: 'role.nullable' } as Column, dataset[1], {} as any); | ||
expect(result).toBe(expectedOutput); | ||
}); | ||
|
||
it('should return the value from the complex object when "complexFieldLabel" property with dot notation was found in the data context object', () => { | ||
const params = { complexFieldLabel: 'role.name' }; | ||
const expectedOutput = 'Administrator'; | ||
|
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