From 9ca077b3dc75b2fa105d599d1de5a7700bb27b76 Mon Sep 17 00:00:00 2001 From: Brian Mearns Date: Tue, 1 Oct 2019 22:29:07 -0400 Subject: [PATCH] Add some test coverage for getBranchesAsObjArray --- src/diagrams/git/gitGraphParser.spec.js | 31 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/diagrams/git/gitGraphParser.spec.js b/src/diagrams/git/gitGraphParser.spec.js index 14c962b0e..dbd06ace3 100644 --- a/src/diagrams/git/gitGraphParser.spec.js +++ b/src/diagrams/git/gitGraphParser.spec.js @@ -7,15 +7,19 @@ import cryptoRandomString from 'crypto-random-string'; jest.mock('crypto-random-string'); describe('when parsing a gitGraph', function() { - let i = 0; + let randomNumber; beforeEach(function() { parser.yy = gitGraphAst; parser.yy.clear(); + randomNumber = 0; cryptoRandomString.mockImplementation(() => { - i = i + 1; - return String(i); + randomNumber = randomNumber + 1; + return String(randomNumber); }); }); + afterEach(function() { + cryptoRandomString.mockReset(); + }); it('should handle a gitGraph defintion', function() { const str = 'gitGraph:\n' + 'commit\n'; @@ -234,7 +238,7 @@ describe('when parsing a gitGraph', function() { parser.yy.prettyPrint(); }); - it('it should generate a secure random ID for commits', () => { + it('it should generate a secure random ID for commits', function() { const str = 'gitGraph:\n' + 'commit\n' + 'commit\n'; const EXPECTED_LENGTH = 7; const EXPECTED_CHARACTERS = '0123456789abcdef'; @@ -261,4 +265,23 @@ describe('when parsing a gitGraph', function() { expect(commits[key].id).toEqual(key); }); }); + + it('it should generate an array of known branches', function() { + const str = + 'gitGraph:\n' + + 'commit\n' + + 'branch b1\n' + + 'checkout b1\n' + + 'commit\n' + + 'commit\n' + + 'branch b2\n'; + + parser.parse(str); + const branches = gitGraphAst.getBranchesAsObjArray(); + + expect(branches).toHaveLength(3); + expect(branches[0]).toHaveProperty('name', 'master'); + expect(branches[1]).toHaveProperty('name', 'b1'); + expect(branches[2]).toHaveProperty('name', 'b2'); + }); });