I'm using the Jasmine BDD Javascript library and really enjoying it. I have test code that I'd like to reuse (for example, testing multiple implementations of a base class or running the same tests in a slightly different context) and I'm not sure how to do it using Jasmine. I know that I could move code out of the jasmine functions and into reusable classes but I like the way the code reads interspersed with the Jasmine functions (describe, it) and I don't want to separate the specs from the test code unless I have to. Has anyone out there using Jasmine come across this issue and how have you handled it?
Jasmine is one of the popular JavaScript unit testing frameworks which is capable of testing synchronous and asynchronous JavaScript code. It is used in BDD (behavior-driven development) programming which focuses more on the business value than on the technical details.
Angular ships with Jasmine, a JavaScript framework that enables you to write and execute unit and integration tests.
One of the quickest ways to get your tests running faster is by running your tests in parallel, with karma-parallel. This npm package splits your unit tests into multiple suites that run in parallel with each other, on different threads of your processor.
Here is an article by a guy at Pivotal Labs that goes into detail about how to wrap a describe call:
DRYing up Jasmine Specs with Shared Behavior
Snippet from the article that shows part of the wrapper function:
function sharedBehaviorForGameOf(context) { describe("(shared)", function() { var ball, game; beforeEach(function() { ball = context.ball; game = context.game; }); }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With