Comments (10)
Are you sure that fail is defined in Jasmine? I just looked over their API, and I don't see it. Jasmine-node just uses jasmine so there is no extra magic there
from jasmine-node.
On 10/11/2011 11:20 AM, Miško Hevery wrote:
Are you sure that fail is defined in Jasmine? I just looked over their API, and I don't see it. Jasmine-node just uses jasmine so there is no extra magic there
Assuming I'm not misreading something
(http://pivotal.github.com/jasmine/jsdoc/symbols/jasmine.Spec.html) tt's
defined alongside describe(.) and it(.)
from jasmine-node.
I think that is accessible by this.fail() in the it, there is no global alias
from jasmine-node.
Hmm, gives me this, with the test:
it('should support adding items', function() {
this.fail('f');
});
cclamb@fawkes:~/Work/grocery-list$ jasmine-node test/spec
Started
...........FFFF
/usr/lib/node_modules/jasmine-node/lib/jasmine-node/index.js:52
text.split(/\n/).forEach(function(line){
^
TypeError: Cannot call method 'split' of undefined
at Object.removeJasmineFrames as stackFilter
at
/usr/lib/node_modules/jasmine-node/lib/jasmine-node/reporter.js:105:53
at Array.forEach (native)
at
/usr/lib/node_modules/jasmine-node/lib/jasmine-node/reporter.js:100:21
at Array.forEach (native)
at Object.reportSuiteResults
(/usr/lib/node_modules/jasmine-node/lib/jasmine-node/reporter.js:89:24)
at [object Object].reportSuiteResults
(/usr/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1508:39)
at [object Object].finish
(/usr/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2169:21)
at [object Object].onComplete
(/usr/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2216:10)
at [object Object].next_
(/usr/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1800:14)
While a test with this.fail() gives me:
it should support adding items
TypeError: Cannot read property 'stack' of undefined
at [object Object]. (/Users/cclamb/Work/grocery-list/test/spec/list_spec.js:36:8)
Finally, this:
it('should support adding items', this.fail());
gives me this trace:
s907454:grocery-list cclamb$ jasmine-node test/spec/
Started
...........F
list
it encountered a declaration exception
TypeError: Object [object Object] has no method 'fail'
at [object Object]. (/Users/cclamb/Work/grocery-list/test/spec/list_spec.js:35:41)
at Object. (/Users/cclamb/Work/grocery-list/test/spec/list_spec.js:10:1)
at Module._compile (module.js:411:26)
at Object..js (module.js:417:10)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)
at require (module.js:355:19)
at Object.executeSpecsInFolder (/Users/cclamb/node_modules/jasmine-node/lib/jasmine-node/index.js:73:5)
I'm going to spend some time trying to find out how the Jasmine project handles explicit failure calls to compare, then I'll post back so we have a record.
from jasmine-node.
So here: http://try-jasmine.heroku.com/
I tried this test:
describe('panda',function(){
it('is happy',function(){
this.fail();
});
});
which failed with this trace:
Error: Exception
at new (http://try-jasmine.heroku.com/js/vendor/jasmine-1.0.2/jasmine.js:94:50)
at [object Object].fail (http://try-jasmine.heroku.com/js/vendor/jasmine-1.0.2/jasmine.js:1963:27)
at [object Object]. (eval at (http://try-jasmine.heroku.com/js/try-it.js:30:14))
at [object Object].execute (http://try-jasmine.heroku.com/js/vendor/jasmine-1.0.2/jasmine.js:968:15)
at [object Object].next_ (http://try-jasmine.heroku.com/js/vendor/jasmine-1.0.2/jasmine.js:1739:31)
at http://try-jasmine.heroku.com/js/vendor/jasmine-1.0.2/jasmine.js:1729:18
This is what I'd expect to see. So the case where the call is this.fail() is correct, but it's not handled correctly after the failure (see the previous post with text.split(.) crashing).
from jasmine-node.
so I looked into it and it is a bug in jasmine. Jasmine fail function expects to get an Error and it does not fail gracefully
so the correct thing to write is: this.fail(Error('abc'));
I think they may have regressed it in the 2.0 version of jasmine. Here is the function. Notice how they assume tha e existis and that it has a trace attribute.
jasmine.Spec.prototype.fail = function (e) {
var expectationResult = new jasmine.ExpectationResult({
passed: false,
message: e ? jasmine.util.formatException(e) : 'Exception',
trace: { stack: e.stack }
});
this.results_.addResult(expectationResult);
};
from jasmine-node.
Thanks!
from jasmine-node.
I'm finding I can't use fail within callbacks. For example,
describe('panda',function(){
it('is happy',function(){
fs.writeFile("target/test/happyPanda.txt", "Hey there!", function(err) {
this.fail(Error('abc'));
});
asyncSpecWait();
});
});
TypeError: Object # has no method 'fail'
from jasmine-node.
@caoilte, the code inside the callback is executing in its own scope, so the "this" in this.fail(...) is no longer referring to the Jasmine object that contains the fail member. If you are running your tests in an environment that supports it (JavaScript 1.8.5 and later, I believe), call .bind(this) on your callback function:
describe('panda',function(){
it('is happy',function(){
fs.writeFile("target/test/happyPanda.txt", "Hey there!", function(err) {
this.fail(Error('abc'));
}.bind(this));
asyncSpecWait();
});
});
If you haven't already, I would suggest reading up on how the bind function works and refresh yourself on the concept of scope in JavaScript. It's tricky, but understanding it is critical.
from jasmine-node.
Oh, of course! Thanks Daniel. I have been using binds but hadn't spotted how applying them would help here.
from jasmine-node.
Related Issues (20)
- Combination of --verbose and --noStack
- Upgrade gaze version HOT 2
- What's the status of this project? HOT 5
- jasmine-node can't find tests HOT 1
- --forceExit option on v2.0.0 beta not working
- jasmine.any(Array) breaks when vm.runInNewContext is used
- jasmine-node file.js take long time
- Command Injection due to old node-modules HOT 6
- Dependency coffee-script triggers a failure on Windows. HOT 1
- (node:10112) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'isBllingPaymentLinkDisplayed' of undefined
- SyntaxError: Unexpected token import HOT 1
- npm updates badly needed HOT 3
- v1.14/v1.15 includes a breaking change in a minor version. HOT 16
- Enable Travis CI for Node.js 0.x, 4, 6, 8, 10
- Use tilde (~) instead of carrot (^) in version 1 HOT 1
- New major release - feature release HOT 1
- 2.0 BETA with Jasmine 2.0 & rewrite in CoffeeScript no longer supported
- major: use please-upgrade-node
- Slow Uint8Array comparison HOT 1
- Vulnerability in dependency underscore HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jasmine-node.