qunitjs / qunitjs/qunit

Extend Assert#pushResult to receive a custom diff value

Open
#1,005 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Category: API Component: Diff Type: Enhancement
Dominant language
JavaScript
Stars
4k
Forks
773
PR merge metrics
No merged PRs in 30d

Description

As requested by @wycats, it would be good to extend Assert#pushResult to receive a custom diff value, where it does not replace the default QUnit.diff (still useful for other assertions) but it prints a customized diff value.

Examples:

// Using default diff
QUnit.assert.prototype.customAssertion1 = function(actual, expected, result = actual == expected) {
  return this.pushResult({result, actual, expected});
};

// Using custom diff
QUnit.assert.prototype.customAssertion2 = function(actual, expected, result = actual == expected) {
  return this.pushResult({
    result,
    diff: lineDiff(actual, expected)
  });
};

If diff is given, QUnit should get its value and ignore calling the default QUnit.diff.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Assert#pushResult and trace how it currently obtains the default QUnit.diff value. Confirm how a supplied diff should take precedence while leaving the default available to other assertions, then add coverage for both the default and custom cases using the examples in the issue as the completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.