Skip to content

Commit

Permalink
qunit: Update eslint-plugin-qunit to 6.0.0 (#367)
Browse files Browse the repository at this point in the history
Enables:
* no-async-module-callbacks
* no-compare-relation-boolean
* no-hooks-from-ancestor-modules
* no-nested-tests
* require-object-in-propequal

Disables:
* no-arrow-tests
* no-assert-equal-boolean (#366)
  • Loading branch information
edg2s committed Mar 25, 2021
1 parent ef3e1ac commit bde581f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 19 deletions.
35 changes: 25 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"eslint-plugin-mocha": "^8.1.0",
"eslint-plugin-no-jquery": "^2.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-qunit": "^5.2.0",
"eslint-plugin-qunit": "^6.0.0",
"eslint-plugin-vue": "^7.7.0",
"eslint-plugin-wdio": "^6.0.12"
},
Expand Down
5 changes: 3 additions & 2 deletions qunit.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"extends": [
"plugin:qunit/recommended",
"plugin:qunit/two"
"plugin:qunit/recommended"
],
"env": {
"qunit": true
},
"plugins": [ "qunit" ],
"rules": {
"qunit/no-arrow-tests": "off",
"qunit/no-assert-equal": "error",
"qunit/no-assert-equal-boolean": "off",
"qunit/no-assert-logical-expression": "off",
"qunit/no-conditional-assertions": "off",
"qunit/require-expect": [ "error", "never-except-zero" ]
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/qunit/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"root": true,
"extends": [
"../../../client-es5",
"../../../client-es6",
"../../../language/es2017",
"../../../qunit"
]
}
35 changes: 32 additions & 3 deletions test/fixtures/qunit/invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ QUnit.module( 'Example' );
// Local rules
// eslint-disable-next-line qunit/require-expect
QUnit.test( '.foo()', function ( assert ) {
var x = 'bar';
const x = 'bar';

// eslint-disable-next-line qunit/no-assert-equal
assert.equal( x, 'bar' );
Expand All @@ -22,7 +22,7 @@ QUnit.test( '.foo()', function ( assert ) {
// Recommended
// eslint-disable-next-line qunit/no-identical-names, qunit/resolve-async
QUnit.test( '.foo()', function ( assert ) {
var done = assert.async();
const done = assert.async();

// eslint-disable-next-line qunit/assert-args
assert.ok( 'result', 'message', 'extra' );
Expand All @@ -38,10 +38,15 @@ QUnit.test( '.foo()', function ( assert ) {
// eslint-disable-next-line qunit/no-ok-equality
assert.ok( done === 'bar' );

// eslint-disable-next-line qunit/no-compare-relation-boolean
assert.strictEqual( done > 3, true );

// eslint-disable-next-line qunit/no-throws-string
assert.throws( function () {
}, 'error message', 'An error should have been thrown' );

// eslint-disable-next-line qunit/require-object-in-propequal
assert.propEqual( done, 'foo' );
} );

// eslint-disable-next-line qunit/no-commented-tests
Expand All @@ -62,7 +67,6 @@ QUnit.init();
// eslint-disable-next-line qunit/no-jsdump
QUnit.jsDump( {} );

// Two:
// eslint-disable-next-line qunit/no-async-test, qunit/no-test-expect-argument, qunit/require-expect
QUnit.asyncTest( 'Asynchronous test', 3, function () {
// eslint-disable-next-line qunit/no-qunit-start-in-tests
Expand All @@ -81,6 +85,31 @@ QUnit.asyncTest( 'Asynchronous test', 3, function () {
strictEqual( 3, 4 );
} );

// eslint-disable-next-line qunit/no-async-module-callbacks
QUnit.module( 'An async module', async function () {
QUnit.test( 'a passing test', function ( assert ) {
assert.ok( true );
} );

await Promise.resolve();

QUnit.test( 'another passing test', function ( assert ) {
assert.ok( true );
} );
} );

QUnit.module( 'outer module', function ( hooks ) {
QUnit.module( 'inner module', function () {
// eslint-disable-next-line qunit/no-hooks-from-ancestor-modules
hooks.beforeEach( function () {} );
} );
} );

QUnit.test( 'Parent', function () {
// eslint-disable-next-line qunit/no-nested-tests
QUnit.test( 'Child', function () {} );
} );

// eslint-disable-next-line qunit/no-qunit-push
QUnit.push( 'result', 'actual', 'expected', 'message' );

Expand Down
8 changes: 6 additions & 2 deletions test/fixtures/qunit/valid.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
QUnit.module( 'Example' );

// Off: qunit/no-arrow-tests
// Valid: qunit/require-expect
QUnit.test( '.foo()', function ( assert ) {
var x = 'bar',
QUnit.test( '.foo()', ( assert ) => {
const x = 'bar',
y = 'baz';

// Valid: qunit/no-assert-equal
assert.strictEqual( x, 'bar' );

// Off: qunit/no-assert-equal-boolean
assert.strictEqual( x, true );

// Valid: qunit/no-negated-ok
assert.notOk( x );

Expand Down

0 comments on commit bde581f

Please sign in to comment.