-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controller): add stringConverter for empty reflecting attributes
PiperOrigin-RevId: 464124340
- Loading branch information
1 parent
bcc5635
commit 2a0d563
Showing
3 changed files
with
51 additions
and
3 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,14 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const stringConverter = { | ||
fromAttribute(value: string|null): string { | ||
return value ?? ''; | ||
}, | ||
toAttribute(value: string): string|null { | ||
return value || null; | ||
} | ||
}; |
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,32 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import 'jasmine'; | ||
|
||
import {stringConverter} from './string-converter'; | ||
|
||
describe('stringConverter', () => { | ||
describe('.fromAttribute', () => { | ||
it('should return an empty string if string is empty or null', () => { | ||
expect(stringConverter.fromAttribute('')).toBe(''); | ||
expect(stringConverter.fromAttribute(null)).toBe(''); | ||
}); | ||
|
||
it('should return value of string if not empty', () => { | ||
expect(stringConverter.fromAttribute('foo')).toBe('foo'); | ||
}); | ||
}); | ||
|
||
describe('.toAttribute', () => { | ||
it('should return null if string is empty', () => { | ||
expect(stringConverter.toAttribute('')).toBeNull(); | ||
}); | ||
|
||
it('should return value of string if not empty', () => { | ||
expect(stringConverter.toAttribute('foo')).toBe('foo'); | ||
}); | ||
}); | ||
}); |
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