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.

AVA team is extremely excited to announce the new & shiny AVA feature. We call it “Magic assert”.

We could try and describe magic-assert and all its features, but it’s faster and better to let you see what it is all about right away.

Strings

test('strings', t => {
  const actual = 'this is so cool';
  const expected = 'this is so bad';

  t.is(actual, expected);
});

Different value types

test('different types', t => {
  const actual = 'this is so cool';
  const expected = {msg:'this is so bad'};

  t.is(actual, expected);
});

Objects and arrays

test('objects', t => {
  const actual = {
    a: 1,
    b: {
      c: 2
    }
  };

  const expected = {
    a: 2,
    b: {
      c: 1
    }
  };

  t.deepEqual(actual, expected);
});

t.true/t.false assertions

These kind of assertions obviously can’t have diffs, because they’re being compared to true/false. Having “actual: true, expected: false” output wouldn’t be much of a help, so instead we display the value of each statement in the assertion.

test('nested', t => {
  const actual = {a:[1]};
  
  t.true(actual.a[0]);
});

Now that we got you all excited (hopefully), few words about what it actually is. Magic assert is not an assertion library, but a feature that handles assertion errors and is responsible for displaying them in a clean yet informative way. It replaces power-assert output, although it still uses its core for some cases.

Magic assert adds code excerpts pointing to the source of the error and clean colorful diffs to each error report. You can also spot there’s now more spacing between each error, which makes it easier to go through all the errors.

Your tests don’t need to be modified in any way to take support magic-assert’s output. If you use other assertion library like expect/chai or other, you are in luck too - you will get the same magical output!

There’s one more thing…

React support

Magic assert PR also lands two new assertion methods to improve React support: t.jsxEquals() and t.jsxNotEquals(). And as you may have expected, it provides a nice output of the “React tree” as well!

test('react', t => {
  const actual = <div className="body">Hello</div>;
  const expected = <div className="header">Hello</div>;

  t.jsxEqual(actual, expected);
});
screen shot 2016-12-12 at 11 19 57 pm

I’m not sure whether this change should be in this or separate PR - feedback welcome here too.

Credits

Magic assert was made possible by these amazing modules:

Huge thanks!


We think it is a big step forward towards more comfortable debugging of failed tests and developer happiness in general.

You can try Magic assert by using PR https://github.com/avajs/ava/pull/1154 today!

We’d love to hear your feedback and ideas on how to improve the output of Magic assert! Thank you!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:25
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ccorcoscommented, Jan 3, 2017

Using your current WIP branch:

 Difference:

    Array [
      Object {
        children: Array [
          Object {
  -         type: "text",
  -         value: "[hello](world)",
  +         children: Array [
  +           Object {
  +             type: "text",
  +             value: "hello",
  +           },
  +         ],
  +         type: "link",
  +         url: "world",
          },
        ],
        type: "italic",
      },

Awww yeah! Thank you so much @vadimdemedes 😃

0reactions
vadimdemedescommented, Jan 9, 2017

I think we’ll probably stick with the default “-” for “missing” and “+” for “extra” signs, like in git diff. We can improve it after some real world usage of magic assert (if needed).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assert Authority (Mirrodin) - Gatherer - Magic
Card Name: Assert Authority ; Mana Cost: 5 Blue ; Converted Mana Cost: 7 ; Types: Instant ; Card Text: Affinity for artifacts...
Read more >
unittest.mock — mock object library — Python 3.11.1 ...
Mocks record how you use them, allowing you to make assertions about what your code has done to them. MagicMock is a subclass...
Read more >
Assert Authority - Mirrodin - Magic: The Gathering - TCGplayer
369 listings on TCGplayer for Assert Authority - Magic: The Gathering - Affinity for artifacts (This spell costs 1 less toplay for each...
Read more >
assert_not magic?
assert_not magic? All Posts · About Ryan · Tags · Uses. Solving an ExecJS Error that Breaks Jekyll on Rebuild. Jun 14, 2021 ......
Read more >
ts-magic-assert - npm
Get more information from asserts & checks. Latest version: 0.1.7, last published: a year ago. Start using ts-magic-assert in your project by running...
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