utcOffset wrong return in jest.test
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
utcOffset Return number **"540"** in test
Write simple unit test for in my service, but all utc
my util
```ts
export function isBefore(_schedule: Date, _offset: number = 0): boolean {
if (!_schedule) return false;
const now = dayjs();
const schedule = dayjs(_schedule).utcOffset(_offset);
// console.log(schedule);
return schedule.isBefore(now);
}
```
```tsx
import {isBefore} from '~/utils/date';
const _isBefore = (testDate: Date, result: boolean) => {
expect(isBefore(testDate)).toBe(result);
};
describe('is_Before 테스트', () => {
it('isBefore test', () => {
const date = new Date();
_isBefore(date, true);
});
});
```
```
Console
console.log
540
at isBefore (src/utils/date.ts:44:11)
● is_Before 테스트 › isBeforeTest
TypeError: schedule.isBefore is not a function
44 | console.log(schedule);
45 | // console.log('isBefore End');
> 46 | return schedule.isBefore(now);
| ^
47 | }
48 |
49 | export function getScheduleText(_schedule: Date, _offset: number = 0): string {
at isBefore (src/utils/date.ts:46:19)
at _isBefore (__tests__/utils/date.test.ts:4:10)
at Object. (__tests__/utils/date.test.ts:10:5)
```
Real Service work correctly only problem in test
**Information**
- Day.js Version [e.g. v1.0.0]: 1.11.5
- OS: [e.g. iOS]: mac m1
- Browser [e.g. chrome 62]: node
- Time zone: [e.g. GMT-07:00 DST (Pacific Daylight Time)]: GMT-09:00
Contributor guide
Research direction
Start with src/utils/date.ts and __tests__/utils/date.test.ts, then run the failing Jest test to inspect the utcOffset result and the subsequent isBefore call. Done means the test no longer raises the reported TypeError and the date utility behavior is covered without breaking the service behavior described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100