Add some test coverage for getBranchesAsObjArray
This commit is contained in:
parent
351dd3728e
commit
9ca077b3dc
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue