Skip to content

Commit

Permalink
Fix setOptions to the ConsoleReporter if it exists on the options param
Browse files Browse the repository at this point in the history
- setOptions to the ConsoleReporter if it exists on the options param
- test setOptions should not override existing options if set multiple times

closes #95
  • Loading branch information
cnishina committed Dec 2, 2016
1 parent 6f58487 commit 1d51773
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/reporters/console_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,27 @@ function ConsoleReporter() {
onComplete = function() {};

this.setOptions = function(options) {
print = options.print;
if (options.print) {
print = options.print;
}
showColors = options.showColors || false;
timer = options.timer || noopTimer;
jasmineCorePath = options.jasmineCorePath;
printDeprecation = options.printDeprecation || require('../printDeprecation');
stackFilter = options.stackFilter || defaultStackFilter;
if (options.timer) {
timer = options.timer;
}
if (options.jasmineCorePath) {
jasmineCorePath = options.jasmineCorePath;
}
if (options.printDeprecation) {
printDeprecation = options.printDeprecation;
}
if (options.stackFilter) {
stackFilter = options.stackFilter;
}

if(options.onComplete) {
printDeprecation('Passing in an onComplete function to the ConsoleReporter is deprecated.');
onComplete = options.onComplete;
}
onComplete = options.onComplete || function() {};
};

this.jasmineStarted = function() {
Expand Down
28 changes: 28 additions & 0 deletions spec/reporters/console_reporter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ describe("ConsoleReporter", function() {
expect(this.out.getOutput()).toEqual("Started\n");
});

it("setOptions should not override existing options if set multiple times", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start']),
reporter = new ConsoleReporter();

reporter.setOptions({
print: this.out.print,
timer: timerSpy
});

reporter.jasmineStarted();
expect(timerSpy.start).toHaveBeenCalled();
expect(this.out.getOutput()).toEqual("Started\n");

// clean up this.out.output
this.out.clear();
expect(this.out.getOutput()).toEqual("");

// set options that does not include print, should still print with this.out.print
reporter.setOptions({
timer: timerSpy
});

reporter.jasmineStarted();
expect(timerSpy.start).toHaveBeenCalled();
expect(this.out.getOutput()).toEqual("Started\n");
});


it("starts the provided timer when jasmine starts", function() {
var timerSpy = jasmine.createSpyObj('timer', ['start']),
reporter = new ConsoleReporter();
Expand Down

0 comments on commit 1d51773

Please sign in to comment.