Closed customcommander closed 3 months ago
There is no official or supported way to add assertions.
That said, you could import https://github.com/substack/tape/blob/master/lib/test.js and mutate it with your own assertions - I do this in a project or two (example). However, it could break even in a patch release, so use it at your own risk.
It might be nice/reasonable to have some kind of top-level const wrappedTape = tape.withAssertion(name, handler);
kind of API? That way, you could add your own assertions safely, without affecting other consumers of tape
in the same application.
That is pretty much what I was thinking.
Not polluting other tape
instances with third-party assertions is definitely the way to go. May I perhaps suggest we can register more than one assertion so that we can integrate third-party assertions as seamlessly as possible (YMMV)? e.g.,
const test = require('tape').withAssertions(['foo', fn], ['bar', fn], ...)
test('...', t => {
t.foo(...);
t.bar(...);
t.end();
});
I went with a slightly simpler API - t.assertion(fn, ...args)
. fn
is what you would have installed on Test.prototype
, and it can take whatever arguments you want.
If a call-this operator existed, this would be native, but this will have to do in the meantime.
Hi all,
I use
jsverify
withtape
. It looks like this:The problem is that since I'm not actually using an assertion the output is:
When a property-based assertion fails, it breaks the test (which is nice) but not in a nice way:
Some libraries have support for property-based assertions, ideally with
tape
it'd look like this:So I'm looking into adding a new assertion
t.property
and have failures properly reported. Ideally I would want this as a plugin e.g.tape-jsverify
.Is there any documentation, code or other tape plugin you would recommend I take a look at? Just looking for some info from the maintainers to get me started in the right direction (hopefully).
If
tape
doesn't really support third-party assertions, that's good to know too.Thanks!