Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install Mocha's global error handler in each test's iframe #140

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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