This repository has been archived on 2025-03-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cetra/lib/core/Cetra.test.js

77 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

2024-01-11 23:27:32 +00:00
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';