@schukai/monster
Version:
Monster is a simple library for creating fast, robust and lightweight websites.
61 lines (48 loc) • 2.06 kB
JavaScript
import {expect} from "chai"
import {UniqueQueue} from "../../../source/types/uniquequeue.mjs";
describe('UniqueQueue', function () {
let queue;
beforeEach(() => {
queue = new UniqueQueue;
})
describe('isEmpty()', function () {
it('first it should empty', function () {
expect(queue.isEmpty()).to.be.true;
});
})
describe('add sequence peek and poll', function () {
it('result a,a,a,b', function () {
expect(queue.add({a: 1})).to.be.instanceOf(UniqueQueue);
expect(queue.isEmpty()).to.be.false;
expect(queue.add({a: 2})).to.be.instanceOf(UniqueQueue);
expect(queue.add({a: 3})).to.be.instanceOf(UniqueQueue);
expect(queue.peek()).to.deep.equal({a:1});
expect(queue.peek()).to.deep.equal({a:1});
expect(queue.poll()).to.deep.equal({a:1});
expect(queue.poll()).to.deep.equal({a:2});
expect(queue.isEmpty()).to.be.false;
expect(queue.peek()).to.deep.equal({a:3});
expect(queue.poll()).to.deep.equal({a:3});
expect(queue.isEmpty()).to.be.true;
});
})
describe('add and clear', function () {
it('should empty', function () {
expect(queue.isEmpty()).to.be.true;
expect(queue.add({a: 1})).to.be.instanceOf(UniqueQueue);
expect(queue.isEmpty()).to.be.false;
expect(queue.clear()).to.be.instanceOf(UniqueQueue);
expect(queue.isEmpty()).to.be.true;
});
})
describe('add no object', function () {
it('should throw error', function () {
expect(()=>{queue.add([])}).to.throw(TypeError)
expect(()=>{queue.add(1)}).to.throw(TypeError)
expect(()=>{queue.add(true)}).to.throw(TypeError)
expect(()=>{queue.add()}).to.throw(TypeError)
expect(()=>{queue.add(Symbol("1"))}).to.throw(TypeError)
expect(()=>{queue.add(function(){})}).to.throw(TypeError)
});
})
})