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

Prevent early return (before assertion) in QUnit test #27

Closed
platinumazure opened this issue Apr 3, 2016 · 1 comment
Closed

Prevent early return (before assertion) in QUnit test #27

platinumazure opened this issue Apr 3, 2016 · 1 comment
Assignees
Milestone

Comments

@platinumazure
Copy link
Collaborator

The purpose of this rule is to prevent unit tests from returning early (even conditionally) if there are still assertions further in the test code. If a test may need to return early, this is a sign that the test either is testing nondeterministically (in which case the test or code should be refactored to support deterministic testing), or that the entire test might need to be skipped in certain conditions.

The following example is a problem under this rule:

QUnit.test("test", function (assert) {
    if (true) {
        return;
    }
    assert.ok(false);
});

The following examples are not problems under this rule:

if (condition) {
    QUnit.test("test", function (assert) {
        assert.ok(false);
    });
}

QUnit[condition ? "test" : "skip"]("a test", function (assert) {
    assert.ok(false);
});
@platinumazure
Copy link
Collaborator Author

For now, we can report on any ReturnStatement in a test as long as it is not in a new function scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant