Files
shields/lib/svg-to-img.spec.js
Paul Melnikow 6c2ce413b1 Adopt async-await for most promise-based code (#1565)
* Address todo for Node 8 upgrade
2018-03-15 09:36:40 -04:00

32 lines
1.0 KiB
JavaScript

'use strict';
const { expect } = require('chai');
const isPng = require('is-png');
const sinon = require('sinon');
const svg2img = require('./svg-to-img');
const testHelpers = require('./make-badge-test-helpers');
const makeBadge = testHelpers.makeBadge();
describe('The rasterizer', function () {
let cacheGet;
beforeEach(function () { cacheGet = sinon.spy(svg2img._imgCache, 'get'); });
afterEach(function () { cacheGet.restore(); });
it('should produce PNG', async function() {
const svg = makeBadge({ text: ['cactus', 'grown'], format: 'svg' });
const data = await svg2img(svg, 'png');
expect(data).to.satisfy(isPng);
});
it('should cache its results', async function() {
const svg = makeBadge({ text: ['will-this', 'be-cached?'], format: 'svg' });
const data1 = await svg2img(svg, 'png');
expect(data1).to.satisfy(isPng);
expect(cacheGet).not.to.have.been.called;
const data2 = await svg2img(svg, 'png')
expect(data2).to.satisfy(isPng);
expect(cacheGet).to.have.been.calledOnce;
});
});