Files
shields/lib/svg-to-img.spec.js
Paul Melnikow 7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00

36 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
})
})