Skip to content

Commit

Permalink
Docs: Move QUnit/push page to assert/push, and improve migration docs
Browse files Browse the repository at this point in the history
* Rename QUnit.push to assert.push.

  Back in QUnit 1.0, there was indeed a global function called
  QUnit.push, however it moved to the Assert class leading up to
  QUnit 2.0 with an alias from QUnit[name], same as for other assertion
  methods, such as `QUnit.equal()`.

  The actual global name for this has long been removed,
  back in QUnit 2.0, along with all the other global aliases,
  in commit a5aa1d8.

  We've never given aliases their own page, so move this page to be
  among its sibling Assert methods. This reflects the state of the
  code, and also makes its deprecated state less confusing as
  otherwise it would say that we removed QUnit.push in 2.0.0,
  and then deprecated it, after removing it, in QUnit 2.1.1,
  which doesn't make sense :)

* Add redirect for the URL used between QUnit 2.1.1 and 2.4.0.
  Ref #1206. Easy enough!
  • Loading branch information
Krinkle committed May 31, 2024
1 parent bb5bef6 commit 0f7aeac
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
38 changes: 38 additions & 0 deletions docs/api/assert/push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
layout: page-api
title: assert.push()
excerpt: Report the result of a custom assertion.
groups:
- deprecated
redirect_from:
- "/config/QUnit.push/"
- "/extension/QUnit.push/"
- "/api/extension/QUnit.push/"
version_added: "1.0.0"
version_deprecated: "2.1.1"
---

`push( result, actual, expected, message )`

Report the result of a custom assertion.

<p class="note note--warning" markdown="1">This method is __deprecated__ and it's recommended to use [`assert.pushResult()`](../assert/pushResult.md) instead.</p>

| name | description |
|------|-------------|
| `result` (boolean) | Result of the assertion |
| `actual` | Expression being tested |
| `expected` | Known comparison value |
| `message` (string) | A short description of the assertion |

`QUnit.assert.push()` relies on global state to push the assertion to the currently running test. This may leak assertions from asynchronous tests into an unrelated test.

To create a QUnit assertion plugin, refer to [`assert.pushResult()`](../assert/pushResult.md).

To safely report a global error from inside a plugin or other integration layer, without needing to know whether or which test is running, use [`QUnit.onUncaughtException()`](../extension/QUnit.onUncaughtException.md) instead.

## Changelog

| [QUnit 2.1.0](https://github.com/qunitjs/qunit/releases/tag/2.1.0) | Deprecated. Use `assert.pushResult` instead.
| [QUnit 2.0.0](https://github.com/qunitjs/qunit/releases/tag/2.0.0)| Remove `QUnit.push` alias.
| [QUnit 1.15.0](https://github.com/qunitjs/qunit/releases/tag/1.15.0) | Rename `QUnit.push` to `QUnit.assert.push`, with alias.
2 changes: 2 additions & 0 deletions docs/api/assert/pushResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ title: assert.pushResult()
excerpt: Report the result of a custom assertion.
groups:
- assert
- extension
redirect_from:
- "/pushResult/"
- "/assert/pushResult/"
version_added: "1.22.0"
---
Expand Down
30 changes: 0 additions & 30 deletions docs/api/extension/QUnit.push.md

This file was deleted.

3 changes: 1 addition & 2 deletions src/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class Assert {
});
}

// Exports test.push() to the user API
// Alias of pushResult.
push (result, actual, expected, message, negative) {
Logger.warn('assert.push is deprecated and will be removed in QUnit 3.0.' +
' Please use assert.pushResult instead. https://qunitjs.com/api/assert/pushResult');
Expand All @@ -105,6 +103,7 @@ class Assert {
});
}

// Public API to internal test.pushResult()
pushResult (resultInfo) {
// Destructure of resultInfo = { result, actual, expected, message, negative }
let assert = this;
Expand Down
10 changes: 6 additions & 4 deletions src/html-reporter/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,11 @@ const stats = {
let diff;
let showDiff = false;

// The pushFailure doesn't provide details.expected
// when it calls, it's implicit to also not show expected and diff stuff
// Also, we need to check details.expected existence, as it can exist and be undefined
// When pushFailure() is called, it is implied that no expected value
// or diff should be shown. It does not set details.expected.
//
// This must check details.expected existence. If it exists as undefined,
// that's a regular assertion for which to render actual/expected and a diff.
if (!details.result && hasOwn.call(details, 'expected')) {
if (details.negative) {
expected = 'NOT ' + QUnit.dump.parse(details.expected);
Expand Down Expand Up @@ -922,7 +924,7 @@ const stats = {

message += '</table>';

// This occurs when pushFailure is set and we have an extracted stack trace
// This occurs when pushFailure is called and we have an extracted stack trace
} else if (!details.result && details.source) {
message += '<table>' +
"<tr class='test-source'><th>Source: </th><td><pre>" +
Expand Down
4 changes: 2 additions & 2 deletions src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ Test.prototype = {
});
},

pushFailure: function (message, source, actual) {
pushFailure: function (message, source) {
if (!(this instanceof Test)) {
throw new Error('pushFailure() assertion outside test context, was ' +
sourceFromStacktrace(2));
Expand All @@ -599,7 +599,7 @@ Test.prototype = {
this.pushResult({
result: false,
message: message || 'error',
actual: actual || null,
actual: null,
source
});
},
Expand Down

0 comments on commit 0f7aeac

Please sign in to comment.