jest-extended
jest-extended copied to clipboard
Feature Request: extend the expect library
Feature Request
Description:
Would it be (have been?) possible to extend the 'expect' library instead? My use case is that I am using Jest from the command line (the "normal" way), but am also trying to use the 'expect' library directly from within my client-side code in order to make assertions. That way I only have 1 assertion library to learn.
I'm not sure I fully understand the question of extend the expect library instead.
Jest allows it's expect to be extended via the expect.extend API, that is what jest-extended does inside of the entry point of the lib. When setting up jest-extended on the CLI you need to tell Jest you are using jest-extended, Jest allows you to do that in the setupTestFrameworkScript field of the config.
If you wanted to also use expect with jest-extended in a browser you would need to import jest-extended and call expect.extend yourself inside of the code that is to be bundled up for the browser.
Something like the following might be what you want (not sure exactly)
const matchers = require('jest-extended/dist/matchers');
const expect = require('expect');
expect.extend(matchers);
module.exports = expect;
OMG I think that's exactly what I wanted! I'll give it a try and let you know. Thanks Matt!
Hi @mattphillips , your suggestion works great! Thanks so much!
Can I do something similar with jest-chain?
This worked for me:
import chain from 'jest-chain/dist/chain'
import matchers from 'jest-extended/dist/matchers'
import expect_ from 'expect'
expect_.extend(matchers)
const expect = chain(expect_)
So now I can do both chaining thanks to jest-chain, and use the more expressive tests from jest-extended. Great!
A question would be, is it worth bringing chaining directly into jest-extended, to enable that functionality out the box when you bring in jest-extended?
I presume (my outlook) is that jest-extended gives jest a tonne of steroid injections, this would just be another direct one of those things.
Hi, sorry for the late reply. You can close this issue if you'd like.