How can we make a javascript unit testable

35 views
Skip to first unread message

Ashetty

unread,
Mar 21, 2015, 8:46:27 PM3/21/15
to jasmi...@googlegroups.com
(function($){
function helloWorld() {
 return "Hello world!";
}
})(jQuery);


How can we make the above javascript testable with jasmine ?  helloWorld here is not directly accessible to the spec javascript file.

Greg Cobb

unread,
Mar 21, 2015, 11:44:01 PM3/21/15
to jasmi...@googlegroups.com
A common pattern for something like this is:

//helloWorldSpec.js
describe('hello world', function(){
  it('returns "Hello world!"', function(){
    expect(myApp.helloWorld()).toEqual('Hello world!');
  });
});

//helloWorld.js
myApp.helloWorld = function() {
  return "Hello world!";
}

//boot.js
(function($){
  console.log(myApp.helloWorld());
})(jQuery);

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jasmine-js+...@googlegroups.com.
To post to this group, send email to jasmi...@googlegroups.com.
Visit this group at http://groups.google.com/group/jasmine-js.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages