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

Definition of Pending #63

Closed
1-0-1 opened this issue May 30, 2018 · 5 comments
Closed

Definition of Pending #63

1-0-1 opened this issue May 30, 2018 · 5 comments

Comments

@1-0-1
Copy link

1-0-1 commented May 30, 2018

When tests are marked pending programmatically in Jasmine, the pending status doesn't get set. They are considered fails but many would like to see them in the Pending list. After searching for solutions to report these the "right" way when run, the best I came up with was extending a jasmine spec reporter to report out to the console that these items should be reported as pending. Can similar logic be applied with this report?

This is a code snippet from this work around. The failedExpectation messages are all prefixed with "Failed: => marked Pending" and then whatever message is supplied by the pending('Pending reason') call.

jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
let PendingSpecReporter = SpecReporter;

PendingSpecReporter.prototype.specDone = function (spec) {
    this.metrics.stopSpec(spec);
    var pending = false;
    for (var i = 0; i < spec.failedExpectations.length; i++) {
        if (spec.failedExpectations[i].message.toLowerCase().indexOf('pending') >= 0) {
            pending = true;
            spec.pendingReason = spec.failedExpectations[i].message;
        }
    }
    if (spec.status === 'pending' || pending) {
        this.metrics.pendingSpecs++;
        this.display.pending(spec);
    } else if (spec.status === 'passed') {
        this.metrics.successfulSpecs++;
        this.display.successful(spec);
    } else if (spec.status === 'failed') {
        this.metrics.failedSpecs++;
        this.display.failed(spec);
    }
};

module.exports = PendingSpecReporter;
@Evilweed
Copy link
Owner

Evilweed commented Jun 4, 2018

@1-0-1 Can You prepare small spec that reproduces the issue, and can You show current outcome and desired outcome?

PS. Are you using "xit" "xdescribe" or "pending();"?
It's strange because last time i was checking "xit" "xdescribe" was working properly - marking as pending in report.

@1-0-1
Copy link
Author

1-0-1 commented Jun 4, 2018

Yes, this happens when using pending(), they are counted as failures. This is a known Jasmine/Protractor issue. The code snippet above is the going work around for this when searching for a work around to the issue (angular/jasminewd#32).
The result of calling pending() in a test is a failure with the text "Failed: => marked Pending". If a description is passed in the pending() call, then it is appended to this text.
Then workaround looks at the failedExpectations messages and looks to see if "pending" is there and then counts the test as pending instead of a failure.

@miller45
Copy link
Collaborator

@1-0-1 first i thought the workaround above could be used with beautiful reporter but this is not possible because internally the could is wrapped with some "ayncflow polyfills"...

I "posted" a solution for the problem by using the jasmine2MetaDataBuilder which was undocumented until now. The solution is now in the standard README.md. You can see it if you go back to the splash screen of protractor-beautiful-reporter and search for the keyword "jasmine2MetaDataBuilder".

BTW:
It is "sad" that jasmine guys have not "fixed" this issue after 2.5 years. (though there are commits with fixes). But it could also be that these fixes are not released yet (it happend before with other issues).

@miller45
Copy link
Collaborator

Posted the workaround in our readme...the underlying problem should be fixed by jasmine

@1-0-1
Copy link
Author

1-0-1 commented Aug 21, 2018

Close. The issue is when a message is passed in the pending argument, the string is no longer matching. If you change the comparison to an includes comparison, it works. Thanks for following up with this.

results.failedExpectations[0].message.indexOf('Failed: => marked Pending') >= 0
or
results.failedExpectations[0].message.includes('Failed: => marked Pending')

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