-
Notifications
You must be signed in to change notification settings - Fork 194
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.js for the browser #26
Comments
the design of should is pretty specific to modern js implementations that support accessors etc, my co-worker guillermo is almost done a nice option though using |
anyone actually using mocha is going to be using a modern js implementation. |
not necessarily, even modern safari has issues with keywords as props |
Safari 5.1 -- everything works OK for me. > a = {true: false, if: true, while: true}
Object
> a.while
true 👍 to this issue. |
Alternatively, you could use
I think there might still be a problem with |
Object.defineProperty isn't available in all browsers, though I'm sure it would be fine for modern browsers if that's all you care about |
For me supporting relatively modern browsers would be enough. However, I've just tested it and even though I can define a property called Still, this makes should.js run in older browsers (they will parse the JS without problems). The test itself must use alternative syntax though ( Actually, I'm working on making should.js work in PhantomJS which uses JavaScriptCore and I encountered another weirdness: 'test'.should.equal('test') Results in:
This seems to affect primitive types only. The lame fix I came up with is: Object.defineProperty(Object.prototype, 'should', {
set: function() {},
get: function() {
// TODO: who knows why this is needed in JavaScriptCore
// if not applied, "test" becomes { '0': 't', '1': 'e', '2': 's', '3': 't' }
// and 123 becomes {}
if (this instanceof String || this instanceof Number || this instanceof Boolean) {
return new assert.Assertion(this.constructor(this));
}
return new assert.Assertion(this);
},
configurable: true
}); If you are interested in merging those hacks, I can make a pull request. |
Having some free time I've made those modifications that make should.js work on JavaScriptCore:
I tried to modify as little code as possible. Nothing should be broken, all the tests pass. It should be easy to load it in a browser now using RequireJS. |
one advantage of "expect(x).to.eql(4)" over x.should.eql(4) is that it can On Wed, Nov 30, 2011 at 5:11 PM, Juliusz Gonera <
|
True, but you can also check |
yeah, that's a slight advantage, though it will break on null/undefined anyway, so it's essentially the same just not a nice message :) it's worth it IMO |
Shoot. Without should.js working in the browser it's not a very viable alternative to Jasmine (if you're testing client code). |
should.js isnt a requirement at all, you can use any assertion lib you want |
I guess we're talking about mocha now ;) Also, would you mind if I made a pull request of those two commits I mentioned (I mixed up names/urls in the previous message but I fixed it)? |
meh I'm not a fan of AMD, nor do I want to restrict their use to AMD. It wouldn't be difficult to make should work browsers, but with the current style of the lib it would be restricted to modern browsers |
As I said, I'm in favor of making it work only in modern browsers. As for AMD, many libraries detect it and work both with and without it (e.g. jQuery), also without much additional work. |
Modern browsers would be better than no browsers. I really like Speaking of AMD, its only a couple lines of code to optionally register as AMD like jQuery, backbone, and underscore do. Probably a separate issue though. |
yeah im sure someone could have a generic AMD wrapper script thingy, as for making should work in the browser, we could add the little script i use in jade and some others, or @guille created https://github.com/learnboost/browserbuild we could run it through that and see how it goes |
I went ahead and made an assert implementation that works for both node.js and browser. Its at https://github.com/logicalparadox/chai/. Has a |
FWIW, here's my implementation |
I have docs et all but they're in the hard drive with the backup from my laptop that was in the fire, I'll recover it soon |
Check if the value is truthy: this.obj == true should this be: !!this.obj == true ? On Thu, Dec 15, 2011 at 6:02 PM, Guillermo Rauch
|
+1 for having should.js work at least in modern browsers. |
In the meantime I'm using chai.js and its BDD style is pretty good. It also has the |
I'm using it too but having troubles with the html reporter, it just says "Script error" whenever an assertion throws. I'm not sure if that's the normal behavior though. @visionmedia any idea? |
c4milo with mocha + chai? not sure what we're talking about |
ops, yes, mocha + chai. Sorry I should just open an issue in chai. |
hmm could be chai |
@c4milo please post up your specs on chai issues and we can see whats going on |
closing this since we have chai |
le chai |
I would like to use Mocha BDD and run specs in the browser. Would be nice to have a build of should.js that doesn't rely on Node's stuff.
The text was updated successfully, but these errors were encountered: