runner-wide beforeEach, afterEach support
This commit is contained in:
@@ -72,7 +72,7 @@ describe('Exceptions:', function() {
|
||||
});
|
||||
});
|
||||
|
||||
var runner = env.currentRunner;
|
||||
var runner = env.currentRunner();
|
||||
suite.execute();
|
||||
fakeTimer.tick(2500);
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('jasmine.Reporter', function() {
|
||||
runnerCallback: runnerCallback
|
||||
});
|
||||
|
||||
var runner = env.currentRunner;
|
||||
var runner = env.currentRunner();
|
||||
runner.execute();
|
||||
|
||||
expect(foo).toEqual(3); // 'foo was expected to be 3, was ' + foo);
|
||||
|
||||
@@ -12,6 +12,70 @@ describe('RunnerTest', function() {
|
||||
env.clearInterval = fakeTimer.clearInterval;
|
||||
});
|
||||
|
||||
describe('beforeEach', function() {
|
||||
it('should run before each spec for all suites', function () {
|
||||
var foo;
|
||||
env.beforeEach(function () {
|
||||
foo = 0;
|
||||
});
|
||||
|
||||
env.describe('suite 1', function () {
|
||||
env.it('test 1-1', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
env.it('test 1-2', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('suite 2', function () {
|
||||
env.it('test 2-1', function() {
|
||||
foo++;
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner().execute();
|
||||
|
||||
var runnerResults = env.currentRunner().results();
|
||||
expect(runnerResults.totalCount).toEqual(3);
|
||||
expect(runnerResults.passedCount).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('afterEach', function() {
|
||||
it('should run after each spec for all suites', function () {
|
||||
var foo = 3;
|
||||
env.afterEach(function () {
|
||||
foo = foo - 1;
|
||||
});
|
||||
|
||||
env.describe('suite 1', function () {
|
||||
env.it('test 1-1', function() {
|
||||
this.expect(foo).toEqual(3);
|
||||
});
|
||||
env.it('test 1-2', function() {
|
||||
this.expect(foo).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('suite 2', function () {
|
||||
env.it('test 2-1', function() {
|
||||
this.expect(foo).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner().execute();
|
||||
|
||||
var runnerResults = env.currentRunner().results();
|
||||
expect(runnerResults.totalCount).toEqual(3);
|
||||
expect(runnerResults.passedCount).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('should run child suites and specs and generate results when execute is called', function() {
|
||||
env.describe('one suite description', function () {
|
||||
env.it('should be a test', function() {
|
||||
@@ -29,9 +93,9 @@ describe('RunnerTest', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner.execute();
|
||||
env.currentRunner().execute();
|
||||
|
||||
var runnerResults = env.currentRunner.results();
|
||||
var runnerResults = env.currentRunner().results();
|
||||
expect(runnerResults.totalCount).toEqual(2);
|
||||
expect(runnerResults.passedCount).toEqual(1);
|
||||
expect(runnerResults.failedCount).toEqual(1);
|
||||
@@ -55,9 +119,9 @@ describe('RunnerTest', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner.execute();
|
||||
env.currentRunner().execute();
|
||||
|
||||
var runnerResults = env.currentRunner.results();
|
||||
var runnerResults = env.currentRunner().results();
|
||||
expect(runnerResults.totalCount).toEqual(1);
|
||||
expect(runnerResults.passedCount).toEqual(0);
|
||||
expect(runnerResults.failedCount).toEqual(1);
|
||||
@@ -80,9 +144,9 @@ describe('RunnerTest', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner.execute();
|
||||
|
||||
var results = env.currentRunner.results();
|
||||
env.currentRunner().execute();
|
||||
|
||||
var results = env.currentRunner().results();
|
||||
expect(results.totalCount).toEqual(2);
|
||||
expect(results.passedCount).toEqual(1);
|
||||
expect(results.failedCount).toEqual(1);
|
||||
@@ -113,16 +177,16 @@ describe('RunnerTest', function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.currentRunner.execute();
|
||||
env.currentRunner().execute();
|
||||
expect(fakeReporter.reportRunnerResults).wasNotCalled();
|
||||
fakeTimer.tick(200);
|
||||
//This blows up the JSApiReporter.
|
||||
//expect(fakeReporter.reportRunnerResults).wasCalledWith(env.currentRunner);
|
||||
expect(fakeReporter.reportRunnerResults).wasCalled();
|
||||
expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner.results());
|
||||
expect(fakeReporter.reportRunnerResults.mostRecentCall.args[0].results()).toEqual(env.currentRunner().results());
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
it("should report when the tests start running", function() {
|
||||
@@ -139,18 +203,19 @@ describe('RunnerTest', function() {
|
||||
var reportedRunner = fakeReporter.reportRunnerStarting.mostRecentCall.args[0];
|
||||
expect(reportedRunner.arbitraryVariable).toEqual('foo');
|
||||
expect(runner.queue.start).wasCalled();
|
||||
|
||||
|
||||
});
|
||||
|
||||
it("should return a flat array of all suites, including nested suites", function() {
|
||||
var suite1, suite2;
|
||||
suite1 = env.describe("spec 1", function() {
|
||||
suite2 = env.describe("nested spec", function() {});
|
||||
suite2 = env.describe("nested spec", function() {
|
||||
});
|
||||
});
|
||||
|
||||
document.runner = env.currentRunner;
|
||||
document.runner = env.currentRunner();
|
||||
|
||||
var suites = env.currentRunner.suites();
|
||||
var suites = env.currentRunner().suites();
|
||||
var suiteDescriptions = [];
|
||||
for (var i = 0; i < suites.length; i++) {
|
||||
suiteDescriptions.push(suites[i].getFullName());
|
||||
|
||||
@@ -864,6 +864,14 @@ describe("jasmine spec running", function () {
|
||||
it("testNestedDescribes", function() {
|
||||
var actions = [];
|
||||
|
||||
env.beforeEach(function () {
|
||||
actions.push('runner beforeEach');
|
||||
});
|
||||
|
||||
env.afterEach(function () {
|
||||
actions.push('runner afterEach');
|
||||
});
|
||||
|
||||
env.describe('Something', function() {
|
||||
env.beforeEach(function() {
|
||||
actions.push('outer beforeEach');
|
||||
@@ -914,27 +922,35 @@ describe("jasmine spec running", function () {
|
||||
|
||||
|
||||
var expected = [
|
||||
"runner beforeEach",
|
||||
"outer beforeEach",
|
||||
"outer it 1",
|
||||
"outer afterEach",
|
||||
"runner afterEach",
|
||||
|
||||
"runner beforeEach",
|
||||
"outer beforeEach",
|
||||
"inner 1 beforeEach",
|
||||
"inner 1 it",
|
||||
"inner 1 afterEach",
|
||||
"outer afterEach",
|
||||
"runner afterEach",
|
||||
|
||||
"runner beforeEach",
|
||||
"outer beforeEach",
|
||||
"outer it 2",
|
||||
"outer afterEach",
|
||||
"runner afterEach",
|
||||
|
||||
"runner beforeEach",
|
||||
"outer beforeEach",
|
||||
"inner 2 beforeEach",
|
||||
"inner 2 it",
|
||||
"inner 2 afterEach",
|
||||
"outer afterEach"
|
||||
"outer afterEach",
|
||||
"runner afterEach"
|
||||
];
|
||||
expect(env.equals_(actions, expected)).toEqual(true);
|
||||
expect(actions).toEqual(expected);
|
||||
});
|
||||
|
||||
it("builds up nested names", function() {
|
||||
@@ -963,7 +979,8 @@ describe("jasmine spec running", function () {
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('EmptySuite', function() {});
|
||||
env.describe('EmptySuite', function() {
|
||||
});
|
||||
|
||||
env.describe('NonEmptySuite2', function() {
|
||||
env.it('should pass', function() {
|
||||
@@ -973,7 +990,7 @@ describe("jasmine spec running", function () {
|
||||
|
||||
env.execute();
|
||||
|
||||
var runnerResults = env.currentRunner.results();
|
||||
var runnerResults = env.currentRunner_.results();
|
||||
expect(runnerResults.totalCount).toEqual(3);
|
||||
expect(runnerResults.passedCount).toEqual(3);
|
||||
expect(runnerResults.failedCount).toEqual(0);
|
||||
|
||||
Reference in New Issue
Block a user