Skip to content
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

export expect as alias of must to simplify imports #74

Open
danyg opened this issue Mar 22, 2018 · 3 comments
Open

export expect as alias of must to simplify imports #74

danyg opened this issue Mar 22, 2018 · 3 comments

Comments

@danyg
Copy link

danyg commented Mar 22, 2018

Hi, love this library, much better and safer than chai.

I'm migrating some test done with mocha, chai and typescript, and just a silly request could you export expect as an alias of the function must?

See if you want to use expect on typescript this is what you need to do:

import must from 'must';
const expect = must;

If you try to do this:

import { must as expect } from 'must';

Typescript parser understands that you want to export the must property on the Object returned by require which is an instance of Must according to must.d.ts, in particular this:

    interface Object {
        must: Must;
    }

Other option would be to change expect to must in my tests, but it looks weird:

await must(testee.load()).must.reject.to.error(Error, 'message');
// must must === very must?

I know this intended to be used this way:

await testee.load().must.reject.to.error(Error, 'message');

But don't feel safe using this notation to be honest.

Cheers!

@moll
Copy link
Owner

moll commented Mar 23, 2018

Hey!

Hmm, I've not used Typescript myself, but that sure sounds weird. Doesn't it have a way rename the default export just like with plain CommonJS you can do var expect = require("must")?

I definitely want you to be able to rename the default export to expect if you prefer that over the prototype-extension approach.

@chrisgedrim
Copy link

The only thing exported by Must is declare function must(expected: any): Must;

As it's exporting a single function you can import * as expect from 'must';

@moll
Copy link
Owner

moll commented Nov 2, 2020

Hey! Did @chrisgedrim recommendation fit your use case, @danyg?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants