chai-things icon indicating copy to clipboard operation
chai-things copied to clipboard

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

Open weijie-tang opened this issue 7 years ago • 3 comments

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@[email protected]
+-- types@[email protected]
+-- types@[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]

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 avatar Jul 07 '17 18:07 weijie-tang

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

weijie-tang avatar Jul 07 '17 18:07 weijie-tang

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');

losnir avatar Aug 02 '17 13:08 losnir

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?

jcgsville avatar Nov 06 '19 19:11 jcgsville