-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: STRF-10494 last and first helpers works with strings (#254)
* fix: STRF-10494 last and first helpers works with strings * fix: STRF-10494 PR fixes
- Loading branch information
1 parent
1c8376e
commit 51f341e
Showing
3 changed files
with
174 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
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,85 @@ | ||
const Lab = require('lab'), | ||
lab = exports.lab = Lab.script(), | ||
describe = lab.experiment, | ||
it = lab.it; | ||
const {testRunner} = require("../../spec-helpers"); | ||
|
||
describe('first', () => { | ||
describe('string', () => { | ||
|
||
const context = { | ||
smallString: 'abc', | ||
empty: '', | ||
myString: 'BigCommerce' | ||
}; | ||
|
||
const runner = testRunner({context}); | ||
|
||
it('should extract the first char when no "n" is given.', done => { | ||
runner([{ | ||
input: '{{first myString}}', | ||
output: 'B' | ||
}], done); | ||
}); | ||
|
||
it('should return the whole string when "n" is bigger that string size', done => { | ||
runner([{ | ||
input: '{{first smallString 5}}', | ||
output: context.smallString | ||
}], done); | ||
}); | ||
|
||
it('should return the expected string', done => { | ||
runner([{ | ||
input: '{{first myString 3}}', | ||
output: 'Big' | ||
}], done); | ||
}); | ||
|
||
it('should return empty string when empty string is provided', done => { | ||
runner([{ | ||
input: '{{first empty 3}}', | ||
output: '' | ||
}], done); | ||
}); | ||
}); | ||
|
||
describe('array', () => { | ||
|
||
const context = { | ||
small: [1,2,3], | ||
empty:[], | ||
arrayYay: [1,2,3,4,5,6,7,8,9,0] | ||
}; | ||
|
||
const runner = testRunner({context}); | ||
|
||
it('should extract the first elem when no "n" is given.', done => { | ||
runner([{ | ||
input: '{{first arrayYay}}', | ||
output: '1' | ||
}], done); | ||
}); | ||
|
||
it('should return the whole array when "n" is bigger that array size', done => { | ||
runner([{ | ||
input: '{{first small 5}}', | ||
output: context.small.join() | ||
}], done); | ||
}); | ||
|
||
it('should return the expected elems', done => { | ||
runner([{ | ||
input: '{{first arrayYay 3}}', | ||
output: [1,2,3].join() | ||
}], done); | ||
}); | ||
|
||
it('should return empty string when empty array is provided', done => { | ||
runner([{ | ||
input: '{{first empty 3}}', | ||
output: '' | ||
}], done); | ||
}); | ||
}); | ||
}); |
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,85 @@ | ||
const Lab = require('lab'), | ||
lab = exports.lab = Lab.script(), | ||
describe = lab.experiment, | ||
it = lab.it; | ||
const {testRunner} = require("../../spec-helpers"); | ||
|
||
describe('last', () => { | ||
describe('string', () => { | ||
|
||
const context = { | ||
smallString: 'abc', | ||
empty: '', | ||
myString: 'BigCommerce' | ||
}; | ||
|
||
const runner = testRunner({context}); | ||
|
||
it('should extract the last char when no "n" is given.', done => { | ||
runner([{ | ||
input: '{{last myString}}', | ||
output: 'e' | ||
}], done); | ||
}); | ||
|
||
it('should return the whole string when "n" is bigger that string size', done => { | ||
runner([{ | ||
input: '{{last smallString 5}}', | ||
output: context.smallString | ||
}], done); | ||
}); | ||
|
||
it('should return the expected string', done => { | ||
runner([{ | ||
input: '{{last myString 3}}', | ||
output: 'rce' | ||
}], done); | ||
}); | ||
|
||
it('should return empty string when empty string is provided', done => { | ||
runner([{ | ||
input: '{{last empty 3}}', | ||
output: '' | ||
}], done); | ||
}); | ||
}); | ||
|
||
describe('array', () => { | ||
|
||
const context = { | ||
small: [1, 2, 3], | ||
empty: [], | ||
arrayYay: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] | ||
}; | ||
|
||
const runner = testRunner({context}); | ||
|
||
it('should extract the last elem when no "n" is given.', done => { | ||
runner([{ | ||
input: '{{last arrayYay}}', | ||
output: '0' | ||
}], done); | ||
}); | ||
|
||
it('should return the whole array when "n" is bigger that array size', done => { | ||
runner([{ | ||
input: '{{last small 5}}', | ||
output: context.small.join() | ||
}], done); | ||
}); | ||
|
||
it('should return the expected elems', done => { | ||
runner([{ | ||
input: '{{last arrayYay 3}}', | ||
output: [8, 9, 0].join() | ||
}], done); | ||
}); | ||
|
||
it('should return empty string when empty array is provided', done => { | ||
runner([{ | ||
input: '{{last empty 3}}', | ||
output: '' | ||
}], done); | ||
}); | ||
}); | ||
}); |