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

should not working in browser #6

Closed
jgallen23 opened this issue Jan 24, 2012 · 10 comments
Closed

should not working in browser #6

jgallen23 opened this issue Jan 24, 2012 · 10 comments

Comments

@jgallen23
Copy link

In firebug:

var should = chai.should() //actually call the the function
    , foo = 'bar';

  foo.should.be.a('string');
  foo.should.equal('bar');
  foo.should.have.length(3);
AssertionError: expected { '0': 'b', '1': 'a', '2': 'r' } to be a string
@jgallen23
Copy link
Author

this is in Firefox 9.0.1

@logicalparadox
Copy link
Member

The should interface does it's thing by extending Object.prototype on L22. Unfortunately, the fact is that FF and IE don't like this. The should tests suite does pass in chrome however, if your curious.

Unfortunately, nothing can be done. My recommendation is to use the expect interface:

var expect = chai.expect
  , foo = 'bar';

expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.length(3);

All of the same language applies.

@jgallen23
Copy link
Author

Very odd.

This seems to work fine in firefox:

Object.defineProperty(Object.prototype, 'should', {                                                                          
 get: function() {
     console.log(this);
 }
});
var a = '123';
console.log(a.should);

What, specifically, does firefox not like? It seems like it's fine with extending the Object.prototype, but all strings, numbers, etc, turn into object literals inside the property? is that right?

@logicalparadox
Copy link
Member

Found a bit of a work around. Check out branch bug/issue-6 ... 067d966

Should tests for this branch are passing in Chrome 16, FF 9.0.1, Safari 5.1.2.

Let me know if it works out and I will pull it into the next release later today/tomorrow.

logicalparadox added a commit that referenced this issue Jan 25, 2012
@jgallen23
Copy link
Author

I just grabbed 0.1.7 and everything works great in firefox now. Thanks!

@logicalparadox
Copy link
Member

This patch has been included in 0.1.7. The commit was 48f3815 if your curious.

I also retract my previous statement. Apparently something can be done. Thanks for the motivation :)

Let me know if it troubles you further.

@jgallen23
Copy link
Author

FYI, it's really close to working in IE9 as well. For some reason any number sets this == 0. Trying to figure out a workaround. Other than that, everything seems to work

@logicalparadox
Copy link
Member

That would be awesome if it did. Thanks for the update... will accept pull requests!

@jfirebaugh
Copy link
Member

Should the website be updated? It still says "Should tests do not run in the browser."

@logicalparadox
Copy link
Member

Yeah, the api also a few versions outdate. I'm in the process of updating my docs generator so should be up in a day or two. Opened #12 in response.

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

3 participants