Skip to content

Commit

Permalink
Pass iframe errors up to the parent error handler (if there is one).
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr0grog authored and jfirebaugh committed May 28, 2013
1 parent f3145f5 commit f7fc286
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/assets/javascripts/konacha/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ window.Konacha = {
}
};

// Push errors to parent iframe.
window.onerror = function() {
if (parent.onerror) {
return parent.onerror.apply(parent, arguments);
}
};

window.Mocha = Object.create(parent.Mocha);
window.mocha = Object.create(parent.mocha);

Expand Down
9 changes: 9 additions & 0 deletions spec/dummy/spec/javascripts/failing_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ describe("failure", function(){
// throwing real Error objects.
throw new Error("this one errors out");
});

it("errors asynchronously", function(done) {
setTimeout(function() {
(2 + 2).should.equal(5);
}, 0);
setTimeout(function() {
done();
}, 10);
});
});
15 changes: 15 additions & 0 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@
'error' => {'message' => 'this one errors out', 'name' => 'Error'}}}
end

let(:error_async) do
{'event' => 'fail',
'type' => 'test',
'data' => {
'title' => 'errors asynchronously',
'fullTitle' => 'failure errors asynchronously',
'parentFullTitle' => 'failure',
'status' => 'failed',
'path' => 'failing_spec.js',
# Accept anything for 'message' since async errors have URLs, which
# vary on every run, and line #, which may change in Chai releases.
'error' => {'message' => anything(), 'name' => 'Error'}}}
end

let(:pass) do
{'event' => 'pass',
'type' => 'test',
Expand Down Expand Up @@ -122,6 +136,7 @@
subject.reporter.should_receive(:process_mocha_event).with(test)
subject.reporter.should_receive(:process_mocha_event).with(failure)
subject.reporter.should_receive(:process_mocha_event).with(error)
subject.reporter.should_receive(:process_mocha_event).with(error_async)
subject.reporter.should_receive(:process_mocha_event).with(pass)
subject.reporter.should_receive(:process_mocha_event).with(pending)
subject.reporter.should_receive(:process_mocha_event).with(end_event)
Expand Down

0 comments on commit f7fc286

Please sign in to comment.