Learn how to a build a cloud-first strategyRegister Now

x
?

Advice on how to complete unit test coverage on this function

Posted on 2017-10-12
0
Low Priority
?
33 Views
Last Modified: 2017-10-13
I'm learning how to unit test an Angular 2 application and I would appreciate some guidance here. In the function below, I have some code that connects to a SQLite database and runs a transaction. I am trying to understand how to unit test the parts in red (shown in screen shot). Can you please help me to understand how I would write tests that generate coverage?

I am using Jasmine 2.5.3, karma 1.5.0 and angular 4.1.3.

Thank you for advice and guidance.

runSqlTransaction(db: SQLiteObject) {
    this.db = db;
    return new Promise((resolve, reject) => {
      this.db.open().then((res) => {
        try {
          db.transaction(tx => {
            this.tx = tx;
            tx.executeSql(this.sqlQuery, this.params,
              (tx: any, res: any) => resolve({ tx: tx, res: res }),
              (tx: any, err: any) => reject({ tx: tx, err: err }));
          });
        } catch(e) {
          reject(e);
        }

      }).catch(e => {
        console.log('Is the database open failed', e);
      });
    });
  }

Open in new window


Coverage
0
Comment
Question by:gmsetzer
0 Comments

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Join & Write a Comment

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question