question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an ES6-friendly way to register "should"

See original GitHub issue

I suggest adding a file named should.js at the root of this project that auto-registers ‘should’, i.e. require('./index').should();.

/* CURRENT SITUATION */

  // commonjs style looks nice
  require('chai').should();

  // but es6 isn't so nice
  import chai from 'chai';
  chai.should();

  // or you can do this, but it's still 2 lines
  import {should} from 'chai';
  should();

/* PROPOSAL */

  // single-line way to register 'should' in ES6
  import `chai/should`;

  // nb. other libraries use this convention too
  import 'babel-core/register';
  import 'coffee-script/register';

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
pyrosshcommented, May 13, 2017

After combing the pr’s I found this and it worked.

import "chai/register-should"

Maybe the documentation needs to be updated later.

1reaction
keithamuscommented, May 16, 2016

@jonaswindey this should be released as part of 4.0.0, which will be out soon 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use ES6 Features in React - freeCodeCamp
So to help you learn these handy features, I'll introduce you to them and then show you how to apply them in React.js....
Read more >
Setting up an ES6 Project Using Babel and webpack - SitePoint
Chris Perry shows how to set up a build system for modern JavaScript, using Babel, ES6 modules and webpack, with watch tasks and...
Read more >
Adding object properties conditionally with EcmaScript 6 (ES6)
Adding a property to an object is quite easy in JavaScript. You can basically do it like in the following code. 1. const...
Read more >
How to enable ES6 Support in Client Scripts (Any version)
Step 2: Write ES6 Client Scripts. Now you can go to any Client Script and start scripting in ES6, ES7, or any new...
Read more >
How can I use an ES6 import in Node.js? [duplicate]
Add { "type": "module" } in the nearest package.json . You only need to do one of the above to be able to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found