rfc1484 rfc1484 - 1 year ago 138
JSON Question

How to use chai json schema with es6 syntax

I'm working in a project which uses es6 syntax, for example, instead of require it uses import. In this particular case for importing chai json schema I use the following line:

import jsonSchema from 'chai-json-schema';

But I can't figure out how to tell chai to use json schema using es6 syntax.

In the project documentation shows how to have chai use chai json schema like this:

var chai = require('chai');

How can I do this with es6 syntax?

Answer Source

Just split the line to perform the import first and then call chai.use. This works:

import chai from 'chai';
import jsonSchema from 'chai-json-schema';

If you want to import individual bits of chai together with chai itself, you can do:

import chai, { expect, should } from 'chai';
import jsonSchema from 'chai-json-schema';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download