-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3bfc7a
commit 7ddbb1e
Showing
3 changed files
with
301 additions
and
1 deletion.
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,61 @@ | ||
'use strict' | ||
|
||
const test = require('japa') | ||
const Globals = require('../../src/Globals') | ||
|
||
test.group('Globals', () => { | ||
test('return safe element object when .el global is called', (assert) => { | ||
const context = { | ||
safe (input) { | ||
return input | ||
} | ||
} | ||
const output = Globals.el.bind(context)('<a href="$url"> $title </a>', { title: 'Docs', url: '/docs' }) | ||
assert.equal(output, '<a href="/docs"> Docs </a>') | ||
}) | ||
|
||
test('replace with nested objects', (assert) => { | ||
const context = { | ||
safe (input) { | ||
return input | ||
} | ||
} | ||
const output = Globals.el.bind(context)('<a href="$meta.url"> $meta.title </a>', { meta: {title: 'Docs', url: '/docs'} }) | ||
assert.equal(output, '<a href="/docs"> Docs </a>') | ||
}) | ||
|
||
test('replace with nested objects inside an array', (assert) => { | ||
const context = { | ||
safe (input) { | ||
return input | ||
} | ||
} | ||
const output = Globals.el.bind(context)('<a href="$meta.0.url"> $meta.0.title </a>', { meta: [{title: 'Docs', url: '/docs'}] }) | ||
assert.equal(output, '<a href="/docs"> Docs </a>') | ||
}) | ||
|
||
test('convert a link to an anchor tag', (assert) => { | ||
const context = { | ||
safe (input) { | ||
return input | ||
} | ||
} | ||
const output = Globals.toAnchor.bind(context)('http://google.com') | ||
assert.equal(output, '<a href="http://google.com"> http://google.com </a>') | ||
}) | ||
|
||
test('convert a link to an anchor tag with custom title', (assert) => { | ||
const context = { | ||
safe (input) { | ||
return input | ||
} | ||
} | ||
const output = Globals.toAnchor.bind(context)('http://google.com', 'Google') | ||
assert.equal(output, '<a href="http://google.com"> Google </a>') | ||
}) | ||
|
||
test('encode url', (assert) => { | ||
const output = Globals.urlEncode('http://foo.com?username=aman virk') | ||
assert.equal(output, 'http://foo.com?username=aman%20virk') | ||
}) | ||
}) |