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

new Date() instanceof Date returns false if jasmine.clock() is installed #678

Closed
chernetsov opened this issue Sep 23, 2014 · 4 comments
Closed

Comments

@chernetsov
Copy link
Contributor

No description provided.

@slackersoft
Copy link
Member

What version of jasmine are you using? I just ran this spec and it's green in the current code.

describe('with clock', function() {
  beforeEach(function() {
    jasmine.clock().install();
  });

  afterEach(function() {
    jasmine.clock().uninstall();
  });

  it('can date', function() {
    expect(new Date() instanceof Date).toBe(true);
  });
});

@chernetsov
Copy link
Contributor Author

Here is the test that fails.

  describe('with clock', function() {
    beforeEach(function() {
      jasmine.clock().install();
      jasmine.clock().mockDate();
    });

    afterEach(function() {
      jasmine.clock().uninstall();
    });

    it('can date', function() {
      expect(new Date() instanceof Date).toBe(true);
    });
  });

I use Jasmine version 2.0.1.

@slackersoft
Copy link
Member

Ahh, sorry, I didn't realize you were also mocking out Date. It looks like this is actually happening, not because the object being returned isn't a Date, but because the Date constructor has been rewritten to no longer be the original Date.

This looks like a bug we need to fix, so the state jasmine leaves Date in correctly passes an instanceof check. In the meantime, if you want to do something like:

expect(Object.prototype.toString.apply(new Date())).toEqual('[object Date]');

That should pass, and work in your code under test as well. I'll try to take a look at this at some point soon, but I'd definitely be glad to look at a pull request if you or anyone wants to give it a shot.

@chernetsov
Copy link
Contributor Author

Check out my pull request with the fix.

Tried to follow all the contributor's cookbook rules.

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

2 participants