chai-arrays
Version:
a simple chai plugin for better array assertions
104 lines (75 loc) • 3.09 kB
JavaScript
const chai = require('chai');
const chaiArrays = require('../assertArrays');
chai.use(chaiArrays);
const expect = chai.expect;
describe('Assert Uint32Array', () => {
it('should assert the type is Uint32Array', () => {
const collection = new Uint32Array();
expect(collection).to.be.Uint32Array();
});
it('should assert presence of a value in array', () => {
const collection = new Uint32Array(2);
collection[0] = 1;
collection[1] = 2;
expect(collection).to.be.containing(1);
});
it('should assert absence of a value in array', () => {
const collection = new Uint32Array(2);
collection[0] = 1;
collection[1] = 2;
expect(collection).not.to.be.containing(4);
});
it('should assert presence of all values in array', () => {
const collection = new Uint32Array(3);
collection[0] = 1;
collection[1] = 2;
collection[2] = 3;
expect(collection).to.be.containingAllOf(new Uint32Array([1]));
expect(collection).to.be.containingAllOf(new Uint32Array([1, 3]));
expect(collection).to.be.containingAllOf(new Uint32Array([1, 2, 3]));
});
it('should assert absence of all values in array', () => {
const collection = new Uint32Array(3);
collection[0] = 1;
collection[1] = 2;
collection[2] = 3;
expect(collection).not.to.be.containingAllOf(new Uint32Array([4]));
expect(collection).not.to.be.containingAllOf(new Uint32Array([1, 4]));
});
it('should assert presence of at least one value in array', () => {
const collection = new Uint32Array(3);
collection[0] = 1;
collection[1] = 2;
collection[2] = 3;
expect(collection).to.be.containingAnyOf(new Uint32Array([1]));
expect(collection).to.be.containingAnyOf(new Uint32Array([1, 5]));
expect(collection).to.be.containingAnyOf(new Uint32Array([1, 5, 3]));
});
it('should assert absence of all values in array', () => {
const collection = new Uint32Array(3);
collection[0] = 1;
collection[1] = 2;
collection[2] = 3;
expect(collection).not.to.be.containingAnyOf(new Uint32Array([4]));
expect(collection).not.to.be.containingAnyOf(new Uint32Array([4, 5, 8]));
});
it('should assert actual is equalTo expected', () => {
expect(new Uint32Array([1, 2, 3])).to.be.equalTo(new Uint32Array([1, 2, 3]));
expect(new Uint32Array(['foo', 'bar', 'foobar'])).to.be.equalTo(new Uint32Array(['foo', 'bar', 'foobar']));
});
it('should assert actual is not equal to expected for unequal length arrays', () => {
expect(new Uint32Array([1])).not.to.be.equalTo(new Uint32Array([1, 2, 3]));
});
it('should assert the size of array', () => {
expect(new Uint32Array([1, 2, 3])).to.be.ofSize(3);
});
it('should not assert the size of array', () => {
expect(new Uint32Array([1, 2, 3])).not.to.be.ofSize(5);
});
it('should assert that the array is sorted', () => {
expect(new Uint32Array([1, 2, 3])).to.be.sorted();
});
it('should assert that the array is not sorted', () => {
expect(new Uint32Array([1, 5, 2, 3])).not.to.be.sorted();
});
});