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

Assertion planning #670

Closed
Turbo87 opened this issue Apr 7, 2016 · 1 comment
Closed

Assertion planning #670

Turbo87 opened this issue Apr 7, 2016 · 1 comment

Comments

@Turbo87
Copy link
Contributor

Turbo87 commented Apr 7, 2016

It might be useful to have assertion planning built into chai for async testing (see e.g. avajs/ava#25).

I currently imagine it working roughly like this:

describe('something', function() {
    afterEach(function() {
        chai.verifyPlan();
    });

    it('works', function() {
        chai.plan(2);

        return somethingAsync().then(() => {
            expect(true).to.be.true;
            expect([1, 2, 3])
                .to.contain(1)
                .to.contain(2);
        });
    });
});
  • chai.plan(n) sets an internal assertionsPlanned variable to n and resets assertionsExecuted to 0
  • each expect(...) call increments the assertionsExecuted counter
    • to make this work with the should interface we should increment in the Assertion constructor if a planned flag hasn't been set yet
  • chai.verifyPlan() compared assertionsPlanned with assertionsExecuted and throws an error if they don't match
    • chai.verifyPlan() should also reset assertionsPlanned to 0 to make it work for following tests that don't use chai.plan(n)
@keithamus
Copy link
Member

Hey @Turbo87 thanks for the issue.

We have discussed this before in #94. As per that discussion, it's a little tricky to pull off because the logic of what an "assertion" is with Chai's fluent syntax is very different to simpler test frameworks like that of Ava, Tape, Tap, Qunit et al.

Having said that, #94 is still open so we can come to a consensus, so feel free to continue the discussion there.

Closing this as its a dupe of #94

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

2 participants