-
Notifications
You must be signed in to change notification settings - Fork 2
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
Defer capturing original matchers #9
Comments
That's a good point @jcarlson, What if import enzymeMatchers from 'expect-enzyme'
import customMatchers from './helpers/my-matchers'
expect.extend(customMatchers)
expect.extend(enzymeMatchers()) // invocation captures existing assertions It wouldn't be able to see any extensions added afterwards, but it would solve the import dilemma. |
If you import two assertion utilities and then later extend `expect`, `expect-enzyme` won't see the existing assertions and will simply wipe them out. Not ideal. This makes a breaking change: instead of exporting an object, `expect-enzyme` exports a function. Calling that function will capture the existing assertions and generate properly overloaded assertions. More details and discussion in issue #9
I've released v1.0 which exports a function. Instead of capturing the matchers on import, now it waits until it's invoked. That should help keep the |
Referring to this code snippet: https://github.com/PsychoLlama/expect-enzyme/blob/master/src/assertions.js#L120-L145
This creates a problem, because definitions for any original matchers are captured at the time this module is imported or required rather than at the time
expect
is extended. This can be problematic when used alongside app-specific matchers with colliding names.For example, the following does not work:
In the above example, as soon as
expect-enzyme
is imported, it captures any existing matchers, but they haven't been extended ontoexpect
yet. It is a syntax error to move theimport
statement forenzyme-expect
lower in the file, as allimport
statements must be at the top.This can be worked around using
require
syntax as follows:This second form allows
expect
to be extended with the app-specific matchers beforerequire
ing theexpect-enzyme
matchers. While this work-around is okay for my current use case, it might be more problematic if another module includedenzyme-expect
before the test setup module.Just thought you'd like to know.
The text was updated successfully, but these errors were encountered: