Code Monkey home page Code Monkey logo

Comments (4)

Skn0tt avatar Skn0tt commented on October 10, 2024 1

Happy to hear you solved your problem. As you can see, I deleted my comment with the recommendation because I really don't want anybody who doesn't understand the consequences of importing a private package to see it. But you seem to be aware of that, so have fun! :D I'll close the issue.

from playwright.

yury-s avatar yury-s commented on October 10, 2024

As a workaround you can save original matchers before extending the expect and later call them from your implementation:

const originalToHaveText = (baseExpect as any).toHaveText; 

const dateExpect = baseExpect.extend({
  async toHaveText(this: ExpectMatcherState, date: Date, expected: string | RegExp, options?: { ignoreCase?: boolean, timeout?: number }): Promise<MatcherReturnType> {
...
      } else {
        originalToHaveText.call(baseExpect(date as Locator), expected, options);
      }
...
  },
});

would that work for your scenario?

from playwright.

LeviticusMB avatar LeviticusMB commented on October 10, 2024

I can't get that to work either ... originalToHaveText is (...u)=>new i(!1,...u) which seems to return an AsymmetricMatcher when called:

i {
  '$$typeof': Symbol(jest.asymmetricMatcher),
  sample: [ [ 'Node.js', 'Python', 'Java', '.NET' ], undefined ],
  inverse: false
}

Not sure what to do with this object? Need to build a MatcherReturnType from that somehow.

(I also tried to save (baseExpect({}) as any).toHaveText, but it seems the dummy value is captured so I can't provide the actual Locator when calling it later.)

from playwright.

LeviticusMB avatar LeviticusMB commented on October 10, 2024

Didn't work as-is for me (Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/matchers/matchers' is not defined by "exports" in .../package.json, but I got it working in the import-internal-matchers branch of the demo repo.

It's a bit tricky to actually get the path of matchers.js reliably (playwright might not be hoisted), but the demo code is currently working for all combinations of npm/yarn/pnpm, esm/cjs and Node 16/18/20/22 (at least on macOS).

I think I will go with this approach and cross my fingers it doesn't break too often. Thanks for the help!

PS. It would obviously be totally awesome if @playwright/test had a public export of all the built-in matchers (including toBe etc from the bundled expect library) so we could reuse and extend them in a supported way. Getting the MatcherReturnType right is quite some work.

from playwright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.