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

beforeEach(...) skips error when using function references #944

Closed
mpiasta-ca opened this issue Oct 16, 2015 · 2 comments
Closed

beforeEach(...) skips error when using function references #944

mpiasta-ca opened this issue Oct 16, 2015 · 2 comments

Comments

@mpiasta-ca
Copy link

If I use a function reference in my beforeEach(...), and that function throws an error, the test continues to execute as-if there was no problem. In some cases, this skips the it(...) blocks from executing altogether without throwing any indication that something wrong happened.

ie. a case like this:

var myVariable;

beforeEach(setupMyTest);

it('Should be equal to "fail" string', function () {
  expect(myVariable).toEqual('fail');
});

///

function setupMyTest () {
  myVariable = fail;
}

Where-as if I use a function block, the error is echoed to console and shows the tests as failed:

var myVariable;

beforeEach(function () {
  myVariable = fail;
});

it('Should be equal to "fail" string', function () {
  expect(myVariable).toEqual('fail');
});

I use the first pattern for writing tests because it is much cleaner to read and follow, when there is a large series of tests. But there are cases where a bug goes undetected as a result of the error being silenced.

@slackersoft
Copy link
Member

What version of jasmine are you using? When I try either version with 2.3, I always get this error:

Expected Function to equal 'fail'.

This is because the fail function was introduced in jasmine 2.1.0, so it will be defined.

When I switch fail to something undefined, I see two failures, one from the beforeEach and one from the it:

ReferenceError: thing is not defined
Expected undefined to equal 'fail'.

@Gerg
Copy link
Contributor

Gerg commented Sep 27, 2016

Closing due to inactivity

@Gerg Gerg closed this as completed Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants