alsatian icon indicating copy to clipboard operation
alsatian copied to clipboard

TestCase mutable properties display issue

Open cdibbs opened this issue 5 years ago • 2 comments

As of 2.3.0, a test whose TestCase contains an object that gets modified during the test run will display the final value of the object, if the test fails. This hinders identification of the failed test case.

import { Test, TestCase, Expect, FocusTests } from "alsatian";

@FocusTests
export class Thingy {
    @TestCase({a: false})
    @Test()
    atest(dict: any) {
        new SomethingToTest().amethod(dict);
        Expect(dict).toBeNull();
    }
}

export class SomethingToTest {
    amethod(dict: any) {
        dict["a"] = true;
    }
}

Results in the output:

# FIXTURE Thingy
not ok 24 atest ( {"a":true} )
...

But, a should be false. An obvious fix/workaround is just to clone the object before sending it into the test/tested method.

cdibbs avatar Sep 09 '18 00:09 cdibbs

Good spot @cdibbs probably a bit longer standing than 2.3.0 but a bug nonetheless, I'm currently working on a revamp for 3.0.0 and will try and sneak this in too since should be quite easy :) if it's urgent for you though I am of course as always open to PRs 👍

jamesadarich avatar Sep 09 '18 09:09 jamesadarich

Sweet! Can't wait to try it out. This particular issue has been a minor, cosmetic nuisance, so far, but if it bugs me too much, I'll send a PR your way. :-) Thanks!

cdibbs avatar Sep 09 '18 17:09 cdibbs