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.

Docs: Really, use `t` for assertions

See original GitHub issue

I just tried to covert a project that’s tested with tape over to using AVA instead. The tests all follow this kind of format:

test('function-a', (assert) => {
  assert.plan(1);

  assert.is(
    functionA(),
    resultB,
    'function a should return result b'
  );
});

They seem to run just fine under AVA, but the assertion messages don’t show up when I create a failing test case, just the test messages.

Is there a way to report on the assertion messages? Or is the best practice just to wrap every one of these assertions in its own test block? (In which case, why do the assertions accept optional message parameters?

Am I missing something stupid?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
smeijercommented, Sep 5, 2016

Try using t instead of assert as your parameter name (using t should enable power-assert).

I had this exact same issue. I guess it’s worth a note in the readme, perhaps under FAQ.

Why is the power-assert information not shown?

Try using t instead as your parameter name.

This is a byproduct of the way power-assert works. It uses a pattern matching scheme that makes it easier for implementors to wrap any assertion library with power-assert goodness without having to understand the ES AST at all

1reaction
jamestalmagecommented, Sep 2, 2016

Really?

It seems to work, but that’s kinda voodoo.

Yes, yes it is. This is a byproduct of the way power-assert works. It uses a pattern matching scheme that makes it easier for implementors to wrap any assertion library with power-assert goodness without having to understand the ES AST at all (which is super awesome). That said, the AVA team certainly has members capable of creating a more robust matcher that would detect your use of a different variable name, so if power-assert exposed an “advanced” API, we could certainly leverage it to provide a more user friendly experience.

See https://github.com/power-assert-js/babel-plugin-espower/issues/18.

It would be non-trivial, but something worth doing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assertions Reference | GoogleTest
Assertions Reference. This page lists the assertion macros provided by GoogleTest for verifying code behavior. To use them, include the header gtest/gtest.h ...
Read more >
Programming With Assertions - Oracle Help Center
An assertion is a statement in the Java TM programming language that enables you to test your assumptions about your program. For example,...
Read more >
Type Assertions - Sorbet
There are five ways to assert the types of expressions in Sorbet: ... See Blocks, Procs, and Lambda Types for more real-world usage...
Read more >
Assertions | Cypress Documentation
They don't actually do anything, but they enable you to write clear, english sentences.
Read more >
How to write and report assertions in tests - Pytest
pytest allows you to use the standard Python assert for verifying expectations and values in Python tests. For example, you can write the...
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