Insights into Jasmine and Karma

Unit testing has become a standard in most application development teams. If you are familiar with unit testing, then you’ll already know how confident a developer feels when refactoring tested code. If you are not familiar, then imagine getting rid of deployment stress, a “code-and-pray” coding style and never-ending feature development. The best part of it? It’s automatic.

Unit testing, as the name implies, is about testing individual units of code. Unit tests try to answer questions such as “Did I think about the logic correctly?” or “Does the sort function order the list in the right order?”

Unit tests greatly improve codes twofold by forcing you to write modular logic units, instead of large code chunks.

Unit testing also provides you with documentation that is always up to date and informs you about the code’s intentions and functional behavior. Even if a method has a cryptic name — which is bad, but we won’t get into that here — you’ll instantly know what it does by reading its test.

Recently I have been involved in writing a lot of unit tests for our Angular application, which is why I have written this blog.

It was just a few hours into the process that I realized it had been a big mistake ignoring the unit tests for such a long time. The code base had been growing, and as is usually the case, was getting more complicated with every new feature or modification. Fortunately, we did have another task(s), to clean some portions of our code and to ensure they are testable.  What I learnt from this is that it’s never too late to write tests!

We adopted Jasmine+Karma for our unit testing from the get go. That was my initial choice because after researching Angular Testing frameworks I realised that it was what all the ‘cool kids on the block’ use. The best place to look for testing documentation was the Developer Guide of Angular (

From my research on some popular Unit Testing frameworks for JavaScript I found the most prominent ones:
1. Jasmine
2. Mocha
3. QUnit
4. Tape
5. AVA


Jasmine framework supports a software development practice which is called Behavior Driven Development or BDD. This is one of the main features of Test Driven Development (TDD).   This is the core framework that I chose to write our unit tests with.  Jasmine and BDD try to describe a test method case in a human-readable pattern so that any user, including a non-technical person, can identify what is going on. Jasmine tests are written using JavaScript functions, which makes writing tests a nice extension of writing application code. There are several Jasmine functions in the example, which are described below:

describe       : This method is used to represent a group with related test blocks. This method needs two arguments to execute –

  • Test name
  • A function

beforeEach : This method is fired before each test block.

it                    : This method executes a function to perform a test operation.

expect          : This method evaluates the result from the test block and performs the assertion statements.

toEqual        : This method is used to compare the expected result and the actual result.

beforeAll     : This method is executed only once in the test block to provide the description of the test suites.

On evaluation, the recommended test runner here was Karma and I will detail the advantages and disadvantages from working in a highly scalable application:


  1. Jasmine is a BDD (Behavior Driven Development) framework
  2. One single unit test framework. Don’t need extra assertion library or anything for test doubles
  3. Easy to read and learn
  4. Angular has a developer guide for unit testing Angular applications using Jasmine and Karma
  5. Lesser issues open in github and has more watchers as compared to Mocha and chai
  6. Integrates well with Visual Studio Code and Webstorm
  7. Runs for both Node.js and browser


  1. Assertion library is not as rich as chai
  2. Less flexibility. Especially when it comes to making assertion and mocking utilities richer. (in Mocha, you can use any assertion library that is suitable for the project)
  3. A specific file suffix is expected (*.spec.js)
  4. Asynchronous testing is not that great (though in Jasmine 2.x it is similar to Mocha, but before that it is extremely terrible). Working with promises and async code is not as good as mocha/chai-as-promised

So why Is Unit Testing Required in Angular you may ask?

  • It protects the existing code, which can be broken due to any changes.
  • Integrates an automatic build process to automate the pipeline of resource publishing at any time.
  • Clarifies what the code does, both when used as intended, and when faced with deviant conditions. Serves as a form of documentation for your code.
  • Reveals mistakes in design and implementation. When a part of the application seems hard to test, the root cause is often a design flaw, something to cure now rather than later when it becomes expensive to fix.
  • It allows us to test the interaction of directives or components with its template URL.
  • It allows us to easily track change detection.
  • It also allows us to use and test the Angular Dependency Integration framework.

Developing a UI in Angular? Invest in Unit Testing with Jasmine and Karma for peace of mind!

HFM Awards 2018 Shortlist

Synetec is excited to share that we have been shortlisted for the HFM European Hedge Fund Services Awards 2018!

We’re very proud to receive this acknowledgement from HFM Week for the amazing work we’ve done to help our clients achieve their compliance obligations for MiFID II.

The team has been incredible in delivering solutions that met our clients’ goals within extremely tight deadlines and it’s wonderful to see this being recognized at a national level.

The awards ceremony takes place on 26th April 2018 at The Hurlington Club, London.

The Cost of Compliance – how can you turn this into an advantage?



Over the last 3 years we’ve seen many firms in the financial sector scrambling to meet the compliance requirements of multiple regulations that have been introduced.  The revised Markets in Financial Instruments Directive known as MiFID II went live on January 3 this year following the 2016 publication of the FCA’s Market Abuse Regulation, and the EU’s GDPR enforcement deadline May 25 is just around the corner.

These are just three of the new regulations entering the financial sector and between them they contain significant and wide-spread legislative reform.  Multiple aspects are covered, from trading to recording and monitoring of data, transparency around research costs, new product governance rules and increased personal data protection.  These regulations also carry the potential for heavier fines for non-compliance.  GDPR is an example of this with maximum fines of up to 4% of annual global turnover or €20 Million (£17 Million) for serious breaches compared to the £500,000 maximum applied by the ICO.

As regulations in the financial sector continue to grow in number and complexity, companies need to continue substantial investment to meet their obligations.  For many organisations, the required increase in compliance initiatives, systems and process changes will become unsustainable as staffing commitments continue to grow.  In some institutions this strain is already felt with compliance staffing numbers now matching front office staff one-to-one.

We believe that the increase of regulations can provide many opportunities for organisations to see a return on investment from these ‘enforced’ initiatives if they take a forward-thinking approach.  We’ve implemented many different solutions for businesses to meet their compliance obligations and the most rewarding are those that use the data they’re collecting.  Companies collect and store huge amounts of data and this will continue to increase as more regulations are introduced.  Organisations should be making use of innovative technology to mine this data to achieve significant business insight which can be applied to operating and growth strategies.


One of the requirements being enforced by many regulations is the collection and storage of communication information which must be readily available at the request of authorities or clients.  To ensure regulation requirements are met, actively monitoring this communication information is important for the early detection of possible compliance breaches.  However, the struggle for many companies is in identifying how to successfully transform this communication information into data that makes sense.  Analysis of this data in context to business events and incidents can provide powerful insights which can be applied to important business decisions.  The key to unlocking this potential value lies in the use of NLP (natural language processing) and Machine Learning.  With the use of NLP and Machine Learning these ‘soon-to-be’ terabytes of communication can be monitored and analysed to provide near real-time insights, not to mention exceeding any expectations the FCA or investors would have.

For example, Lloyd’s Banking Group employs NLP in conjunction with ML techniques to identify fraudulent phone calls and Deutsche bank has shown that NLP-based techniques can provide significant improvement to quantitative investing models and stock price prediction.  Amazon has also employed NLP to huge success with their Alexa-enabled devices. According to industry estimates sold approximately 11 million Alexa-enabled devices by the end of 2016, or roughly 70 percent of the existing market at the time for virtual assistant products.

Further-more, NLP-based sentiment analysis techniques can be applied to stored communications records, reports, and even social media or other web content to effectively determine whether those sources contain positive or negative expressions.  We have been working with organisations who record and store their communication information to provide them with real-time monitoring and analysis of this data through the use of NLP and Machine Learning.  This not only ensures companies remain compliant with early detection alerts of potential breaches, but results in further benefits such as the deep understanding and monitoring of what their clients and associates think about them, their products and services.  Analysed in the context of business as usual, it could assist in pre-empting margin calls for example, this is extremely powerful.

Hiroshi Sasaki, our Head of NLP at Synetec, is highly experienced in building the knowledge bases behind NLP utilizing active learning, text mining and LUI (language user interface), he says,

“Using NLP can turn your compliance costs into a business opportunity by giving you significant business insights. Through readily available and improved transcription technologies, NLP and machine learning we can accurately identify topics, behaviour and the related sentiment. Who said what, how they said it and where they said it!”

Hiroshi completed a Master’s Degree in Computational Linguistics at the Nara Institute of Science and Technology in 2003 and has previously worked for Toshiba in their Research and Development Centre in Japan.  Hiroshi’s projects focussed on how to reduce the cost of manual data labelling that is required for ML and he is very interested in effectively applying these techniques to real business problems.

There are several components that need to be understood to truly make NLP work for you and your business, including Topic, Behaviour and Sentiment Identification.  These areas provide huge benefits in the use of NLP techniques to mine your data effectively and we’ll be writing about each of these in future posts, so stay tuned.


Synetec is a solutions provider certified in many diverse development technologies, such as Microsoft and AWS, delivering integration and development solutions since 2000.

We work with a number of the UK’s most respected financial institutions to deliver a range of innovative solutions. We have expertise in working with both established businesses as well as start-ups and extreme growth businesses.


Written by Natasha Walters

Page 4 of 17« First...23456...10...Last »




509 The Print Rooms
164-180 Union Street
London, SE1 0LH
Phone: 0208 1444 206


Important: The information contained in this website is for general information purposes only. Any reliance you place on such information is therefore strictly at your own risk. Synetec Ltd endeavour to keep it up to date and correct.
All images are copyrighted to their respective owners.