Rewrite Spec & allow Jasmine to be namespaced

- THere seems to be a performance regression. Large test suites may
  throw
- Regressions: Mock Clock won't install correctly, async specs are
  temporarily not supported.
- Async spec runs/waits interface is gone. Blocks are gone.
- Move most global usage into jasmine.Env constructor.
- Remove optional 'Jasmine running' from HtmlReporter -- caused
  NS_FACTORY_ERROR in firefox when tested
This commit is contained in:
Davis W. Frank & Rajan Agaskar
2012-12-05 09:37:05 -08:00
parent 779dee1211
commit a1011e7748
44 changed files with 1343 additions and 2586 deletions

View File

@@ -1,4 +1,9 @@
describe('Spies', function () {
var env;
beforeEach(function() {
env = new jasmine.Env();
});
it('should replace the specified function with a spy object', function() {
var originalFunctionWasCalled = false;
var TestClass = {
@@ -6,11 +11,13 @@ describe('Spies', function () {
originalFunctionWasCalled = true;
}
};
this.spyOn(TestClass, 'someFunction');
env.spyOn(TestClass, 'someFunction');
expect(TestClass.someFunction.wasCalled).toEqual(false);
expect(TestClass.someFunction.callCount).toEqual(0);
TestClass.someFunction('foo');
expect(TestClass.someFunction.wasCalled).toEqual(true);
expect(TestClass.someFunction.callCount).toEqual(1);
expect(TestClass.someFunction.mostRecentCall.args).toEqual(['foo']);
@@ -29,7 +36,7 @@ describe('Spies', function () {
originalFunctionWasCalled = true;
}
};
this.spyOn(TestClass, 'someFunction');
env.spyOn(TestClass, 'someFunction');
TestClass.someFunction('foo');
TestClass.someFunction('bar');
@@ -51,7 +58,7 @@ describe('Spies', function () {
}
};
this.spyOn(TestClass, 'someFunction').andCallThrough();
env.spyOn(TestClass, 'someFunction').andCallThrough();
var result = TestClass.someFunction('arg1', 'arg2');
expect(result).toEqual("return value from original function");
expect(originalFunctionWasCalled).toEqual(true);
@@ -69,7 +76,7 @@ describe('Spies', function () {
}
};
this.spyOn(TestClass, 'someFunction').andReturn("some value");
env.spyOn(TestClass, 'someFunction').andReturn("some value");
originalFunctionWasCalled = false;
var result = TestClass.someFunction('arg1', 'arg2');
expect(result).toEqual("some value");
@@ -85,7 +92,7 @@ describe('Spies', function () {
}
};
this.spyOn(TestClass, 'someFunction').andThrow(new Error('fake error'));
env.spyOn(TestClass, 'someFunction').andThrow(new Error('fake error'));
var exception;
try {
TestClass.someFunction('arg1', 'arg2');
@@ -108,7 +115,7 @@ describe('Spies', function () {
}
};
this.spyOn(TestClass, 'someFunction').andCallFake(function() {
env.spyOn(TestClass, 'someFunction').andCallFake(function() {
fakeFunctionWasCalled = true;
passedArgs = arguments;
passedObj = this;
@@ -124,41 +131,54 @@ describe('Spies', function () {
expect(TestClass.someFunction.wasCalled).toEqual(true);
});
it('is torn down when this.removeAllSpies is called', function() {
var originalFunctionWasCalled = false;
var TestClass = {
it('is torn down when env.removeAllSpies is called', function() {
var originalFunctionWasCalled = false,
env = new jasmine.Env(),
TestClass = {
someFunction: function() {
originalFunctionWasCalled = true;
}
};
this.spyOn(TestClass, 'someFunction');
env.spyOn(TestClass, 'someFunction');
TestClass.someFunction('foo');
expect(originalFunctionWasCalled).toEqual(false);
this.removeAllSpies();
env.removeAllSpies();
TestClass.someFunction('foo');
expect(originalFunctionWasCalled).toEqual(true);
});
it('calls removeAllSpies during spec finish', function() {
var test = new jasmine.Spec(new jasmine.Env(), {}, 'sample test');
var env = new jasmine.Env(),
originalFoo = function() {},
testObj = {
foo: originalFoo
},
firstSpec = originalJasmine.createSpy('firstSpec').andCallFake(function() {
env.spyOn(testObj, 'foo');
}),
secondSpec = originalJasmine.createSpy('secondSpec').andCallFake(function() {
expect(testObj.foo).toBe(originalFoo);
});
env.describe('test suite', function() {
env.it('spec 0', firstSpec);
env.it('spec 1', secondSpec);
});
this.spyOn(test, 'removeAllSpies');
test.finish();
expect(test.removeAllSpies).wasCalled();
env.execute();
expect(firstSpec).toHaveBeenCalled();
expect(secondSpec).toHaveBeenCalled();
});
it('throws an exception when some method is spied on twice', function() {
var TestClass = { someFunction: function() {
} };
this.spyOn(TestClass, 'someFunction');
env.spyOn(TestClass, 'someFunction');
var exception;
try {
this.spyOn(TestClass, 'someFunction');
env.spyOn(TestClass, 'someFunction');
} catch (e) {
exception = e;
}
@@ -166,23 +186,23 @@ describe('Spies', function () {
});
it('to spy on an undefined method throws exception', function() {
var TestClass = {
someFunction : function() {
}
};
function efunc() {
this.spyOn(TestClass, 'someOtherFunction');
};
expect(function() {
efunc();
}).toThrow('someOtherFunction() method does not exist');
it('to spy on an undefined method throws exception', function() {
var TestClass = {
someFunction : function() {
}
};
function efunc() {
env.spyOn(TestClass, 'someOtherFunction');
};
expect(function() {
efunc();
}).toThrow('someOtherFunction() method does not exist');
});
});
it('should be able to reset a spy', function() {
var TestClass = { someFunction: function() {} };
this.spyOn(TestClass, 'someFunction');
env.spyOn(TestClass, 'someFunction');
expect(TestClass.someFunction).not.toHaveBeenCalled();
TestClass.someFunction();