mercredi 6 juillet 2016

Angular2 Unit Testing Setup issue

Testing Guide
I have been following it.

NOTE : I have my app running without testing part.

Problem: I'm unable to load unit-tests.html. I think problem is very small but unable to figure it out. I'm using VisualCode and when I hit F5 it runs my app only. So how to load unit-tests.html?

My setup is as follow.

package.json

{
  "name": "angular2-quickstart",
  "version": "1.0.0",


  "scripts": {

    "test": "live-server --open=unit-tests.html",  
     //<------ I have added this as mentioned.

    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
     //<------ I tried to disable this line as well.

    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
    },


  "license": "ISC",
  "dependencies": {
    "@angular/common": "2.0.0-rc.4",
    "@angular/compiler": "2.0.0-rc.4",
    "@angular/core": "2.0.0-rc.4",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.4",
    "@angular/platform-browser": "2.0.0-rc.4",
    "@angular/platform-browser-dynamic": "2.0.0-rc.4",
    "@angular/router": "3.0.0-beta.1",
    "@angular/router-deprecated": "2.0.0-rc.2",
    "@angular/upgrade": "2.0.0-rc.4",
    "systemjs": "0.19.27",
    "core-js": "^2.4.0",
    "reflect-metadata": "^0.1.3",
    "rxjs": "5.0.0-beta.6",
    "zone.js": "^0.6.12",
    "angular2-in-memory-web-api": "0.0.14",
    "bootstrap": "^3.3.6"
  },
  "devDependencies": {
    "concurrently": "^2.0.0",
    "jasmine-core": "2.4.1",
    "lite-server": "^2.2.0",
    "typescript": "^1.8.10",
    "typings": "^1.0.4"
  }
}

unit-tests.html

<!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>

  <script src="../node_modules/systemjs/dist/system.src.js"></script>

  <script>
    System.config({
      packages: {
        'app': {defaultExtension: 'js'}
      }
    });

    System.import('app/app.spec')
      .then(window.onload)
      .catch(console.error.bind(console));
  </script>

</body>
</html>

app.spec.ts (NOTE: within app folder, app.spec.ts is there)

it('true is true', () => expect(true).toEqual(true));

Aucun commentaire:

Enregistrer un commentaire