Skip to content

Commit

Permalink
test(ses): Cover assert.bare
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Jun 5, 2023
1 parent d1eb564 commit 7c27d7f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/ses/test/error/test-assert-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';
import { assertLogs, throwsAndLogs } from './throws-and-logs.js';
import { assert } from '../../src/error/assert.js';

const { details: d, quote: q } = assert;
const { details: d, quote: q, bare: b } = assert;

// Self-test of the example from the throwsAndLogs comment.
test('throwsAndLogs with data', t => {
Expand Down Expand Up @@ -385,6 +385,28 @@ test('assert q', t => {
);
});

test('assert b', t => {
throwsAndLogs(t, () => assert.fail(d`${b('foo')}`), 'foo', [
['log', 'Caught', Error],
]);
// Spaces are allowed in bare values.
throwsAndLogs(t, () => assert.fail(d`${b('foo bar')}`), 'foo bar', [
['log', 'Caught', Error],
]);
// Multiple consecutive spaces are disallowed and fall back to quote.
throwsAndLogs(t, () => assert.fail(d`${b('foo bar')}`), '"foo bar"', [
['log', 'Caught', Error],
]);
// Strings with non-word punctuation also fall back.
throwsAndLogs(t, () => assert.fail(d`${b('foo%bar')}`), '"foo%bar"', [
['log', 'Caught', Error],
]);
// Non-strings also fall back.
throwsAndLogs(t, () => assert.fail(d`${b(undefined)}`), '"[undefined]"', [
['log', 'Caught', Error],
]);
});

test('q as best efforts stringify', t => {
t.is(`${q('baz')}`, '"baz"');
const list = ['a', 'b', 'c'];
Expand Down

0 comments on commit 7c27d7f

Please sign in to comment.