I\'d like to unit test the following ES6 class:
// service.js
const InternalService = require(\'internal-service\');
class Service {
constructor(args) {
You can either create a namespace or create a stub instance using sinon.createStubInstance (this will not invoke the constructor).
Creating a namespace:
const namespace = {
Service: require('./service')
};
describe('Service', function() {
it('getData', function() {
sinon.stub(namespace, 'Service').returns(0);
console.log(new namespace.Service()); // Service {}
});
});
Creating a stub instance:
let Service = require('./service');
describe('Service', function() {
it('getData', function() {
let stub = sinon.createStubInstance(Service);
console.log(stub); // Service {}
});
});