when decoded as

  • <Buffer> [when] decoded as <string> <assertion?>

Decode a Buffer, then delegate the return value to another assertion. Supports the standard node.js Buffer encodings.

expect(
  Buffer.from([0xe2, 0x98, 0xba]),
  'when decoded as',
  'utf-8',
  'to equal',
  '☺'
);

In case of a failing expectation you get the following output:

expect(
  Buffer.from([0xe2, 0x98, 0xba]),
  'when decoded as',
  'utf-8',
  'to equal',
  'happy face'
);
expected Buffer.from([0xE2, 0x98, 0xBA])
when decoded as 'utf-8' to equal 'happy face'
 
happy face

If you don't provide an assertion to delegate to, the decoded value will be provided as the fulfillment value of the promise:

return expect(Buffer.from([0xe2, 0x98, 0xba]), 'decoded as', 'utf-8').then(
  function (result) {
    expect(result, 'to equal', '☺');
  }
);