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

[expect-expect] support chained function names #471

Closed
erunion opened this issue Nov 9, 2019 · 5 comments
Closed

[expect-expect] support chained function names #471

erunion opened this issue Nov 9, 2019 · 5 comments

Comments

@erunion
Copy link
Contributor

erunion commented Nov 9, 2019

[see #418 for previous discussion]

Currently expect/expect doesn't recognize supertest or sinon assertions. For example:

const spy = sinon.spy()
it('should work as expected', async () => {
  // test code here

  sinon.assert.calledOnce(spy);
});

Adding sinon (or calledOnce) into the assertFunctionNames configuration block doesn't get recognized, so it would be cool to:

  • Be able to supply full, chained, functions to assertFunctionNames like sinon.assert.calledOnce.
  • It would also be neat to be able to do the same but with a glob-style syntax. Something to the effect of sinon.assert.* or for supertest cases, request.*.expect.
@erunion
Copy link
Contributor Author

erunion commented Nov 9, 2019

Turns out adding sinon.assert.calledOnce into assertFunctionNames works, and has tests, already! It would still be nice to be able to do glob syntax since right now the only way to kind of get supertest matching is to add your common supertest constant name (likely request) as a function name, and that's way too general. Not to mention having to duplicate every sinon assertion.

@G-Rath
Copy link
Collaborator

G-Rath commented Nov 9, 2019

Yeah I was pretty sure I'd already implemented that for this exact reason 😄

While I understand why globbing sounds useful, I feel like it could be an easy footgun since it could result in non-assertion method being counted by mistake.

Plus as soon as you have "globbing" people generally expect it to work in a similar way to how it does everywhere else, so we'd have to add a new dependency for something like micromatch or globby.

None of these are a hard no, but I'll have it on the backburner for now, and have a think.

@erunion erunion changed the title [expect/expect] support chained function names [expect-expect] support chained function names Nov 9, 2019
@jrnail23
Copy link

jrnail23 commented Nov 27, 2019

@erunion, I just stopped by to create an feature request for this exact issue (supertest's expect), so you already beat me to it.

@G-Rath, I tend to agree with your concerns about globbing, but would it be possible to (optionally) detect usages of a method by name, rather than only standalone functions?

@erunion
Copy link
Contributor Author

erunion commented Nov 27, 2019

Instead of globbing, I've been playing around with a PR that'd support regex matching instead, but haven't made much progress so far due to my lack of ESLint parsing internals.

folke added a commit to folke/eslint-plugin-jest that referenced this issue Jan 10, 2020
G-Rath pushed a commit that referenced this issue Jan 10, 2020
* feat(expect-expect): support chained function names (#471)

* feat(expect-expect): updated docs with an example for supertest

* fix: coverage for no-jasmin-globals with chained functions
github-actions bot pushed a commit that referenced this issue Jan 10, 2020
# [23.4.0](v23.3.0...v23.4.0) (2020-01-10)

### Features

* **expect-expect:** support chained function names ([#471](#471)) ([#508](#508)) ([beb1aec](beb1aec))
* **rules:** add support for function declaration as test case ([#504](#504)) ([ac7fa48](ac7fa48))
@folke
Copy link
Contributor

folke commented Jan 12, 2020

This issue can be closed since 295ca9a implements this

@erunion erunion closed this as completed Feb 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants