UNPKG

jasmine-istanbul-reporter

Version:

Jasmine report plugin that scrapes test pages for istanbul coverage stats and writes them to a set of files for eventual conversion to LCOV, Cobertura, etc.

63 lines (60 loc) 2.53 kB
var sinon = require('sinon'); var assert = require('assert'); var utilities = require('./utilities'); var subjectPath = '../lib/file-system'; var subject; describe('file-system', function () { beforeEach(function (done) { subject = require(subjectPath); done(); }); describe('::writeJsonToFile', function () { beforeEach(function (done) { sinon.stub(subject.fs, 'outputJsonSync'); done(); }); describe('when given a valid object', function () { describe('when given a valid path', function () { it('uses its underlying fs library to write the object to the file', function (done) { var assignedObject = {}; var assignedFilePath = 'some/path'; subject.writeJsonToFile(assignedObject, assignedFilePath, function (error) { if (error) throw error; sinon.assert.calledWith(subject.fs.outputJsonSync, assignedFilePath, assignedObject); done(); }); }); }); describe('when given an invalid path', function () { it('it rejects a non-string path with an appropriate error code', function (done) { var assignedObject = {}; var assignedFilePath = null; subject.writeJsonToFile(assignedObject, assignedFilePath, function (error) { assert.notEqual(error, undefined); assert.equal(error.name, 'ArgumentError'); done(); }); }); }); }); describe('when given an invalid object', function () { it('it rejects a non-object object with an appropriate error code', function (done) { var assignedObject = undefined; // null is okay var assignedFilePath = 'some/path'; subject.writeJsonToFile(assignedObject, assignedFilePath, function (error) { assert.notEqual(error, undefined); assert.equal(error.name, 'ArgumentError'); done(); }); }); }); afterEach(function (done) { subject.fs.outputJsonSync.restore(); done(); }); }); afterEach(function (done) { delete require.cache[require.resolve(subjectPath)]; done(); }); });