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

Chai-As-Promised integration not working (possible Typescript clash?) #59

Open
weijie-tang opened this issue Jul 7, 2017 · 3 comments

Comments

@weijie-tang
Copy link

weijie-tang commented Jul 7, 2017

When parsing the values of an array returned by a promise, I get weird behavior.

Given the following versions of chai, chai-things, chai-as-promised and typescript:

+-- types@chai@3.5.2
+-- types@chai-as-promised@0.0.30
+-- types@chai-things@0.0.32
+-- chai@3.5.0
+-- chai-as-promised@6.0.0
+-- chai-things@0.2.0
+-- typescript@2.4.1

And the following import order:

import chai = require('chai');
chai.use(require('chai-things'));
chai.use(require('chai-as-promised'));
const expect = chai.expect;

And the following assertions:

expect(Promise.resolve([{ test: 'test' }])).to.eventually.all.have.property('test', 'test');
Promise.resolve([{ test: 'test' }]).should.eventually.all.have.property('test', 'test');

I get the following error:

TS2339: Property 'have' does not exist on type 'PromisedKeyFilter'.
@weijie-tang weijie-tang changed the title Integration with chai-as-promised works with expect, but not with should (possible Typescript clash?) Chai-As-Promised integration not working (possible Typescript clash?) Jul 7, 2017
@weijie-tang weijie-tang reopened this Jul 7, 2017
@weijie-tang
Copy link
Author

The second assertion worked after using chai.should(); in my imports, but the first one still has the same issue.

@losnir
Copy link

losnir commented Aug 2, 2017

The expect assertion works well for me with chai-as-promised & chai-things.

Import:

import chaiThings from 'chai-things';
import chaiAsPromised from 'chai-as-promised';

chai.use(chaiThings);
chai.use(chaiAsPromised);

Assert:

return expect(request)
      .to.eventually.be.an('array')
      .that.contains.something.with.property('x', 'y');

@jcgsville
Copy link

Maybe I'm missing something here, but I'm still getting this error:

TS2339: Property 'have' does not exist on type 'PromisedKeyFilter'.

I'm running these versions

    "@types/chai": "^4.2.4",
    "@types/chai-as-promised": "^7.1.2",
    "@types/chai-things": "^0.0.34",
    "chai": "^4.2.0",
    "chai-as-promised": "^7.1.1",
    "chai-things": "^0.2.0",
    "typescript": "^3.6.3",

Here's the repro

import chai from 'chai';
import chaiThings from 'chai-things';
import chaiAsPromised from 'chai-as-promised';
import 'mocha';

const should = chai.should();

chai.use(chaiThings);
chai.use(chaiAsPromised);
const { expect } = chai;

async function foo(): Promise<any> {
    return [ { bar: 'baz' }, { bar: 'baz' } ];
}

describe('foo', () => {
    it('works', async () => {
        foo().should.eventually.all.have.property('bar', 'baz');
        await expect(foo()).to.eventually.all.have.property('bar', 'baz');
    })
})

Any ideas?

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