acEx(actual, expected, prefix)

Return a formatted message that compares actual/expected values.

  • actual any — 

    actual value

  • expected any — 

    expected value

  • prefix string — 

    added to the start of the returned message

    (default: '')
returns string

See

  • maybeStringify — 

    used by this function to produce the string representation of the actual and expected values

  • UnexpectedOutputError — 

    uses this function to generate the error message

Examples

No Prefix

const {acEx} = require('spooning');
console.log(acEx('A', 'B'));

Output

<<<<<<< actual
A
=======
B
>>>>>>> expected

Prefix

const {acEx} = require('spooning');
console.log(acEx('A', 'B', 'Unexpected output\n'));

Output

Unexpected output
<<<<<<< actual
A
=======
B
>>>>>>> expected

Use in Assertion

const {deepEqual} = require('assert');
const {acEx, testSync} = require('spooning');

function greet(name) {
  return `Hello, ${name}!`;
}

testSync('Should greet world', () => {
  const actual = {greeting: greet('world')};
  const expected = {greeting: 'Hello, world!'};
  deepEqual(actual, expected, acEx(actual, expected, 'did not greet world'));
});