I am working on a react webapp and have run into a really strange issue when trying to get my unit tests to pass.
Essentially I have a javascript class called Time that's essentially just the time component of a DateTime (its based on a Luxon Duration). I have added isBefore(Time) and isAfter(Time) methods to this class to allow two times to be compared.
These methods are used in a helper function (checkTimeRange) in another file to implement a three-way comparison (i.e. it can tell if one Time is before, during, or after a range denoted by two other Times).
Here's the state of my unit tests:
Timetests: passing, including forisAfter.- helper tests: passing, including for
checkTimeRange School,ClassPeriod, andBellSchedule(all classes that contain methods that indirectly depend oncheckTimeRange) tests for those methods are failing because<variable storing a Time>.isAfter is not a function
In researching, I found this, which seemed to describe the issue perfectly (in the title at least), but the solution seemed to be a simple typo, which doesn't appear to be the case here.
Things I have tried:
- checking out the project in another folder
- deleting and re-installing the node_modules
- clearing the yarn cache
- updating dependencies
- changing the functions from
public function name () {}syntax to arrow function (public const name = () => {}) syntax - checking for typos and variable shadowing
- running tests both via
yarn testand using the VSCode integration thats showing up in my editor (idk whats causing this to show up though) - placing a unit test for
Time.isAfterright alongside the case that is failing becauseisAfter is not a functionto show that its not a difference in how the different unit test files are set up - updating yarn from 1.17.3 to 1.22.19
I still have basically no idea as to what may be causing this. I have a feeling that maybe something deep inside Jest is not working properly, but I don't really know whats causing this contradicting behavior.
Here is the branch of the repo where im seeing this behavior if anyone needs more info on whats happening
The test that i'm looking at is the last one in the file of unit tests for the School class. However many of the other classes, like ClassPeriod also have their last test failing for similar reasons.
isAftermethods are?src/@typesfolder. the helpers file i referenced is atsrc/utils/helpers.tsx. tests can be run withyarn yest. let me know if you need more info! happy to create a chat (on SO or otherwise) and help walk through what im seeingcheckTimeRangehelper (the one that swapsstartTimeandendTime) seems to eliminate the problem with the tests (by causing the tests to report failure based on the actual test results). I have no idea why these lines are causing this problem thoughcheckTimeis used instead of the second (startTime) in theif (checkTime.isAfter(endTime)) {line ofcheckTimeRange. i have no idea why this may bestartTime.isAfter is not a functiontocheckTime.isBefore is not a function. this line is further down the program. It seems like calling instance methods on the first parameter passed to a function is making it angry somehow