-
-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an ES6-friendly way to register "should" #594
Comments
Something I'd like to address in the roadmap (#457). Not sure what the right way to address this is though, as each has its downsides, especially when using plugins: /* CURRENT SITUATION */
// commonjs style looks nice
require('chai').use(require('some-plugin')).should();
// but es6 isn't so nice
import chai from 'chai';
import somePlugin from 'some-plugin';
chai.use(somePlugin).should();
// or you can do this, but it's still 2 lines
import chai, {should} from 'chai';
import somePlugin from 'some-plugin';
chai.use(somePlugin);
should();
/* PROPOSAL */
// single-line way to register 'should' in ES6
import chai from 'chai';
import somePlugin from 'some-plugin';
chai.use(somePlugin);
import `chai/should`;
// nb. other libraries use this convention too
import 'babel-core/register';
import 'coffee-script/register'; |
I suppose keeping // Plugin-less
import { expect } from 'chai'
import { assert } from 'chai'
import 'chai/should'
// if you need should.exist/should.fail etc:
import should from 'chai/should'
// With plugins
import chai from 'chai';
import somePlugin from 'some-plugin';
const expect = chai.use(somePlugin).expect
import chai from 'chai';
import somePlugin from 'some-plugin';
const assert = chai.use(somePlugin).assert
import chai from 'chai';
import somePlugin from 'some-plugin';
const should = chai.use(somePlugin).should() |
@callumlocke how do you feel about making a PR for this? It should simply be a case of creating a file named module.exports = require('./').should() |
I'm getting when using this syntax (chai 3.5.0) |
@jonaswindey this should be released as part of |
Well the documentation seems to be updated to the latest syntax. Will need to wait for 4.0.0 release then. |
After combing the pr's I found this and it worked. import "chai/register-should" Maybe the documentation needs to be updated later. |
I suggest adding a file named
should.js
at the root of this project that auto-registers 'should', i.e.require('./index').should();
.Note: people sometimes think side-effecting imports feel dirty, but it's arguably less dirty than a globally side-effecting function call like
.should()
. When you have a 'fromless' import that doesn't assign any variables, the syntax is explicitly intended for side-effects.The text was updated successfully, but these errors were encountered: