Socket
Socket
Sign inDemoInstall

chai-xsd-schema

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-xsd-schema

Chai plugin for using libxml-xsd schema validation


Version published
Maintainers
1
Created
Source

Chai plugin for XML validation using libxml-xsd

Chai plugin to allow XML Schemas (XSD) to be used with expect. This is currently a stub and is under heavy development. All contributions are welcome.

##Installation

To install plugin simply run: npm install chai-xsd-schema

Then add the following to your unit tests under your chai definition:

chai.use(require('chai-xsd-schema'))

##Usage This plugin adds validWithSchema to the expect validation methods.

expect('xmldocstring').to.be.validXML(['xsdschemastring1','xsdschemastring2']);
expect('xmldocstring').to.be.validXML('xsdschemastring');

##Simple Example

import chai from 'chai';
import fs from 'fs';

chai.use(require('chai-xsd-schema'))

const expect = chai.expect;

describe('Test XML', () => {
  it('Fails with invalid input and valid schema', () => {
    const schema = fs.readFileSync(`${__dirname}/schemas/dhl.xsd`, {
      encoding: 'utf8',
    });

    const xml = fs.readFileSync(`${__dirname}/vectors/invalidData.xml`, {
      encoding: 'utf8',
    });

    expect(xml).to.not.be.validXML(schema);
  });

  it('Passes with valid input and valid schema', () => {
    const schema = fs.readFileSync(`${__dirname}/schemas/dhl.xsd`, {
      encoding: 'utf8',
    });

    const xml = fs.readFileSync(`${__dirname}/vectors/validData.xml`, {
      encoding: 'utf8',
    });

    expect(xml).to.be.validXML(schema);
  });
});

Keywords

FAQs

Package last updated on 09 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc