Code Monkey home page Code Monkey logo

Comments (10)

mhevery avatar mhevery commented on August 15, 2024

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.

cclamb avatar cclamb commented on August 15, 2024

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.

mhevery avatar mhevery commented on August 15, 2024

I think that is accessible by this.fail() in the it, there is no global alias

from jasmine-node.

cclamb avatar cclamb commented on August 15, 2024

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.

cclamb avatar cclamb commented on August 15, 2024

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.

mhevery avatar mhevery commented on August 15, 2024

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.

cclamb avatar cclamb commented on August 15, 2024

Thanks!

from jasmine-node.

caoilte avatar caoilte commented on August 15, 2024

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.

danielellis avatar danielellis commented on August 15, 2024

@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.

caoilte avatar caoilte commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.