-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1155 from alphagov/ldeb-replace-keypather
Replace keypather with lodash.get
- Loading branch information
Showing
5 changed files
with
57 additions
and
191 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
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,48 @@ | ||
/* eslint-env jest */ | ||
|
||
const nunjucks = require('nunjucks') | ||
|
||
const utils = require('./utils.js') | ||
|
||
describe('checked', () => { | ||
var ctx, checked | ||
|
||
beforeAll(() => { | ||
var env = new nunjucks.Environment() | ||
utils.addCheckedFunction(env) | ||
ctx = { data: {} } | ||
checked = env.getGlobal('checked').bind({ ctx }) | ||
}) | ||
|
||
it('can be added as global function to a nunjucks env', () => { | ||
var env = new nunjucks.Environment() | ||
utils.addCheckedFunction(env) | ||
expect(env.getGlobal('checked')).toBeDefined() | ||
}) | ||
|
||
it('returns a string', () => { | ||
expect(checked('foo', 'bar')).toBe('') | ||
}) | ||
|
||
it('returns checked if data has specified value', () => { | ||
ctx.data.foo = 'bar' | ||
expect(checked('foo', 'bar')).toBe('checked') | ||
}) | ||
|
||
it('returns empty string if data does not has specified value', () => { | ||
ctx.data.foo = 'baz' | ||
expect(checked('foo', 'bar')).toBe('') | ||
}) | ||
|
||
it('allows deep access into objects', () => { | ||
ctx.data.foo = 'bar' | ||
expect(checked('foo', 'bar')).toBe('checked') | ||
ctx.data.foo = { bar: 'baz' } | ||
expect(checked("['foo']['bar']", 'baz')).toBe('checked') | ||
}) | ||
|
||
it('allows deep access using dot notation (undocumented)', () => { | ||
ctx.data.foo = { bar: 'baz' } | ||
expect(checked('foo.bar', 'baz')).toBe('checked') | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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