fix: Mark underscored methods as private - #638
Conversation
privateprivate
privateprivate
|
Generally speaking, spying on private methods is a code smell, unit tests should relay on the public API of a class only. But there's a lot of history in this repo, so it's not an easy fix. |
As in, one PR would mark one method as private, removing/rewriting tests that rely on it?
can you expand a bit on what a better approach would be? |
|
I'm not sure I have a better approach besides removing _ from methods/fields that are in use outside a class (like _map, _style, etc). One PR for a class/file I think would make sense. |
|
Makes sense. Feel free to close this PR then (if you see fit) and I'll see if I can chip away at this |
|
Oh, wait, I was under the impression we are talking about maplibre-gl-js, my mistake. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #638 +/- ##
==========================================
- Coverage 88.80% 0.00% -88.81%
==========================================
Files 3 3
Lines 929 561 -368
Branches 189 154 -35
==========================================
- Hits 825 0 -825
- Misses 104 561 +457 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
I took a stab at #186. The approach is to mark all underscored methods as
private(where not already the case), which excludes them from the docs:However, this breaks a bunch of unit tests that want to
spyOn()those methods. I addressed that by switching some method calls to bracket notation, ie:... and bumping
vitestandvitest/coverage-v8to^v5.0.0-beta.2, which adds support for spying on private methods.It's unclear to me if marking these methods
privateconstitutes a breaking change. Happy to amend the PR when/if the vitest feature makes it into a stable release.Closes #186
mainheading before merging