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

useFakeTimers with typescript #1740

Closed
aboeglin opened this issue Mar 20, 2018 · 5 comments
Closed

useFakeTimers with typescript #1740

aboeglin opened this issue Mar 20, 2018 · 5 comments

Comments

@aboeglin
Copy link

aboeglin commented Mar 20, 2018

I try to make an es6 project move to typescript. It's still pretty small at the moment. In the current test file there are no dependencies except the test file, chai and mocha.

I import sinon like this:

import * as sinon from 'sinon';

But it then throws at me when running the tests:

TypeError: Cannot read property 'now' of undefined
        at mirrorDateProperties (base/test/SESKApplication.test.js?cbd5a7d2db216d155cbf259dccb4fc057a6c807d:23248:16)
        at hijackMethod (base/test/SESKApplication.test.js?cbd5a7d2db216d155cbf259dccb4fc057a6c807d:23522:20)
        at Object.install (base/test/SESKApplication.test.js?cbd5a7d2db216d155cbf259dccb4fc057a6c807d:23793:13)
        at Object.exports.useFakeTimers (base/test/SESKApplication.test.js?cbd5a7d2db216d155cbf259dccb4fc057a6c807d:11686:21)
        at Context.<anonymous> (base/test/SESKApplication.test.js?cbd5a7d2db216d155cbf259dccb4fc057a6c807d:30655:21)

Everything else works just fine. It's only useFakeTimers which seems to be a little brittle somehow. I even tried to install types for lolex just in case, but that did not solve the issue.

  • Sinon version : 5.0.0-next.3 ( tried 4.3 originally with the same issue )
  • Environment : OSX 10.13.3
  • Other libraries you are using: Mocha, Karma, Chai, Typescript 2.6
@mroderick
Copy link
Member

@aboeglin did you find a solution to this problem?

@fatso83
Copy link
Contributor

fatso83 commented Mar 27, 2018

Whatever the reason is for this problem, it is highly likely to have nothing to do with TypeScript per se. Date or Performance is undefined for some reason, and as this problem is not reproducible without supporting code, I am closing this as it means we cant' do anything to help fix this until the issue description is improved.

@fatso83 fatso83 closed this as completed Mar 27, 2018
@iraklisg
Copy link

I am facing the same problem after upgrading from sinon@4.4.6 to sinon@6.0.1

I made a silly little test to showcase the issue:

describe('Countdown', () => {
    it('should works', () => {
            const clock = sinon.useFakeTimers();
            expect(clock).to.be.an.instanceOf(Object);
    });
});

The test will fail with the following errors:

  1. Countdown
    should works:
    TypeError: Cannot read property 'now' of undefined
    at mirrorDateProperties (.tmp/mocha-webpack/1530006960272/bundle.js:53971:20)
    at hijackMethod (.tmp/mocha-webpack/1530006960272/bundle.js:54274:24)
    at Object.install (.tmp/mocha-webpack/1530006960272/bundle.js:54664:17)
    at useFakeTimers (.tmp/mocha-webpack/1530006960272/bundle.js:54712:23)
    at Sandbox.useFakeTimers (.tmp/mocha-webpack/1530006960272/bundle.js:65700:47)
    at Context. (.tmp/mocha-webpack/1530006960272/bundle.js:24018:76)

@fatso83
Copy link
Contributor

fatso83 commented Jun 26, 2018

@iraklisg I cannot reproduce this locally or in this online demo. Try making a new demo in a fresh directory and make sure to install afresh (removing node_modules first). If it is still an issue, make a new issue.

@iraklisg
Copy link

@fatso83 sorry for the late reply, the issue is being reported also in #1852

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

4 participants