Skip to content

Commit de005b5

Browse files
authored
fix: doctest linter
PR-URL: #9234 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent 8f95215 commit de005b5

File tree

2 files changed

+55
-0
lines changed
  • lib/node_modules/@stdlib/_tools/doctest/compare-values

2 files changed

+55
-0
lines changed

lib/node_modules/@stdlib/_tools/doctest/compare-values/lib/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ function checkArray( actual, expected ) {
435435
return false;
436436
}
437437
} else if ( isPrimitive( a ) ) {
438+
if ( !isPrimitive( b ) ) {
439+
return false;
440+
}
438441
b = String( b );
439442
if ( !checkPrimitive( a, b ) ) {
440443
return false;

lib/node_modules/@stdlib/_tools/doctest/compare-values/test/test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,3 +611,55 @@ tape( 'the function compares a function and a corresponding return annotation',
611611
return x;
612612
}
613613
});
614+
615+
tape( 'the function detects a mismatch when an actual array element is a primitive and the expected array element is an array', function test( t ) {
616+
var expected;
617+
var actual;
618+
var msg;
619+
620+
actual = [ 300, 700 ];
621+
expected = '[[ 300, 700 ]]';
622+
msg = 'Displayed return value is `[[ 300, 700 ]]`, but expected `[ 300, 700 ]` instead';
623+
t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' );
624+
625+
t.end();
626+
});
627+
628+
tape( 'the function detects a mismatch when an actual array element is a primitive and the expected array element is an object', function test( t ) {
629+
var expected;
630+
var actual;
631+
var msg;
632+
633+
actual = [ 1 ];
634+
expected = '[ {} ]';
635+
msg = 'Displayed return value is `[ {} ]`, but expected `[ 1 ]` instead';
636+
t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' );
637+
638+
t.end();
639+
});
640+
641+
tape( 'the function detects a mismatch when an actual array element is a primitive and the expected array element is a RegExp', function test( t ) {
642+
var expected;
643+
var actual;
644+
var msg;
645+
646+
actual = [ 1 ];
647+
expected = '[ /abc/ ]';
648+
msg = 'Displayed return value is `[ /abc/ ]`, but expected `[ 1 ]` instead';
649+
t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' );
650+
651+
t.end();
652+
});
653+
654+
tape( 'the function detects a mismatch in a mixed array where a primitive corresponds to an array', function test( t ) {
655+
var expected;
656+
var actual;
657+
var msg;
658+
659+
actual = [ 1, 2 ];
660+
expected = '[ 1, [ 2 ] ]';
661+
msg = 'Displayed return value is `[ 1, [ 2 ] ]`, but expected `[ 1, 2 ]` instead';
662+
t.strictEqual( compareValues( actual, expected ), msg, 'returns expected message' );
663+
664+
t.end();
665+
});

0 commit comments

Comments
 (0)