diff options
| author | Marak <[email protected]> | 2017-02-09 23:24:39 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-02-09 23:24:39 -0500 |
| commit | 530c2ea186858ce82ab9707d11fe35def51bfbcf (patch) | |
| tree | 14dc708ef33887dfa287ecc656a3ea12ecfc3c02 /test | |
| parent | ecb42b179573138dac20ad0b4481954a2ac72e67 (diff) | |
| parent | 8794efa5bfdaccaf47a7cee227bbef93cffbb66e (diff) | |
| download | faker-530c2ea186858ce82ab9707d11fe35def51bfbcf.tar.xz faker-530c2ea186858ce82ab9707d11fe35def51bfbcf.zip | |
Merge pull request #437 from lencse/master
[api] Added `lorem.slug` method
Diffstat (limited to 'test')
| -rw-r--r-- | test/all.functional.js | 2 | ||||
| -rw-r--r-- | test/lorem.unit.js | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/test/all.functional.js b/test/all.functional.js index 02025837..4ea196b6 100644 --- a/test/all.functional.js +++ b/test/all.functional.js @@ -18,7 +18,7 @@ var modules = { internet: ['email', 'userName', 'domainName', 'domainWord', 'ip'], - lorem: ['words', 'sentence', 'sentences', 'paragraph', 'paragraphs'], + lorem: ['words', 'sentence', 'slug', 'sentences', 'paragraph', 'paragraphs'], name: ['firstName', 'lastName', 'findName', 'jobTitle'], diff --git a/test/lorem.unit.js b/test/lorem.unit.js index fbf09497..300786b8 100644 --- a/test/lorem.unit.js +++ b/test/lorem.unit.js @@ -34,6 +34,36 @@ describe("lorem.js", function () { }); }); + describe("slug()", function () { + beforeEach(function () { + sinon.spy(faker.helpers, 'shuffle'); + }); + + afterEach(function () { + faker.helpers.shuffle.restore(); + }); + + var validateSlug = function (wordCount, str) { + assert.equal(1, str.match(/^[a-z][a-z-]*[a-z]$/).length); + assert.equal(wordCount - 1, str.match(/-/g).length); + }; + + context("when no 'wordCount' param passed in", function () { + it("returns a slug with three words", function () { + var str = faker.lorem.slug(); + validateSlug(3, str); + }); + }); + + context("when 'wordCount' param passed in", function () { + it("returns a slug with requested number of words", function () { + var str = faker.lorem.slug(7); + validateSlug(7, str); + }); + }); + + }); + /* describe("sentence()", function () { context("when no 'wordCount' or 'range' param passed in", function () { |
