Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom assertions? #25

Closed
RedHatter opened this issue Dec 9, 2018 · 2 comments
Closed

Custom assertions? #25

RedHatter opened this issue Dec 9, 2018 · 2 comments

Comments

@RedHatter
Copy link
Contributor

It would be nice if we could extend the assertions object to provide custom assertions.

@lorenzofox3
Copy link
Owner

lorenzofox3 commented Dec 11, 2018

you can simply decorate your spec function:

const withFooAssert = specFn => t => specFn(Object.assign(t, {
  foo(actual, expected, description = 'foo !') {
    const assertResult = {
      pass: Object.is(actual, expected),
      actual: actual,
      expected: expected,
      description,
      operator: 'foo'
    };

    this.collect(assertResult); // COLLECT RESULT
    return assertResult;
  }
}));

// and then when you write your tests:

test('foo bar bim', withFooAssert(t => {
   t.foo('var','bar');
}));

You can centralize it if you find it troublesome to write the decorator on each test:

const test = require('zora');

module.exports = (description, spec) => test(description, withFooAssert(spec));

And require this function instead of zora

What is the missing assertion ? might worth add it to the core library

@RedHatter
Copy link
Contributor Author

Snapshot testing jest style that compares a string against a cached version and visual snapshot testing using pixelmatch that compares an image against a cached version.

I've run into a bit of an issue with the visual snapshot. I have three values I need to I need to display when the assertion fails, expected, actual, and the difference. The collect function doesn't have any place to put the difference value. Could you either add an additional field (reason maybe?) or even better have the tap printer print all fields in the object?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants