Skip to content
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

Plugin: how to get calling test file's info #1477

Open
jacob-orbiit opened this issue Aug 19, 2022 · 0 comments
Open

Plugin: how to get calling test file's info #1477

jacob-orbiit opened this issue Aug 19, 2022 · 0 comments

Comments

@jacob-orbiit
Copy link

jacob-orbiit commented Aug 19, 2022

I'm trying to create a snapshot plugin for chai (and would be happy to contribute it); snapshots live adjacent to the test file itself. The docs related to creating plugins are rather…sparse, and I don't see anything related to that, and the info related to getting the actual value seems to be incorrect (I just get undefined).

For example:

// setup.mjs
chai.use(myChaiSnapshot);
export default function chaiSnapshotPlugin(chai, utils) {
  chai.Assertion.addChainableMethod('matchSnapshot', function matchSnapshot(...args) {
    const obj = utils.flag(this, 'string');
    console.log({ this: this, obj }, ...args);
  });
}
it('should contain debug into in dev mode', () => {
  expect('<div>debug: foo, bar, baz</div>').to.matchSnapshot();
});
{
  this: Assertion {
    __flags: [Object: null prototype] {
      ssfi: [Function: chainableMethodWrapper] Assertion,
      lockSsfi: undefined,
      object: undefined,
      message: undefined
    }
  },
  obj: undefined
}

I could pass import.meta.url to matchSnapshot() every time, but that would very inelegant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant