-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: SanData#get() return undefined when not found
- Loading branch information
Showing
2 changed files
with
33 additions
and
13 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
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,28 @@ | ||
import { SanData } from '../../../src/models/san-data' | ||
|
||
describe('models/SanData', () => { | ||
it('should get directly defined data', () => { | ||
const data = new SanData({ foo: 'FOO' }, {}) | ||
expect(data.get('foo')).toEqual('FOO') | ||
}) | ||
it('should get nested data', () => { | ||
const data = new SanData({ bar: { foo: 'FOO' } }, {}) | ||
expect(data.get('bar.foo')).toEqual('FOO') | ||
}) | ||
it('should get computed data', () => { | ||
const data = new SanData({}, { foo: () => 'FOO' }) | ||
expect(data.get('foo')).toEqual('FOO') | ||
}) | ||
it('computed data should override defined data', () => { | ||
const data = new SanData({ foo: 'FOO' }, { foo: () => 'Foo' }) | ||
expect(data.get('foo')).toEqual('Foo') | ||
}) | ||
it('should return undefined if not found', () => { | ||
const data = new SanData({ foo: 'FOO' }, {}) | ||
expect(data.get('bar')).toBeUndefined() | ||
}) | ||
it('should return undefined if not found nested', () => { | ||
const data = new SanData({ bar: { bar: 'FOO' } }, {}) | ||
expect(data.get('bar.foo')).toBeUndefined() | ||
}) | ||
}) |