Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cannot capture UpdateExpression like ++foo #32

Closed
falsandtru opened this issue Nov 9, 2015 · 2 comments
Closed

Cannot capture UpdateExpression like ++foo #32

falsandtru opened this issue Nov 9, 2015 · 2 comments
Labels

Comments

@falsandtru
Copy link
Contributor

class C {
  count_ = {};
  count() {
    return this.count_;
  }
}
var counter = new C();
assert(++counter.count_ === counter.count());

expected:

          assert(++counter.count_ === counter.count())
                 | |       |      |   |       |
                 | |       |      |   |       Object{}
                 | |       |      |   C{count_:#Object#}
                 | |       |      false
                 | |       Object{}
                 | C{count_:#Object#}
                 NaN

actual:

          assert(++counter.count_ === counter.count())
                 |                |   |       |
                 |                |   |       NaN
                 |                |   C{count_:NaN}
                 NaN              false

other:

          assert(+counter.count_ === counter.count())
                 ||       |      |   |       |
                 ||       |      |   |       Object{}
                 ||       |      |   C{count_:#Object#}
                 ||       |      false
                 ||       Object{}
                 |C{count_:#Object#}
                 NaN

@falsandtru falsandtru changed the title Incorrect increment/decrement assertion messages Incomplete increment/decrement assertion messages Nov 9, 2015
@twada
Copy link
Member

twada commented Nov 9, 2015

Hi, thank you for reporting.

Unfortunately, it's a limitation of power-assert. I cannot support UpdateExpression since it causes ReferenceError.

Let me explain. Given example.js,

'use strict';

function capt (val) {
    return val;
}

var counter = {
    count: 0
};

console.log(++counter.count); // => 1
console.log(capt(++capt(capt(counter).count)));  // => ReferenceError

results in ReferenceError when executed.

$ node example.js
1
~/src/github.com/power-assert-js/power-assert/example.js:12
console.log(capt(++capt(capt(counter).count)));
                   ^
ReferenceError: Invalid left-hand side expression in prefix operation
    at Object.<anonymous> (~/src/github.com/power-assert-js/power-assert/example.js:12:20)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3
$

capt function is what power-assert is doing internally, so when I tried to capture UpdateExpression like ++foo, it always result in ReferenceError.

Since test tool should not change behavior of SUT (System Under Test), I gave up supporting UpdateExpression.

Sorry for inconvenience. I'll write about this limitation to FAQ section in REAME. Thanks!

@twada twada closed this as completed Nov 9, 2015
twada added a commit that referenced this issue Nov 9, 2015
@falsandtru
Copy link
Contributor Author

I understand, thanks!

@twada twada changed the title Incomplete increment/decrement assertion messages Cannot capture UpdateExpression like ++foo May 28, 2016
@twada twada added the wontfix label Jun 10, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants