Skip to content

Commit

Permalink
Assert: Remove deprecation warning from assert.push()
Browse files Browse the repository at this point in the history
Cherry-picks eaa0dbe (3.0.0-dev)

> This is still used by numerous plugins that have no other reason to
> break [in QUnit 3.0.0]. It's trivial to map to the new method
> and requires no maintenance or increased complexity, and we're not
> under any size constraints. Let's keep it around.

Cherry-picks 2b0ae95 (3.0.0-dev)

> Improve assert.pushResult() tests.
  • Loading branch information
Krinkle committed Jul 15, 2024
1 parent 98d7942 commit 279abaa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
6 changes: 1 addition & 5 deletions src/assert.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import dump from './dump';
import equiv from './equiv';
import Logger from './logger';

import config from './core/config';
import { objectType, objectValues, objectValuesSubset, errorString } from './core/utilities';
Expand Down Expand Up @@ -90,12 +89,8 @@ 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');

const currentAssert = this instanceof Assert ? this : config.current.assert;
return currentAssert.pushResult({
result,
Expand All @@ -106,6 +101,7 @@ class Assert {
});
}

// Public API to internal test.pushResult()
pushResult (resultInfo) {
// Destructure of resultInfo = { result, actual, expected, message, negative }
let assert = this;
Expand Down
45 changes: 30 additions & 15 deletions test/main/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,39 @@ QUnit.module('test', function () {
this.push(true, value, expected, message, false);
};

QUnit.test('mod2', function (assert) {
assert.mod2(2, 0, '2 % 2 == 0');
assert.mod2(3, 1, '3 % 2 == 1');
QUnit.test('assert.pushResult()', function (assert) {
var detail;
QUnit.log(function (data) {
detail = data;
});

assert.mod2(2, 0, 'two');
assert.mod2(3, 1, 'three');

assert.propContains(detail, {
result: true,
actual: 1,
expected: 1,
message: 'three',
negative: false
});
});

QUnit.test('testForPush', function (assert) {
QUnit.log(function (detail) {
if (detail.message === 'should be call pushResult') {
/* eslint-disable qunit/no-conditional-assertions */
assert.equal(detail.result, true);
assert.equal(detail.actual, 1);
assert.equal(detail.expected, 1);
assert.equal(detail.message, 'should be call pushResult');
assert.equal(detail.negative, false);
/* eslint-enable */
}
QUnit.test('assert.push()', function (assert) {
var detail;
QUnit.log(function (data) {
detail = data;
});

assert.testForPush(10, 20, 'hello');

assert.propContains(detail, {
result: true,
actual: 10,
expected: 20,
message: 'hello',
negative: false
});
assert.testForPush(1, 1, 'should be call pushResult');
});

QUnit.module('aliases');
Expand Down

0 comments on commit 279abaa

Please sign in to comment.