The most common way to test Angular 2 apps is with the Jasmine test framework. Jasmine allows you to test your code in the browser.
To get started, all you need is the jasmine-core
package (not jasmine
).
npm install jasmine-core --save-dev --save-exact
To verify that Jasmine is set up properly, create the file ./src/unit-tests.html
with the following content and open it in the browser.
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>Ng App Unit Tests</title> <link rel="stylesheet" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css"> <script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script> <script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> <script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script> </head> <body> <!-- Unit Testing Chapter #1: Proof of life. --> <script> it('true is true', function () { expect(true).toEqual(true); }); </script> </body> </html>