lens-filter-sepia
Version:
Small library to apply a sepia transformation to a image
56 lines (47 loc) • 1.47 kB
JavaScript
import core from 'lens-core';
import victim, { transform } from '../index';
jest.mock('lens-core');
describe('sepia', () => {
describe('when data is not defined', () => {
it('should throw error', () => {
expect(() => victim()).toThrowError(
'lens-filter-sepia:: invalid options provided'
);
});
});
describe('when has all paramters', () => {
let result;
const data = 'DATA';
beforeAll(() => {
core.applyFilter = jest.fn().mockReturnValue('MOCK-VALUE');
result = victim({ data, nWorkers: 4 });
});
it('should call applyFilter', () => {
expect(core.applyFilter).toHaveBeenCalledWith({
data,
transform: expect.anything(),
nWorkers: 4
});
});
it('should return the applyFilter result', () => {
expect(result).toEqual('MOCK-VALUE');
});
});
});
describe('#transform()', function() {
it('should apply transformation and return as imageData', function() {
const data = [193, 219, 242, 255, 193, 219, 242, 255];
const expectedData = [
289.998,
258.247,
201.144,
255,
193,
219,
242,
255
];
const result = transform({ data, length: 4 });
expect(result).toEqual(expectedData);
});
});