chaijs / chai-things

Chai support for assertions on array elements
http://chaijs.com/plugins/chai-things
Other
104 stars 14 forks source link

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

Open weijie-tang opened 7 years ago

weijie-tang commented 7 years ago

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 commented 7 years ago

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

losnir commented 7 years ago

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 commented 4 years ago

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?