Skip to content

Custom jest matcher which can be used to find differences between XML structures

License

Notifications You must be signed in to change notification settings

kbiedrzycki/jest-xml-matcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jest-xml-matcher

Custom Jest matcher which can be used to find differences between XML structures

Installation

It can be installed using yarn

yarn add -D jest-xml-matcher

Or using npm

npm install --save-dev jest-xml-matcher

Usage with JS

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",
  ...
}

Usage with TS (or JS)

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.

Examples

Assuming you have following XML structures:

const actualXML = `
  <parent>
    <child attr="test">
      <anotherInside>That's changing</anotherInside>
    </child>
  </parent>
`

const expectedXML = `
  <parenting>
    <child attr="tested">
      <anotherInside>What a pity :(</anotherInside>
    </child>
  </parenting>
`

In test file you can write

expect(actualXML).toEqualXML(expectedXML)

Which should result in:

example

About

Custom jest matcher which can be used to find differences between XML structures

Resources

License

Stars

Watchers

Forks

Packages

No packages published