1

Why is this test not passing with fastxmlparser

 import parser from 'fast-xml-parser'    
    test("fastxmlparser", () => {
            let parsed = parser.parse('<detail><name>john</name><value>116347579610481033</value></detail>')
            expect(parsed.detail.value).toBe('116347579610481033')
        })


Expected value to be:
          "116347579610481033"
        Received:
          116347579610481040

        Difference:

          Comparing two different types of values. Expected string but received number.

           95 | test("fastxmlparser", () => {
           96 |     let parsed = parser.parse('<detail><name>john</name><value>116347579610481033</value></detail>')
        >  97 |     expect(parsed.detail.value).toBe('116347579610481033')
           98 | })
           99 | 
          100 | 
sat
  • 5,489
  • 10
  • 63
  • 81
  • 1
    Can you find a way to tell it to parse the content of the `` tag as a string? – Andrew Morton Oct 02 '19 at 21:27
  • 1
    @AndrewMorton - Yes. I can. Two configuration options work (parseTrueNumberOnly: true) and (stopNodes: ['value']), but I am not sure why the value itself would change during parsing. – sat Oct 02 '19 at 22:39
  • 1
    It's probably due to the resolution of the number type being used - it doesn't have enough bits to represent 116347579610481033 exactly. – Andrew Morton Oct 03 '19 at 06:55

0 Answers0