From 2968497cff29f81b223010c25fa7d34785a8a004 Mon Sep 17 00:00:00 2001 From: Danielle Adams Date: Tue, 26 Jun 2018 16:03:46 -0400 Subject: add unit test for git module --- test/git.unit.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/git.unit.js (limited to 'test/git.unit.js') diff --git a/test/git.unit.js b/test/git.unit.js new file mode 100644 index 00000000..3e0c5104 --- /dev/null +++ b/test/git.unit.js @@ -0,0 +1,62 @@ +if (typeof module !== 'undefined') { + var assert = require('assert'); + var sinon = require('sinon'); + var faker = require('../index'); +} + +describe("git.js", function() { + describe("branch()", function() { + beforeEach(function() { + sinon.spy(faker.hacker, 'noun'); + sinon.spy(faker.hacker, 'verb'); + }); + + afterEach(function() { + faker.hacker.noun.restore(); + faker.hacker.verb.restore(); + }); + + it("returns a branch with hacker noun, adj and verb", function() { + var message = faker.git.branch(); + + assert.ok(faker.hacker.noun.calledOnce); + assert.ok(faker.hacker.verb.calledOnce); + }); + }); + + describe("commitSha()", function() { + it("returns a random commit SHA", function() { + var commitSha = faker.git.commitSha(); + assert.ok(commitSha.match(/^[a-z0-9]{40}$/)); + }); + }); + + describe("commitMessage()", function() { + beforeEach(function() { + sinon.spy(faker.hacker, 'verb'); + sinon.spy(faker.hacker, 'adjective'); + sinon.spy(faker.hacker, 'noun'); + }); + + afterEach(function() { + faker.hacker.verb.restore(); + faker.hacker.adjective.restore(); + faker.hacker.noun.restore(); + }); + + it("returns a commit message with hacker noun, adj and verb", function() { + var message = faker.git.commitMessage(); + + assert.ok(faker.hacker.verb.calledOnce); + assert.ok(faker.hacker.adjective.calledOnce); + assert.ok(faker.hacker.noun.calledOnce); + }); + }); + + describe("shortSha()", function() { + it("returns a random short SHA", function() { + var commitSha = faker.git.shortSha(); + assert.ok(commitSha.match(/^[a-z0-9]{7}$/)); + }); + }); +}); \ No newline at end of file -- cgit v1.2.3