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

Getting different results depending on how test is run #1

Open
JeffML opened this issue Dec 6, 2018 · 4 comments
Open

Getting different results depending on how test is run #1

JeffML opened this issue Dec 6, 2018 · 4 comments

Comments

@JeffML
Copy link

JeffML commented Dec 6, 2018

I have this set up before my mocha tests:

import chai from 'chai';
import chaiAlmost from 'chai-almost';

// some test values are approximately equal to spreadsheet values; see NOTE on materialsCost()
const TOLERANCE = 0.0501;          // +/- cents
chai.use(chaiAlmost(TOLERANCE));

chai.should();
describe("quantity 1000, 4x1, black & blue, adh free=2", function () {...

And later I have an assertion:

    it('displayPrice', done => {
        instance.displayPrice(fakeContext)
        props.should.have.property('displayPrice');
        props.displayPrice.should.almost.equal(1953.19); 
        console.log({displayPrice: props.displayPrice})
        done();
    })

When running the test singly, the output is:

{ displayPrice: 1953.24 }
✓ displayPrice

43 passing (326ms)

However, when run the whole series of 8 test files, I see this:
2) quantity 1000, 4x1, black & blue, adh free=2

   displayPrice:

  AssertionError: expected 1953.24 to almost equal 1953.19
  + expected - actual

  -1953.24
  +1953.19

Not sure how that is possible.

@JeffML
Copy link
Author

JeffML commented Dec 6, 2018

Moved the console.log statement above the almost check and threw in TOLERANCE:

it('displayPrice', done => {
    instance.displayPrice(fakeContext)
    props.should.have.property('displayPrice');
    console.log({TOLERANCE, displayPrice: props.displayPrice})
    props.displayPrice.should.almost.equal(1953.19); 
    done();
})

The multi-file test run is now:

{ TOLERANCE: 0.0501, displayPrice: 1953.24 }
1) displayPrice
...

  1. quantity 1000, 4x1, black & blue, adh free=2
    displayPrice:

    AssertionError: expected 1953.24 to almost equal 1953.19

    • expected - actual

    -1953.24
    +1953.19

Also, there was another failure just before this one, again related to tolerance, but it disappeared durin this test run.

@JeffML
Copy link
Author

JeffML commented Dec 6, 2018

Refined this a bit further, and moved the console output to the actual failure output.

    const trace = {TOLERANCE, displayPrice: props.displayPrice}
    props.displayPrice.should.almost.equal(1953.19, JSON.stringify(trace));

seeing this now:

  1. quantity 1000, 4x1, black & blue, adh free=2
    displayPrice:

    AssertionError: {"TOLERANCE":0.0501,"displayPrice":1953.24}: expected 1953.24 to almost equal 1953.19

    • expected - actual

    -1953.24
    +1953.19

@JeffML
Copy link
Author

JeffML commented Dec 6, 2018

Okay, this seems to be related to the test file name. If I change it from this:
quantity1000_4x1_black-blue_adhfree2.js
to
testy.js

all tests pass, whether run solo or with others.

Could be a mocha issue.

@JeffML JeffML closed this as completed Dec 6, 2018
@JeffML JeffML reopened this Dec 6, 2018
@JeffML
Copy link
Author

JeffML commented Dec 6, 2018

I take it back. Worked once, now failing again with file name change.

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

1 participant