mardi 30 décembre 2014

Can I have more than one expectation inside an it block?

Just wondering because this behaviour is a little weird:



it 'shoud call console.log on mouse enter', ->
expect(console.log.calls.count()).toEqual 1


The above passes with no problems. The below passes with no problems either:



it 'shoud call console.log on mouse enter with the correct parameters', ->
expect(console.log).toHaveBeenCalledWith 'mouse has entered'


But this:



it 'shoud call console.log on mouse enter with the correct parameters', ->
expect(console.log.calls.count()).toEqual 1
expect(console.log).toHaveBeenCalledWith 'mouse has entered'


Doesn't fail, but gives me this strange error:



Opera 26.0.1656 (Linux) [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] encountered a declaration exception FAILED
TypeError: Cannot read property 'expect' of null


How can I prevent this error from occuring? Or is it normal? Something to do with coffeescript perhaps? Coffeescript automatically returns the result of the last function...


Here's what my rendered code looks like: (those returns are looking a little dodgy)


Update



describe('supermanDirective', function() {
var run;
run = function() {
module('App');
return injectDirective('<div enter></div>');
};
describe('something', function() {
beforeEach(function() {
return run();
});
return it('should be defined', function() {
return expect(element).toBeDefined();
});
});
describe('something', function() {
beforeEach(function() {
spyOn(console, 'log');
element.trigger('mouseenter');
return run();
});
it('shoud call console.log on mouse enter', function() {
return expect(console.log.calls.count()).toEqual(1);
});
return it('should call it with correct parameters', function() {
return expect(console.log).toHaveBeenCalledWith('mouse has entered');
});
});
return describe('something', function() {
beforeEach(function() {
spyOn(console, 'log');
return run();
});
return it('shoud call console.log on mouse enter', function() {
return expect(console.log.calls.count()).toEqual(0);
});
});

Aucun commentaire:

Enregistrer un commentaire