Add test cases for utils.initIdGeneratior

This commit is contained in:
Julian Amelung
2020-11-23 23:34:47 +01:00
parent 35cd3918df
commit c472024921
3 changed files with 44 additions and 8 deletions

View File

@@ -253,3 +253,34 @@ describe('when calculating SVG size', function() {
expect(attrs.get('width')).toEqual(200);
});
});
describe('when initializing the id generator', function () {
it('should return a random number generator based on Date', function (done) {
const idGenerator = utils.initIdGeneratior(false)
expect(typeof idGenerator.next).toEqual('function')
const lastId = idGenerator.next()
setTimeout(() => {
expect(idGenerator.next() > lastId).toBe(true)
done()
}, 5)
});
it('should return a non random number generator', function () {
const idGenerator = utils.initIdGeneratior(true)
expect(typeof idGenerator.next).toEqual('function')
const start = 0
const lastId = idGenerator.next()
expect(start).toEqual(lastId)
expect(idGenerator.next()).toEqual(lastId +1)
});
it('should return a non random number generator based on seed', function () {
const idGenerator = utils.initIdGeneratior(true, 'thisIsASeed')
expect(typeof idGenerator.next).toEqual('function')
const start = 11
const lastId = idGenerator.next()
expect(start).toEqual(lastId)
expect(idGenerator.next()).toEqual(lastId +1)
});
})