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:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user