Clean up a bunch of spec global variable leaks

Also some formatting changes to highlight when using one 'var' with comma operator
This commit is contained in:
Sheel Choksi
2014-01-18 14:17:14 -08:00
parent 8ca08ff999
commit 9c7ba43ebd
10 changed files with 74 additions and 69 deletions

View File

@@ -14,7 +14,7 @@ describe("DelayedFunctionScheduler", function() {
it("schedules a string for later execution", function() {
var scheduler = new j$.DelayedFunctionScheduler(),
strfn = "horrible = true;";
strfn = "horrible = true;";
scheduler.scheduleFunction(strfn, 0);

View File

@@ -6,20 +6,20 @@ describe("Env", function() {
});
it('removes all spies when env is executed', function(done) {
originalFoo = function() {},
testObj = {
foo: originalFoo
},
firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
env.spyOn(testObj, 'foo');
}),
secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
expect(testObj.foo).toBe(originalFoo);
});
env.describe('test suite', function() {
env.it('spec 0', firstSpec);
env.it('spec 1', secondSpec);
});
var originalFoo = function() {},
testObj = {
foo: originalFoo
},
firstSpec = jasmine.createSpy('firstSpec').and.callFake(function() {
env.spyOn(testObj, 'foo');
}),
secondSpec = jasmine.createSpy('secondSpec').and.callFake(function() {
expect(testObj.foo).toBe(originalFoo);
});
env.describe('test suite', function() {
env.it('spec 0', firstSpec);
env.it('spec 1', secondSpec);
});
var assertions = function() {
expect(firstSpec).toHaveBeenCalled();

View File

@@ -35,7 +35,7 @@ describe('Exceptions:', function() {
env.it('should be a passing test that runs after exceptions are thrown from a async test', secondTest);
});
expectations = function() {
var expectations = function() {
expect(secondTest).toHaveBeenCalled();
done();
};
@@ -55,7 +55,7 @@ describe('Exceptions:', function() {
});
env.describe("a suite that doesn't throw an exception", secondDescribe);
expectations = function() {
var expectations = function() {
expect(secondDescribe).toHaveBeenCalled();
done();
};

View File

@@ -50,31 +50,31 @@ describe("QueueRunner", function() {
//createSpy('asyncfn').and.callFake(function(done) {});
var onComplete = jasmine.createSpy('onComplete'),
beforeCallback = jasmine.createSpy('beforeCallback'),
fnCallback = jasmine.createSpy('fnCallback'),
afterCallback = jasmine.createSpy('afterCallback'),
fn1 = function(done) {
beforeCallback();
setTimeout(function() {
done()
}, 100);
},
fn2 = function(done) {
fnCallback();
setTimeout(function() {
done()
}, 100);
},
fn3 = function(done) {
afterCallback();
setTimeout(function() {
done()
}, 100);
},
queueRunner = new j$.QueueRunner({
fns: [fn1, fn2, fn3],
onComplete: onComplete
});
beforeCallback = jasmine.createSpy('beforeCallback'),
fnCallback = jasmine.createSpy('fnCallback'),
afterCallback = jasmine.createSpy('afterCallback'),
fn1 = function(done) {
beforeCallback();
setTimeout(function() {
done()
}, 100);
},
fn2 = function(done) {
fnCallback();
setTimeout(function() {
done()
}, 100);
},
fn3 = function(done) {
afterCallback();
setTimeout(function() {
done()
}, 100);
},
queueRunner = new j$.QueueRunner({
fns: [fn1, fn2, fn3],
onComplete: onComplete
});
queueRunner.execute();
@@ -129,11 +129,10 @@ describe("QueueRunner", function() {
it("continues running the functions even after an exception is thrown in an async spec", function() {
var fn = function(done) { throw new Error("error"); },
nextFn = jasmine.createSpy("nextFunction");
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
});
nextFn = jasmine.createSpy("nextFunction"),
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
});
queueRunner.execute();
expect(nextFn).toHaveBeenCalled();

View File

@@ -8,7 +8,8 @@ describe("toBeGreaterThan", function() {
});
it("fails when actual <= expected", function() {
var matcher = j$.matchers.toBeGreaterThan();
var matcher = j$.matchers.toBeGreaterThan(),
result;
result = matcher.compare(1, 1);
expect(result.pass).toBe(false);

View File

@@ -9,7 +9,8 @@ describe("toBeNaN", function() {
});
it("fails for anything not a NaN", function() {
var matcher = j$.matchers.toBeNaN();
var matcher = j$.matchers.toBeNaN(),
result;
result = matcher.compare(1);
expect(result.pass).toBe(false);

View File

@@ -9,7 +9,8 @@ describe("toBeUndefined", function() {
});
it("fails when matching defined values", function() {
var matcher = j$.matchers.toBeUndefined();
var matcher = j$.matchers.toBeUndefined(),
result;
result = matcher.compare('foo');
expect(result.pass).toBe(false);

View File

@@ -3,7 +3,8 @@ describe("toContain", function() {
var util = {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
matcher = j$.matchers.toContain(util);
matcher = j$.matchers.toContain(util),
result;
result = matcher.compare("ABC", "B");
expect(util.contains).toHaveBeenCalledWith("ABC", "B", []);
@@ -15,7 +16,8 @@ describe("toContain", function() {
contains: jasmine.createSpy('delegated-contains').and.returnValue(true)
},
customEqualityTesters = ['a', 'b'],
matcher = j$.matchers.toContain(util, customEqualityTesters);
matcher = j$.matchers.toContain(util, customEqualityTesters),
result;
result = matcher.compare("ABC", "B");
expect(util.contains).toHaveBeenCalledWith("ABC", "B", ['a', 'b']);

View File

@@ -13,7 +13,8 @@ describe("toHaveBeenCalled", function() {
it("fails when the actual was not called", function() {
var matcher = j$.matchers.toHaveBeenCalled(),
uncalledSpy = j$.createSpy('uncalled spy');
uncalledSpy = j$.createSpy('uncalled spy'),
result;
result = matcher.compare(uncalledSpy);
expect(result.pass).toBe(false);

View File

@@ -326,7 +326,7 @@ describe("New HtmlReporter", function() {
beforeEach(function() {
env = new j$.Env();
container = document.createElement("div");
getContainer = function() { return container; },
var getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
env: env,
getContainer: getContainer,
@@ -377,13 +377,13 @@ describe("New HtmlReporter", function() {
beforeEach(function() {
env = new j$.Env();
container = document.createElement("div");
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
var getContainer = function() { return container; };
reporter = new j$.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.jasmineStarted({});
@@ -414,14 +414,14 @@ describe("New HtmlReporter", function() {
beforeEach(function() {
env = new j$.Env();
container = document.createElement("div"),
getContainer = function() { return container; },
reporter = new j$.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
container = document.createElement("div");
var getContainer = function() { return container; }
reporter = new j$.HtmlReporter({
env: env,
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
});
reporter.initialize();
reporter.jasmineStarted({});