forked from swimlane/ngx-datatable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit test deepValueGetter. fix swimlane#596 prop field name with dots.
- Loading branch information
Showing
2 changed files
with
63 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { deepValueGetter } from './column-prop-getters'; | ||
|
||
describe('deepValueGetter', () => { | ||
|
||
it('should get values one level deep', () => { | ||
let data = { | ||
a: { | ||
value: 123 | ||
} | ||
}; | ||
expect(deepValueGetter(data, 'a.value')).toEqual(123); | ||
}); | ||
|
||
it('should get values two levels deep', () => { | ||
let data = { | ||
a: { | ||
b: { | ||
value: 'foo' | ||
} | ||
} | ||
}; | ||
expect(deepValueGetter(data, 'a.b.value')).toEqual('foo'); | ||
}); | ||
|
||
it('should return empty string on missing nested field', () => { | ||
let data = { | ||
a: {} | ||
}; | ||
expect(deepValueGetter(data, 'a.x.value')).toEqual(''); | ||
}); | ||
|
||
it('should return empty string on missing final field', () => { | ||
let data = { | ||
a: {} | ||
}; | ||
expect(deepValueGetter(data, 'a.value')).toEqual(''); | ||
}); | ||
|
||
it('should return empty string on missing root field', () => { | ||
let data = { | ||
a: {} | ||
}; | ||
expect(deepValueGetter(data, 'x.value')).toEqual(''); | ||
}); | ||
|
||
it('should check for root-level fields with dots in name', () => { | ||
let data = { | ||
"a.b.value": 5 | ||
}; | ||
expect(deepValueGetter(data, 'a.b.value')).toEqual(5); | ||
}); | ||
|
||
}); |
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