Adds new configuration option to failSpecWithNoExpectations that will report specs without expectations as failures if enabled

This commit is contained in:
Dmitriy T
2019-08-22 16:08:43 -04:00
committed by Steve Gravrock
parent e8870db8d3
commit 7263a38c3f
9 changed files with 172 additions and 48 deletions

View File

@@ -296,7 +296,7 @@ describe('TreeProcessor', function() {
queueRunner.calls.mostRecent().args[0].queueableFns[0].fn('foo');
expect(leaf.execute).toHaveBeenCalledWith('foo', false);
expect(leaf.execute).toHaveBeenCalledWith('foo', false, false);
});
it('runs a node with no children', function() {
@@ -368,10 +368,10 @@ describe('TreeProcessor', function() {
expect(queueableFns.length).toBe(3);
queueableFns[1].fn('foo');
expect(leaf1.execute).toHaveBeenCalledWith('foo', false);
expect(leaf1.execute).toHaveBeenCalledWith('foo', false, false);
queueableFns[2].fn('bar');
expect(leaf2.execute).toHaveBeenCalledWith('bar', false);
expect(leaf2.execute).toHaveBeenCalledWith('bar', false, false);
});
it('cascades errors up the tree', function() {
@@ -397,7 +397,7 @@ describe('TreeProcessor', function() {
expect(queueableFns.length).toBe(2);
queueableFns[1].fn('foo');
expect(leaf.execute).toHaveBeenCalledWith('foo', false);
expect(leaf.execute).toHaveBeenCalledWith('foo', false, false);
queueRunner.calls.mostRecent().args[0].onComplete('things');
expect(nodeComplete).toHaveBeenCalled();
@@ -433,7 +433,7 @@ describe('TreeProcessor', function() {
expect(nodeStart).toHaveBeenCalledWith(node, 'bar');
queueableFns[1].fn('foo');
expect(leaf1.execute).toHaveBeenCalledWith('foo', true);
expect(leaf1.execute).toHaveBeenCalledWith('foo', true, false);
node.getResult.and.returnValue({ im: 'disabled' });
@@ -445,6 +445,35 @@ describe('TreeProcessor', function() {
);
});
it('should execute node with correct arguments when failSpecWithNoExpectations option is set', function() {
var leaf = new Leaf(),
node = new Node({ children: [leaf] }),
root = new Node({ children: [node] }),
queueRunner = jasmine.createSpy('queueRunner'),
nodeStart = jasmine.createSpy('nodeStart'),
nodeComplete = jasmine.createSpy('nodeComplete'),
processor = new jasmineUnderTest.TreeProcessor({
tree: root,
runnableIds: [],
queueRunnerFactory: queueRunner,
nodeStart: nodeStart,
nodeComplete: nodeComplete,
failSpecWithNoExpectations: true
}),
treeComplete = jasmine.createSpy('treeComplete'),
nodeDone = jasmine.createSpy('nodeDone');
processor.execute(treeComplete);
var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
queueableFns[0].fn(nodeDone);
queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
expect(queueableFns.length).toBe(2);
queueableFns[1].fn('foo');
expect(leaf.execute).toHaveBeenCalledWith('foo', true, true);
});
it('runs beforeAlls for a node with children', function() {
var leaf = new Leaf(),
node = new Node({
@@ -600,11 +629,11 @@ describe('TreeProcessor', function() {
queueableFns[0].fn();
expect(nonSpecified.execute).not.toHaveBeenCalled();
expect(specified.execute).toHaveBeenCalledWith(undefined, false);
expect(specified.execute).toHaveBeenCalledWith(undefined, false, false);
queueableFns[1].fn();
expect(nonSpecified.execute).toHaveBeenCalledWith(undefined, true);
expect(nonSpecified.execute).toHaveBeenCalledWith(undefined, true, false);
});
it('runs nodes and leaves with a specified order', function() {

View File

@@ -2138,6 +2138,41 @@ describe("Env integration", function() {
});
});
describe('when spec has no expectations', function() {
var env, reporter;
beforeEach(function() {
env = new jasmineUnderTest.Env();
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
env.addReporter(reporter);
env.it('is a spec without any expectations', function() {
// does nothing, just a mock spec without expectations
});
});
it('should report "failed" status if "failSpecWithNoExpectations" is enabled', function(done) {
reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('failed');
done();
});
env.configure({ failSpecWithNoExpectations: true });
env.execute();
});
it('should report "passed" status if "failSpecWithNoExpectations" is disabled', function(done) {
reporter.jasmineDone.and.callFake(function(e) {
expect(e.overallStatus).toEqual('passed');
done();
});
env.configure({ failSpecWithNoExpectations: false });
env.execute();
});
});
describe('When a top-level beforeAll fails', function() {
it('is "failed"', function(done) {
var env = new jasmineUnderTest.Env(),

View File

@@ -62,19 +62,19 @@ describe('HtmlReporter', function() {
});
describe('when a spec is done', function() {
it('logs errors to the console and prints a special symbol if it is an empty spec', function() {
if (typeof console === 'undefined') {
console = { warn: function() {} };
}
describe('and no expectations ran', function() {
var container, reporter;
beforeEach(function() {
if (typeof console === 'undefined') {
console = { warn: function() {}, error: function() {} };
}
var env = new jasmineUnderTest.Env(),
container = document.createElement('div'),
getContainer = function() {
return container;
},
container = document.createElement('div');
reporter = new jasmineUnderTest.HtmlReporter({
env: env,
getContainer: getContainer,
env: new jasmineUnderTest.Env(),
getContainer: function() {
return container;
},
createElement: function() {
return document.createElement.apply(document, arguments);
},
@@ -83,21 +83,39 @@ describe('HtmlReporter', function() {
}
});
spyOn(console, 'warn');
spyOn(console, 'warn');
spyOn(console, 'error');
reporter.initialize();
reporter.specDone({
status: 'passed',
fullName: 'Some Name',
passedExpectations: [],
failedExpectations: []
reporter.initialize();
});
it('should log warning to the console and print a special symbol when empty spec status is passed', function() {
reporter.specDone({
status: 'passed',
fullName: 'Some Name',
passedExpectations: [],
failedExpectations: []
});
expect(console.warn).toHaveBeenCalledWith(
"Spec 'Some Name' has no expectations."
);
var specEl = container.querySelector('.jasmine-symbol-summary li');
expect(specEl.getAttribute('class')).toEqual('jasmine-empty');
});
it('should log error to the console and print a failure symbol when empty spec status is failed', function() {
reporter.specDone({
status: 'failed',
fullName: 'Some Name',
passedExpectations: [],
failedExpectations: []
});
expect(console.error).toHaveBeenCalledWith(
"Spec 'Some Name' has no expectations."
);
var specEl = container.querySelector('.jasmine-symbol-summary li');
expect(specEl.getAttribute('class')).toEqual('jasmine-failed');
});
expect(console.warn).toHaveBeenCalledWith(
"Spec 'Some Name' has no expectations."
);
var specEl = container.querySelector('.jasmine-symbol-summary li');
expect(specEl.getAttribute('class')).toEqual('jasmine-empty');
});
it('reports the status symbol of a excluded spec', function() {