0

I am trying to write a jest test for the xml2js parse.parseString, but when I pass in an invalid xml it just bypasses the parse.parseString function rather than return the error in the callback function. I want to trigger the error in the callback function.

import xml2js from 'xml2js';

const parser = new xml2js.Parser({
  async: false
});
 
 parser.parseString(`<_>&%xstest</_>`, (err, result) => {

      if (err) {
        console.log('error',err)
        throw new Error(`Parser error: ${err}`);
      }

      console.log('result', result)
    });

any idea on why I can not trigger the err in the callback of parse.parseString to call? I am unable to get parse.parseString to throw an error.

H. Wynn
  • 403
  • 1
  • 4
  • 7

0 Answers0