chore(tests) \o/
This commit is contained in:
76
lib/core/Cetra.test.js
Normal file
76
lib/core/Cetra.test.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import Cetra from './Cetra';
|
||||||
|
|
||||||
|
describe('Cetra', () => {
|
||||||
|
let cetra;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
cetra = new Cetra();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cetra = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('general', () => {
|
||||||
|
it('should emit the onAfterInit event', () => {
|
||||||
|
const spy = jest.fn();
|
||||||
|
let _test = new Cetra(new Map([['onAfterInit', spy]]));
|
||||||
|
expect(spy).toHaveBeenCalled().withArgs('onAfterInit');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('uid', () => {
|
||||||
|
it('should generate a unique identifier', () => {
|
||||||
|
const identifier = cetra.uid();
|
||||||
|
|
||||||
|
expect(typeof identifier).toBe('string');
|
||||||
|
expect(identifier.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should generate a unique identifier with the specified number of groups and group length', () => {
|
||||||
|
const numGroups = 3;
|
||||||
|
const groupLength = 4;
|
||||||
|
|
||||||
|
const identifier = cetra.uid(numGroups, groupLength);
|
||||||
|
|
||||||
|
const groups = identifier.split('-');
|
||||||
|
expect(groups.length).toBe(numGroups);
|
||||||
|
groups.forEach((group) => {
|
||||||
|
expect(group.length).toBe(groupLength);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isUrl', () => {
|
||||||
|
it('should return true for a valid url', () => {
|
||||||
|
const url = 'https://www.google.com';
|
||||||
|
|
||||||
|
expect(cetra.isUrl(url)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for an invalid url', () => {
|
||||||
|
const url = 'https://www.google';
|
||||||
|
|
||||||
|
expect(cetra.isUrl(url)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for a non-string', () => {
|
||||||
|
const url = 123;
|
||||||
|
|
||||||
|
expect(cetra.isUrl(url)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for an empty string', () => {
|
||||||
|
const url = '';
|
||||||
|
|
||||||
|
expect(cetra.isUrl(url)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for a relative path', () => {
|
||||||
|
const url = '/test';
|
||||||
|
|
||||||
|
expect(cetra.isUrl(url)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
import Cetra from './Cetra';
|
||||||
Reference in New Issue
Block a user