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

Tests emitting false positives - Success vs Failure #1

Open
rodolfoprr opened this issue Aug 29, 2017 · 1 comment
Open

Tests emitting false positives - Success vs Failure #1

rodolfoprr opened this issue Aug 29, 2017 · 1 comment

Comments

@rodolfoprr
Copy link

rodolfoprr commented Aug 29, 2017

hi @vvgomes :)

we noticed that all tests related to success or failure are emitting false positive, for example, this one https://github.com/vvgomes/predicado/blob/master/test/predicado.test.js#L26 if you change from Success to Failure:

assert.deepEqual(
  validateUser(user),
  Failure(user)
);

Here's a few experiments with the REPL:

> const {Success, Failure} = require("data.validation")
> const assert = require("assert");

> assert.equal(Success(1), Success(1));
AssertionError [ERR_ASSERTION]: Validation { value: 1 } == Validation { value: 1 }
    at 

> assert.deepEqual(Success(1), Success(1));
undefined

> assert.equal(Failure(1), Success(1));
AssertionError [ERR_ASSERTION]: Validation { value: 1 } == Validation { value: 1 }
    at 

> assert.deepEqual(Failure(1), Success(1));
undefined

> Success(1).toString();
'Validation.Success(1)'

> Failure(1).toString();
'Validation.Failure(1)'

> console.log(Success(1));
Validation { value: 1 }

> console.log(Failure(1));
Validation { value: 1 }

Notice that deepEqual considers Failure and Success to be, well, equal… when we expect it to fail. We've tested it with the expect.js assertion library and could reproduce the issue. Also note that the .toString() for both Failure and Success return reasonable strings, while logging them with console prints the exact same string.

Just wanted to bring it to your attention, given we're doing some exercises using data.validation and thought you might have faced this…

Thanks!

cc/ @gtramontina @ronaldotijucas @alabeduarte

@vvgomes
Copy link
Owner

vvgomes commented Aug 29, 2017

Good catch @rodolfoprr. It seems deepEqual sees both Success and Failure as "objects". I'll work on that.

Thanks!
-v

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