question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Customize assertions

See original GitHub issue

Is there a way to add some custom assertions to t existing ones?

I would like to add those basic ones: — t.instanceof(object, clazz)t.length(array, length)t.members(array, item, item)t.includes(string, substring)

I guess t.context can be used, but feels cumbersome. And maybe, those assertions can be considered to be added to ava core.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:27
  • Comments:22 (13 by maintainers)

github_iconTop GitHub Comments

10reactions
sindresorhuscommented, Oct 26, 2016

Not at the moment, but your needs can be solved with the existing methods:

t.true(object instanceof clazz);
t.is(array.length, length);
t.true(array.every(x => [item, item].includes(x)));
t.true(string.includes(substring));

You can already use any external assertion library. The only caveat is that t.plan() doesn’t work.

7reactions
sotojuancommented, Nov 3, 2016

I guess the problem is that it’s a slippery slope. These kind of extra assertions are better in userland as separate modules, functions, or snippets. I personally don’t see anything wrong with the code block in the last comment but you could make it look “prettier” by abstracting those functions away. That way you can use your own custom logic as well.

The smaller core AVA is, the easier it is to use.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Assertions with AssertJ - Baeldung
In this tutorial, we'll walk through creating custom AssertJ assertions; the AssertJ's basics can be found here.
Read more >
AssertJ / Fluent assertions for java
Custom assertions can be seen as a DSL of domain assertions. Writing your own assertions is simple : create a class inheriting from...
Read more >
Custom Assertion at XUnitPatterns.com
We often run across Custom Assertions that take one actual object and several different Expected Objects that need to be compared with specific...
Read more >
Custom Assertions in Java Tests - InfoQ
Each custom assertion written with AssertJ contains code which is responsible for the creation of an assertion object and the injection of the ......
Read more >
Custom Assertions | Pester
A guide for creating your own custom operators for more advanced or user-specific assertion needs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found