Jest matcher to validate xml equality
npm install jest-xml-matcher
yarn add -D jest-xml-matcher
`
Or using npm
`
npm install --save-dev jest-xml-matcher
`$3
Simplest way to use matcher with Jest is to modify setupTestFrameworkScriptFile configuration part.To do this, include following part in
package.json:
`
"jest": {
"setupTestFrameworkScriptFile": "./node_modules/jest-xml-matcher/index.js",
...
}
`$3
It possible to use test entry file or spec file and include module there (as in setupTests.js while using CRA):
`
require('jest-xml-matcher')
// or
import 'jest-xml-matcher'
`By adding lines mentioned above,
expect is being extended with toEqualXML check.
See examples for more explanation.$3
Assuming you have following XML structures:
`
const actualXML = const expectedXML =
`In test file you can write
`
expect(actualXML).toEqualXML(expectedXML)
``Which should result in: