Merge branch 'beforeAll' into master
Conflicts: lib/jasmine-core/boot.js lib/jasmine-core/boot/boot.js lib/jasmine-core/jasmine.css lib/jasmine-core/jasmine.js spec/core/SpecSpec.js spec/core/SuiteSpec.js spec/core/integration/EnvSpec.js spec/node_suite.js src/core/Env.js src/core/requireCore.js src/core/util.js
This commit is contained in:
@@ -38,13 +38,13 @@ describe("Custom Matchers (Integration)", function() {
|
||||
});
|
||||
|
||||
it("passes the spec if the custom matcher passes", function(done) {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return { compare: function() { return { pass: true }; } };
|
||||
}
|
||||
});
|
||||
|
||||
env.it("spec using custom matcher", function() {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return { compare: function() { return { pass: true }; } };
|
||||
}
|
||||
});
|
||||
|
||||
env.expect(true).toBeReal();
|
||||
});
|
||||
|
||||
@@ -57,16 +57,16 @@ describe("Custom Matchers (Integration)", function() {
|
||||
});
|
||||
|
||||
it("uses the negative compare function for a negative comparison, if provided", function(done) {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return {
|
||||
compare: function() { return { pass: true }; },
|
||||
negativeCompare: function() { return { pass: true }; }
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
env.it("spec with custom negative comparison matcher", function() {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return {
|
||||
compare: function() { return { pass: true }; },
|
||||
negativeCompare: function() { return { pass: true }; }
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
env.expect(true).not.toBeReal();
|
||||
});
|
||||
|
||||
@@ -79,17 +79,17 @@ describe("Custom Matchers (Integration)", function() {
|
||||
});
|
||||
|
||||
it("generates messages with the same rules as built in matchers absent a custom message", function(done) {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
return { pass: false };
|
||||
env.it('spec with an expectation', function() {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return {
|
||||
compare: function() {
|
||||
return { pass: false };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
env.it('spec with an expectation', function() {
|
||||
env.expect("a").toBeReal();
|
||||
});
|
||||
|
||||
@@ -103,13 +103,14 @@ describe("Custom Matchers (Integration)", function() {
|
||||
|
||||
it("passes the expected and actual arguments to the comparison function", function(done) {
|
||||
var argumentSpy = jasmine.createSpy("argument spy").and.returnValue({ pass: true });
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return { compare: argumentSpy };
|
||||
}
|
||||
});
|
||||
|
||||
env.it('spec with an expectation', function () {
|
||||
env.addMatchers({
|
||||
toBeReal: function() {
|
||||
return { compare: argumentSpy };
|
||||
}
|
||||
});
|
||||
|
||||
env.expect(true).toBeReal();
|
||||
env.expect(true).toBeReal("arg");
|
||||
env.expect(true).toBeReal("arg1", "arg2");
|
||||
@@ -130,12 +131,13 @@ describe("Custom Matchers (Integration)", function() {
|
||||
argumentSpy = jasmine.createSpy("argument spy").and.returnValue(matcherFactory),
|
||||
customEqualityFn = function() { return true; };
|
||||
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.addMatchers({
|
||||
toBeReal: argumentSpy
|
||||
});
|
||||
|
||||
env.it("spec with expectation", function() {
|
||||
env.addCustomEqualityTester(customEqualityFn);
|
||||
env.addMatchers({
|
||||
toBeReal: argumentSpy
|
||||
});
|
||||
|
||||
env.expect(true).toBeReal();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,44 @@
|
||||
describe("Env integration", function() {
|
||||
beforeEach(function() {
|
||||
jasmine.addMatchers({
|
||||
toHaveFailedExpecationsForSuite: function(util, customeEqualityTesters) {
|
||||
return {
|
||||
compare: function(actual, suiteName, expectedFailures) {
|
||||
var foundSuite = false, expectations = true, foundFailures = [];
|
||||
for (var i = 0; i < actual.calls.count(); i++) {
|
||||
var args = actual.calls.argsFor(i)[0];
|
||||
|
||||
if (args.description === suiteName) {
|
||||
foundSuite = true;
|
||||
|
||||
for (var j = 0; j < args.failedExpectations.length; j++) {
|
||||
foundFailures.push(args.failedExpectations[j].message);
|
||||
}
|
||||
|
||||
for (var j = 0; j < expectedFailures.length; j++) {
|
||||
var failure = foundFailures[j];
|
||||
var expectedFailure = expectedFailures[j];
|
||||
|
||||
if (Object.prototype.toString.call(expectedFailure) === '[object RegExp]') {
|
||||
expectations = expectations && expectedFailure.test(failure);
|
||||
} else {
|
||||
expectations = expectations && failure === expectedFailure;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
pass: foundSuite && expectations,
|
||||
message: !foundSuite ? 'The suite "' + suiteName + '" never finished' :
|
||||
'Expected suite "' + suiteName + '" to have failures ' + jasmine.pp(expectedFailures) + ' but it had ' + jasmine.pp(foundFailures)
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("Suites execute as expected (no nesting)", function(done) {
|
||||
var env = new j$.Env(),
|
||||
@@ -80,7 +120,7 @@ describe("Env integration", function() {
|
||||
|
||||
env.describe("Outer suite", function() {
|
||||
env.it("an outer spec", function() {
|
||||
calls.push('an outer spec')
|
||||
calls.push('an outer spec');
|
||||
});
|
||||
env.describe("Inner suite", function() {
|
||||
env.it("an inner spec", function() {
|
||||
@@ -212,6 +252,305 @@ describe("Env integration", function() {
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("calls associated beforeAlls/afterAlls only once per suite", function(done) {
|
||||
var env = new j$.Env(),
|
||||
before = jasmine.createSpy('beforeAll'),
|
||||
after = jasmine.createSpy('afterAll');
|
||||
|
||||
env.addReporter({
|
||||
jasmineDone: function() {
|
||||
expect(after).toHaveBeenCalled();
|
||||
expect(after.calls.count()).toBe(1);
|
||||
expect(before.calls.count()).toBe(1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
env.describe("with beforeAll and afterAll", function() {
|
||||
env.it("spec", function() {
|
||||
expect(before).toHaveBeenCalled();
|
||||
expect(after).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
env.it("another spec", function() {
|
||||
expect(before).toHaveBeenCalled();
|
||||
expect(after).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
env.beforeAll(before);
|
||||
env.afterAll(after);
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("calls associated beforeAlls/afterAlls only once per suite for async", function(done) {
|
||||
var env = new j$.Env(),
|
||||
before = jasmine.createSpy('beforeAll'),
|
||||
after = jasmine.createSpy('afterAll');
|
||||
|
||||
env.addReporter({
|
||||
jasmineDone: function() {
|
||||
expect(after).toHaveBeenCalled();
|
||||
expect(after.calls.count()).toBe(1);
|
||||
expect(before.calls.count()).toBe(1);
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
env.describe("with beforeAll and afterAll", function() {
|
||||
env.it("spec", function() {
|
||||
expect(before).toHaveBeenCalled();
|
||||
expect(after).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
env.it("another spec", function() {
|
||||
expect(before).toHaveBeenCalled();
|
||||
expect(after).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
env.beforeAll(function(beforeCallbackUnderTest) {
|
||||
before();
|
||||
beforeCallbackUnderTest();
|
||||
});
|
||||
|
||||
env.afterAll(function(afterCallbackUnderTest) {
|
||||
after();
|
||||
afterCallbackUnderTest();
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("calls associated beforeAlls/afterAlls with the cascaded 'this'", function(done) {
|
||||
var env = new j$.Env();
|
||||
|
||||
env.addReporter({jasmineDone: done});
|
||||
|
||||
env.describe("with beforeAll and afterAll", function() {
|
||||
env.beforeAll(function() {
|
||||
this.x = 1;
|
||||
});
|
||||
|
||||
env.it("has an x at the root", function() {
|
||||
expect(this.x).toBe(1);
|
||||
});
|
||||
|
||||
env.describe("child that deletes", function() {
|
||||
env.beforeAll(function() {
|
||||
expect(this.x).toBe(1);
|
||||
delete this.x;
|
||||
});
|
||||
|
||||
env.it("has no x", function() {
|
||||
expect(this.x).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
env.describe("child should still have x", function() {
|
||||
env.beforeAll(function(innerDone) {
|
||||
expect(this.x).toBe(1);
|
||||
innerDone();
|
||||
});
|
||||
|
||||
env.it("has an x", function() {
|
||||
expect(this.x).toBe(1);
|
||||
delete this.x;
|
||||
});
|
||||
|
||||
env.it("still has an x", function() {
|
||||
expect(this.x).toBe(1);
|
||||
});
|
||||
|
||||
env.it("adds a y", function() {
|
||||
this.y = 2;
|
||||
expect(this.y).toBe(2);
|
||||
});
|
||||
|
||||
env.it("doesn't have y that was added in sibling", function() {
|
||||
expect(this.y).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("fails all underlying specs when the beforeAll fails", function (done) {
|
||||
var env = new j$.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(reporter.specDone.calls.count()).toEqual(2);
|
||||
|
||||
expect(reporter.specDone.calls.argsFor(0)[0])
|
||||
.toEqual(jasmine.objectContaining({status: 'failed'}));
|
||||
expect(reporter.specDone.calls.argsFor(0)[0].failedExpectations[0].message)
|
||||
.toEqual("Expected 1 to be 2.");
|
||||
|
||||
expect(reporter.specDone.calls.argsFor(1)[0])
|
||||
.toEqual(jasmine.objectContaining({status: 'failed'}));
|
||||
expect(reporter.specDone.calls.argsFor(1)[0].failedExpectations[0].message)
|
||||
.toEqual("Expected 1 to be 2.");
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe('A suite', function(){
|
||||
env.beforeAll(function() {
|
||||
env.expect(1).toBe(2);
|
||||
});
|
||||
|
||||
env.it("spec that will be failed", function() {
|
||||
});
|
||||
|
||||
env.describe("nesting", function() {
|
||||
env.it("another spec to fail", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
describe('suiteDone reporting', function(){
|
||||
it("reports when an afterAll fails an expectation", function(done) {
|
||||
var env = new j$.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
|
||||
'Expected 1 to equal 2.',
|
||||
'Expected 2 to equal 3.'
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe('my suite', function() {
|
||||
env.it('my spec', function() {
|
||||
});
|
||||
|
||||
env.afterAll(function() {
|
||||
env.expect(1).toEqual(2);
|
||||
env.expect(2).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("if there are no specs, it still reports correctly", function(done) {
|
||||
var env = new j$.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('outer suite', [
|
||||
'Expected 1 to equal 2.',
|
||||
'Expected 2 to equal 3.'
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe('outer suite', function() {
|
||||
env.describe('inner suite', function() {
|
||||
env.it('spec', function(){ });
|
||||
});
|
||||
|
||||
env.afterAll(function() {
|
||||
env.expect(1).toEqual(2);
|
||||
env.expect(2).toEqual(3);
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("reports when afterAll throws an exception", function(done) {
|
||||
var env = new j$.Env(),
|
||||
error = new Error('After All Exception'),
|
||||
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
|
||||
(/^Error: After All Exception/)
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe('my suite', function() {
|
||||
env.it('my spec', function() {
|
||||
});
|
||||
|
||||
env.afterAll(function() {
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("reports when an async afterAll fails an expectation", function(done) {
|
||||
var env = new j$.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
|
||||
'Expected 1 to equal 2.'
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe('my suite', function() {
|
||||
env.it('my spec', function() {
|
||||
});
|
||||
|
||||
env.afterAll(function(afterAllDone) {
|
||||
env.expect(1).toEqual(2);
|
||||
afterAllDone();
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("reports when an async afterAll throws an exception", function(done) {
|
||||
var env = new j$.Env(),
|
||||
error = new Error('After All Exception'),
|
||||
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
||||
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
|
||||
(/^Error: After All Exception/)
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe('my suite', function() {
|
||||
env.it('my spec', function() {
|
||||
});
|
||||
|
||||
env.afterAll(function(afterAllDone) {
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
it("Allows specifying which specs and suites to run", function(done) {
|
||||
var env = new j$.Env(),
|
||||
calls = [],
|
||||
@@ -248,21 +587,61 @@ describe("Env integration", function() {
|
||||
env.execute([secondSuite.id, firstSpec.id]);
|
||||
});
|
||||
|
||||
it("Functions can be spied on and have their calls tracked", function () {
|
||||
var env = new j$.Env();
|
||||
it('runs before and after all functions for runnables provided to .execute()', function(done) {
|
||||
var env = new j$.Env(),
|
||||
calls = [],
|
||||
first_spec,
|
||||
second_spec;
|
||||
|
||||
var originalFunctionWasCalled = false;
|
||||
var subject = {
|
||||
spiedFunc: function() {
|
||||
originalFunctionWasCalled = true;
|
||||
return "original result";
|
||||
}
|
||||
};
|
||||
var assertions = function() {
|
||||
expect(calls).toEqual([
|
||||
"before",
|
||||
"first spec",
|
||||
"after",
|
||||
"before",
|
||||
"second spec",
|
||||
"after"
|
||||
]);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.describe("first suite", function() {
|
||||
env.beforeAll(function() {
|
||||
calls.push("before");
|
||||
});
|
||||
env.afterAll(function() {
|
||||
calls.push("after")
|
||||
});
|
||||
first_spec = env.it("spec", function() {
|
||||
calls.push('first spec');
|
||||
});
|
||||
second_spec = env.it("spec 2", function() {
|
||||
calls.push("second spec");
|
||||
});
|
||||
});
|
||||
|
||||
env.execute([first_spec.id, second_spec.id]);
|
||||
});
|
||||
|
||||
it("Functions can be spied on and have their calls tracked", function (done) {
|
||||
var env = new j$.Env();
|
||||
|
||||
var originalFunctionWasCalled = false;
|
||||
var subject = {
|
||||
spiedFunc: function() {
|
||||
originalFunctionWasCalled = true;
|
||||
return "original result";
|
||||
}
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: done});
|
||||
|
||||
env.it("works with spies", function() {
|
||||
var spy = env.spyOn(subject, 'spiedFunc').and.returnValue("stubbed result");
|
||||
|
||||
expect(subject.spiedFunc).toEqual(spy);
|
||||
|
||||
expect(subject.spiedFunc.calls.any()).toEqual(false);
|
||||
expect(subject.spiedFunc.calls.count()).toEqual(0);
|
||||
|
||||
@@ -281,6 +660,67 @@ describe("Env integration", function() {
|
||||
expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
|
||||
expect(subject.spiedFunc.calls.mostRecent().returnValue).toEqual("original result");
|
||||
expect(originalFunctionWasCalled).toEqual(true);
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('removes all spies added in a spec after the spec is complete', function(done) {
|
||||
var env = new j$.Env(),
|
||||
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();
|
||||
expect(secondSpec).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({ jasmineDone: assertions });
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('removes all spies added in a suite after the suite is complete', function(done) {
|
||||
var env = new j$.Env(),
|
||||
originalFoo = function() {},
|
||||
testObj = {
|
||||
foo: originalFoo
|
||||
};
|
||||
|
||||
env.describe('test suite', function() {
|
||||
env.beforeAll(function() { env.spyOn(testObj, 'foo');})
|
||||
|
||||
env.it('spec 0', function() {
|
||||
expect(j$.isSpy(testObj.foo)).toBe(true);
|
||||
});
|
||||
|
||||
env.it('spec 1', function() {
|
||||
expect(j$.isSpy(testObj.foo)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('another suite', function() {
|
||||
env.it('spec 2', function() {
|
||||
expect(j$.isSpy(testObj.foo)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
env.addReporter({ jasmineDone: done });
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("Mock clock can be installed and used in tests", function(done) {
|
||||
@@ -345,11 +785,11 @@ describe("Env integration", function() {
|
||||
|
||||
beforeEach(function() {
|
||||
originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
|
||||
jasmine.getEnv().clock.install();
|
||||
jasmine.clock().install();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
jasmine.getEnv().clock.uninstall();
|
||||
jasmine.clock().uninstall();
|
||||
j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
});
|
||||
|
||||
@@ -371,7 +811,63 @@ describe("Env integration", function() {
|
||||
|
||||
env.it("async spec that doesn't call done", function(underTestCallback) {
|
||||
env.expect(true).toBeTruthy();
|
||||
jasmine.getEnv().clock.tick(8416);
|
||||
jasmine.clock().tick(8416);
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("should wait a specified interval before failing beforeAll's and their associated specs that haven't called done", function(done) {
|
||||
var env = new j$.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(reporter.specDone.calls.count()).toEqual(2);
|
||||
expect(reporter.specDone.calls.argsFor(0)[0]).toEqual(jasmine.objectContaining({status: 'failed'}));
|
||||
expect(reporter.specDone.calls.argsFor(1)[0]).toEqual(jasmine.objectContaining({status: 'failed'}));
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
j$.DEFAULT_TIMEOUT_INTERVAL = 1290;
|
||||
|
||||
env.beforeAll(function(done) {
|
||||
jasmine.clock().tick(1290);
|
||||
});
|
||||
|
||||
env.it("spec that will be failed", function() {
|
||||
});
|
||||
|
||||
env.describe("nesting", function() {
|
||||
env.it("another spec to fail", function() {
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("should wait the specified interval before reporting an afterAll that fails to call done", function(done) {
|
||||
var env = new j$.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
expect(reporter.suiteDone).toHaveFailedExpecationsForSuite('my suite', [
|
||||
(/^Error: Timeout - Async callback was not invoked within timeout specified by jasmine\.DEFAULT_TIMEOUT_INTERVAL\./)
|
||||
]);
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
j$.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
||||
|
||||
env.describe('my suite', function() {
|
||||
env.it('my spec', function() {
|
||||
});
|
||||
|
||||
env.afterAll(function(innerDone) {
|
||||
jasmine.clock().tick(3001);
|
||||
innerDone();
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
@@ -436,7 +932,58 @@ describe("Env integration", function() {
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: something is wrong with this spec
|
||||
describe('focused tests', function() {
|
||||
it('should only run the focused tests', function(done) {
|
||||
var env = new j$.Env(),
|
||||
calls = [];
|
||||
|
||||
var assertions = function() {
|
||||
expect(calls).toEqual(['focused']);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.describe('a suite', function() {
|
||||
env.fit('is focused', function() {
|
||||
calls.push('focused');
|
||||
});
|
||||
|
||||
env.it('is not focused', function() {
|
||||
calls.push('freakout');
|
||||
})
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('should only run focused suites', function(){
|
||||
var env = new j$.Env(),
|
||||
calls = [];
|
||||
|
||||
var assertions = function() {
|
||||
expect(calls).toEqual(['focused']);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.fdescribe('a focused suite', function() {
|
||||
env.it('is focused', function() {
|
||||
calls.push('focused');
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('a regular suite', function() {
|
||||
env.it('is not focused', function() {
|
||||
calls.push('freakout');
|
||||
})
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
it("should report as expected", function(done) {
|
||||
var env = new j$.Env(),
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||
@@ -502,11 +1049,7 @@ describe("Env integration", function() {
|
||||
it("Custom equality testers should be per spec", function(done) {
|
||||
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||
"jasmineStarted",
|
||||
"jasmineDone",
|
||||
"suiteStarted",
|
||||
"suiteDone",
|
||||
"specStarted",
|
||||
"specDone"
|
||||
]);
|
||||
|
||||
@@ -536,30 +1079,42 @@ describe("Env integration", function() {
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("Custom matchers should be per spec", function() {
|
||||
it("Custom equality testers should be per suite", function(done) {
|
||||
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
||||
matchers = {
|
||||
toFoo: function() {}
|
||||
},
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||
"jasmineStarted",
|
||||
"jasmineDone",
|
||||
"suiteStarted",
|
||||
"suiteDone",
|
||||
"specStarted",
|
||||
"specDone"
|
||||
]);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
var firstSpecResult = reporter.specDone.calls.first().args[0],
|
||||
secondSpecResult = reporter.specDone.calls.argsFor(0)[0],
|
||||
thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
|
||||
|
||||
expect(firstSpecResult.status).toEqual("passed");
|
||||
expect(secondSpecResult.status).toEqual("passed");
|
||||
expect(thirdSpecResult.status).toEqual("failed");
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe("testing custom matchers", function() {
|
||||
env.it("with a custom matcher", function() {
|
||||
env.addMatchers(matchers);
|
||||
expect(env.expect().toFoo).toBeDefined();
|
||||
env.describe("testing custom equality testers", function() {
|
||||
env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; }); });
|
||||
|
||||
env.it("with a custom tester", function() {
|
||||
env.expect("a").toEqual("b");
|
||||
});
|
||||
|
||||
env.it("without a custom matcher", function() {
|
||||
expect(env.expect().toFoo).toBeUndefined();
|
||||
env.it("with the same custom tester", function() {
|
||||
env.expect("a").toEqual("b");
|
||||
});
|
||||
});
|
||||
|
||||
env.describe("another suite", function() {
|
||||
env.it("without the custom tester", function(){
|
||||
env.expect("a").toEqual("b");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -569,11 +1124,7 @@ describe("Env integration", function() {
|
||||
it("Custom equality testers for toContain should be per spec", function(done) {
|
||||
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||
"jasmineStarted",
|
||||
"jasmineDone",
|
||||
"suiteStarted",
|
||||
"suiteDone",
|
||||
"specStarted",
|
||||
"specDone"
|
||||
]);
|
||||
|
||||
@@ -596,7 +1147,7 @@ describe("Env integration", function() {
|
||||
});
|
||||
|
||||
env.it("without a custom tester", function() {
|
||||
env.expect("a").toContain("b");
|
||||
env.expect(["a"]).toContain("b");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -616,5 +1167,166 @@ describe("Env integration", function() {
|
||||
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
it("Custom equality testers for toContain should be per suite", function(done) {
|
||||
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
||||
reporter = jasmine.createSpyObj('fakeReporter', [
|
||||
"jasmineDone",
|
||||
"specDone"
|
||||
]);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function() {
|
||||
var firstSpecResult = reporter.specDone.calls.first().args[0],
|
||||
secondSpecResult = reporter.specDone.calls.argsFor(1)[0],
|
||||
thirdSpecResult = reporter.specDone.calls.mostRecent().args[0];
|
||||
|
||||
expect(firstSpecResult.status).toEqual("passed");
|
||||
expect(secondSpecResult.status).toEqual("passed");
|
||||
expect(thirdSpecResult.status).toEqual("failed");
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
|
||||
env.describe("testing custom equality testers", function() {
|
||||
env.beforeAll(function() { env.addCustomEqualityTester(function(a, b) { return true; })});
|
||||
|
||||
env.it("with a custom tester", function() {
|
||||
env.expect(["a"]).toContain("b");
|
||||
});
|
||||
|
||||
env.it("also with the custom tester", function() {
|
||||
env.expect(["a"]).toContain("b");
|
||||
});
|
||||
});
|
||||
|
||||
env.describe("another suite", function() {
|
||||
env.it("without the custom tester", function() {
|
||||
env.expect(["a"]).toContain("b");
|
||||
});
|
||||
});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("Custom matchers should be per spec", function(done) {
|
||||
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
||||
matchers = {
|
||||
toFoo: function() {}
|
||||
};
|
||||
|
||||
env.describe("testing custom matchers", function() {
|
||||
env.it("with a custom matcher", function() {
|
||||
env.addMatchers(matchers);
|
||||
expect(env.expect().toFoo).toBeDefined();
|
||||
});
|
||||
|
||||
env.it("without a custom matcher", function() {
|
||||
expect(env.expect().toFoo).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
env.addReporter({jasmineDone: done});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("Custom matchers should be per suite", function(done) {
|
||||
var env = new j$.Env({global: { setTimeout: setTimeout }}),
|
||||
matchers = {
|
||||
toFoo: function() {}
|
||||
};
|
||||
|
||||
env.describe("testing custom matchers", function() {
|
||||
env.beforeAll(function() { env.addMatchers(matchers); });
|
||||
|
||||
env.it("with a custom matcher", function() {
|
||||
expect(env.expect().toFoo).toBeDefined();
|
||||
});
|
||||
|
||||
env.it("with the same custom matcher", function() {
|
||||
expect(env.expect().toFoo).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
env.describe("another suite", function() {
|
||||
env.it("no longer has the custom matcher", function() {
|
||||
expect(env.expect().toFoo).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
env.addReporter({jasmineDone: done});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('throws an exception if you try to create a spy outside of a runnable', function (done) {
|
||||
var env = new j$.Env(),
|
||||
obj = {fn: function () {}},
|
||||
exception;
|
||||
|
||||
env.describe("a suite", function () {
|
||||
try {
|
||||
env.spyOn(obj, 'fn');
|
||||
} catch(e) {
|
||||
exception = e;
|
||||
}
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
expect(exception.message).toBe('Spies must be created in a before function or a spec');
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('throws an exception if you try to add a matcher outside of a runnable', function (done) {
|
||||
var env = new j$.Env(),
|
||||
obj = {fn: function () {}},
|
||||
exception;
|
||||
|
||||
env.describe("a suite", function () {
|
||||
try {
|
||||
env.addMatchers({myMatcher: function(actual,expected){return false;}});
|
||||
} catch(e) {
|
||||
exception = e;
|
||||
}
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
expect(exception.message).toBe('Matchers must be added in a before function or a spec');
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('throws an exception if you try to add a custom equality outside of a runnable', function (done) {
|
||||
var env = new j$.Env(),
|
||||
obj = {fn: function () {}},
|
||||
exception;
|
||||
|
||||
env.describe("a suite", function () {
|
||||
try {
|
||||
env.addCustomEqualityTester(function(first, second) {return true;});
|
||||
} catch(e) {
|
||||
exception = e;
|
||||
}
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
expect(exception.message).toBe('Custom Equalities must be added in a before function or a spec');
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -159,7 +159,7 @@ describe("jasmine spec running", function () {
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
@@ -228,6 +228,257 @@ describe("jasmine spec running", function () {
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('should run beforeAlls before beforeEachs and afterAlls after afterEachs', function() {
|
||||
var actions = [];
|
||||
|
||||
env.beforeAll(function() {
|
||||
actions.push('runner beforeAll');
|
||||
});
|
||||
|
||||
env.afterAll(function() {
|
||||
actions.push('runner afterAll');
|
||||
});
|
||||
|
||||
env.beforeEach(function () {
|
||||
actions.push('runner beforeEach');
|
||||
});
|
||||
|
||||
env.afterEach(function () {
|
||||
actions.push('runner afterEach');
|
||||
});
|
||||
|
||||
env.describe('Something', function() {
|
||||
env.beforeEach(function() {
|
||||
actions.push('inner beforeEach');
|
||||
});
|
||||
|
||||
env.afterEach(function() {
|
||||
actions.push('inner afterEach');
|
||||
});
|
||||
|
||||
env.beforeAll(function() {
|
||||
actions.push('inner beforeAll');
|
||||
});
|
||||
|
||||
env.afterAll(function() {
|
||||
actions.push('inner afterAll');
|
||||
});
|
||||
|
||||
env.it('does something or other', function() {
|
||||
actions.push('it');
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = [
|
||||
"runner beforeAll",
|
||||
"inner beforeAll",
|
||||
"runner beforeEach",
|
||||
"inner beforeEach",
|
||||
"it",
|
||||
"inner afterEach",
|
||||
"runner afterEach",
|
||||
"inner afterAll",
|
||||
"runner afterAll"
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('should run beforeAlls and afterAlls as beforeEachs and afterEachs in the order declared when runnablesToRun is provided', function() {
|
||||
var actions = [],
|
||||
spec,
|
||||
spec2;
|
||||
|
||||
env.beforeAll(function() {
|
||||
actions.push('runner beforeAll');
|
||||
});
|
||||
|
||||
env.afterAll(function() {
|
||||
actions.push('runner afterAll');
|
||||
});
|
||||
|
||||
env.beforeEach(function () {
|
||||
actions.push('runner beforeEach');
|
||||
});
|
||||
|
||||
env.afterEach(function () {
|
||||
actions.push('runner afterEach');
|
||||
});
|
||||
|
||||
env.describe('Something', function() {
|
||||
env.beforeEach(function() {
|
||||
actions.push('inner beforeEach');
|
||||
});
|
||||
|
||||
env.afterEach(function() {
|
||||
actions.push('inner afterEach');
|
||||
});
|
||||
|
||||
env.beforeAll(function() {
|
||||
actions.push('inner beforeAll');
|
||||
});
|
||||
|
||||
env.afterAll(function() {
|
||||
actions.push('inner afterAll');
|
||||
});
|
||||
|
||||
spec = env.it('does something', function() {
|
||||
actions.push('it');
|
||||
});
|
||||
|
||||
spec2 = env.it('does something or other', function() {
|
||||
actions.push('it2');
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = [
|
||||
"runner beforeAll",
|
||||
"inner beforeAll",
|
||||
"runner beforeEach",
|
||||
"inner beforeEach",
|
||||
"it",
|
||||
"inner afterEach",
|
||||
"runner afterEach",
|
||||
"inner afterAll",
|
||||
"runner afterAll",
|
||||
|
||||
"runner beforeAll",
|
||||
"inner beforeAll",
|
||||
"runner beforeEach",
|
||||
"inner beforeEach",
|
||||
"it2",
|
||||
"inner afterEach",
|
||||
"runner afterEach",
|
||||
"inner afterAll",
|
||||
"runner afterAll"
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
env.execute([spec.id, spec2.id]);
|
||||
});
|
||||
|
||||
describe('focused runnables', function() {
|
||||
it('runs the relevant alls and eachs for each runnable', function(done) {
|
||||
var actions = [];
|
||||
env.beforeAll(function() {actions.push('beforeAll')});
|
||||
env.afterAll(function() {actions.push('afterAll')});
|
||||
env.beforeEach(function() {actions.push('beforeEach')});
|
||||
env.afterEach(function() {actions.push('afterEach')});
|
||||
|
||||
env.fdescribe('a focused suite', function() {
|
||||
env.it('is run', function() {
|
||||
actions.push('spec in fdescribe')
|
||||
});
|
||||
});
|
||||
|
||||
env.describe('an unfocused suite', function() {
|
||||
env.fit('has a focused spec', function() {
|
||||
actions.push('focused spec')
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = [
|
||||
'beforeAll',
|
||||
'beforeEach',
|
||||
'spec in fdescribe',
|
||||
'afterEach',
|
||||
'afterAll',
|
||||
|
||||
'beforeAll',
|
||||
'beforeEach',
|
||||
'focused spec',
|
||||
'afterEach',
|
||||
'afterAll'
|
||||
];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('focused specs in focused suites cause non-focused siblings to not run', function(done){
|
||||
var actions = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
env.it('unfocused spec', function() {
|
||||
actions.push('unfocused spec')
|
||||
});
|
||||
env.fit('focused spec', function() {
|
||||
actions.push('focused spec')
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = ['focused spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('focused suites in focused suites cause non-focused siblings to not run', function(done){
|
||||
var actions = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
env.it('unfocused spec', function() {
|
||||
actions.push('unfocused spec')
|
||||
});
|
||||
env.fdescribe('inner focused suite', function() {
|
||||
env.it('inner spec', function() {
|
||||
actions.push('inner spec');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = ['inner spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it('focused runnables unfocus ancestor focused suites', function() {
|
||||
var actions = [];
|
||||
|
||||
env.fdescribe('focused suite', function() {
|
||||
env.it('unfocused spec', function() {
|
||||
actions.push('unfocused spec')
|
||||
});
|
||||
env.describe('inner focused suite', function() {
|
||||
env.fit('focused spec', function() {
|
||||
actions.push('focused spec');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
var expected = ['focused spec'];
|
||||
expect(actions).toEqual(expected);
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
|
||||
it("shouldn't run disabled suites", function(done) {
|
||||
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
|
||||
suite = env.describe('A Suite', function() {
|
||||
@@ -236,10 +487,36 @@ describe("jasmine spec running", function () {
|
||||
});
|
||||
});
|
||||
|
||||
suite.execute(function() {
|
||||
var assertions = function() {
|
||||
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("should allow top level suites to be disabled", function() {
|
||||
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
|
||||
otherSpec = jasmine.createSpy("otherSpec");
|
||||
|
||||
env.xdescribe('A disabled suite', function() {
|
||||
env.it('spec inside a disabled suite', specInADisabledSuite);
|
||||
});
|
||||
env.describe('Another suite', function() {
|
||||
env.it('another spec', otherSpec);
|
||||
});
|
||||
|
||||
var assertions = function() {
|
||||
expect(specInADisabledSuite).not.toHaveBeenCalled();
|
||||
expect(otherSpec).toHaveBeenCalled();
|
||||
done();
|
||||
};
|
||||
|
||||
env.addReporter({jasmineDone: assertions});
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
it("should set all pending specs to pending when a suite is run", function(done) {
|
||||
@@ -254,7 +531,6 @@ describe("jasmine spec running", function () {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// TODO: is this useful? It doesn't catch syntax errors
|
||||
xit("should recover gracefully when there are errors in describe functions", function() {
|
||||
var specs = [];
|
||||
|
||||
Reference in New Issue
Block a user