refactor(ES6): MultiWatching.test.js

This commit is contained in:
Shubheksha Jalan 2017-01-18 19:12:59 +05:30
parent d9ac04380e
commit d2ea2d8d65
1 changed files with 18 additions and 20 deletions

View File

@ -1,50 +1,48 @@
var should = require("should");
var sinon = require("sinon");
var MultiWatching = require("../lib/MultiWatching");
"use strict";
var createWatching = function() {
const should = require("should");
const sinon = require("sinon");
const MultiWatching = require("../lib/MultiWatching");
const createWatching = function() {
return {
invalidate: sinon.spy(),
close: sinon.spy()
};
};
describe("MultiWatching", function() {
var watchings, myMultiWatching;
describe("MultiWatching", () => {
let watchings, myMultiWatching;
beforeEach(function() {
beforeEach(() => {
watchings = [createWatching(), createWatching()];
myMultiWatching = new MultiWatching(watchings);
});
describe('invalidate', function() {
beforeEach(function() {
myMultiWatching.invalidate();
});
describe("invalidate", () => {
beforeEach(() => myMultiWatching.invalidate());
it('invalidates each watching', function() {
it("invalidates each watching", () => {
watchings[0].invalidate.callCount.should.be.exactly(1);
watchings[1].invalidate.callCount.should.be.exactly(1);
});
});
describe('close', function() {
var callback;
var callClosedFinishedCallback = function(watching) {
watching.close.getCall(0).args[0]();
};
describe("close", () => {
let callback;
const callClosedFinishedCallback = (watching) => watching.close.getCall(0).args[0]();
beforeEach(function() {
beforeEach(() => {
callback = sinon.spy();
myMultiWatching.close(callback);
});
it('closes each watching', function() {
it("closes each watching", () => {
watchings[0].close.callCount.should.be.exactly(1);
watchings[1].close.callCount.should.be.exactly(1);
});
it('calls callback after each watching has closed', function() {
it("calls callback after each watching has closed", () => {
callClosedFinishedCallback(watchings[0]);
callClosedFinishedCallback(watchings[1]);
callback.callCount.should.be.exactly(1);