tape-testing / tape

tap-producing test harness for node and browsers
MIT License
5.77k stars 307 forks source link

[readme] improve `t.throws` documentation #542

Closed cagross closed 3 years ago

cagross commented 3 years ago

Addresses #540.

codecov-io commented 3 years ago

Codecov Report

Merging #542 (94220ba) into master (ce0b1ad) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #542   +/-   ##
=======================================
  Coverage   74.15%   74.15%           
=======================================
  Files          19       19           
  Lines         766      766           
  Branches      146      146           
=======================================
  Hits          568      568           
  Misses        198      198           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update ce0b1ad...94220ba. Read the comment docs.

cagross commented 3 years ago

Great, thanks for allowing me to help :-) Again, if there are issues with that documentation, or it needs modification/augmentation, feel free to ping me and I'll be happy to take a look.

yinsang commented 3 years ago

had fixed in the latest version. Sorry

銀桑 notifications@github.com 于2021年2月26日周五 下午10:53写道:

Wrong case in doc. I run the second and get passed.

const tape = require('tape') tape('test for error', (t) => { t.plan(1) const err = new TypeError("Wrong value"); err.code = 404; err.check = "true";

// Failing test.
t.throws(
    () => {
        throw err;
    },
    {
        code: 404,
        check: true // This is not deeply strictly equal to err.check.
    },
    "Test message."
);

})

result is

1..1

tests 1

pass 1

ok

I tried to debug in source code, this line https://github.com/substack/tape/blob/master/lib/test.js#L680 is wrong.

this._assert(typeof fn === 'function' && passed, { message: defined(msg, 'should throw'), operator: 'throws', actual: caught && caught.error, expected: expected, // while caught is an error object, !passed return false, no error will be throw. error: !passed && caught && caught.error, extra: extra });

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/substack/tape/pull/542#issuecomment-786695019, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC6M2UEOR7K6VNDSABUHJDLTA6YWLANCNFSM4WTMZOUA .

cagross commented 3 years ago

had fixed in the latest version. Sorry

YES, well done :smiley: I was just posting here that I remember having a similar issue when I was originally testing that particular case--every test kept passing, even those that should fail. Then I realized my version of tape was 4.14.4. When I updated to v5+, the issue went away.

So you're not the only one it fooled. Actually, maybe I should add a note to the README warning others of that.

ljharb commented 3 years ago

I don’t think we need a note in the readme for something that applies to every software project ever written - “check the docs that match the version you’re using”.