title: Typescript, Express, Mocha & Chai Error while testing
body: <p>I made my first server using express in typescript and it perfectly works</p>
  
  <pre><code>import app from './Server'
  
  const server = app.listen(8080, '0.0.0.0', () =&gt; {
      console.log("Server is listening on standard port 80...");
  });
  
  export default server;
  </code></pre>
  
  <p>Now I try testing the routes stored in app:</p>
  
  <pre><code>import express from 'express';
  import * as bodyParser from "body-parser";
  
  const app = express();
  
  app.use(bodyParser.json());
  
  app.get("/", (req: express.Request, res: express.Response) =&gt; {
      res.status(200).send("SUCCESS");
  });
  
  export default app;
  </code></pre>
  
  <p>Using this test:</p>
  
  <pre><code>import * as chai from 'chai';
  import chaiHttp = require('chai-http');
  
  chai.use(chaiHttp);
  
  import server from '../src';
  
  describe("LogAPI", () =&gt; {
  
      describe('Base express tests', () =&gt; {
          it("Should return 'SUCCESS' if GET /", async () =&gt; {
              return chai.request(server).get("/").then(res =&gt; {
                  chai.expect(res.body).to.equal("SUCCESS");
              })
          });
  
          it("Should return status-code 200 by calling GET /", async () =&gt; {
              return chai.request(server).get("/").then(res =&gt; {
                  chai.expect(res.status).to.equal(200);
              })
          });
  
      });
  });
  </code></pre>
  
  <p>But even while running the server itself works, staring the test with</p>
  
  <pre><code>mocha --require ts-node/register ./../test/**/*.ts
  </code></pre>
  
  <p>throws me this error: </p>
  
  <blockquote>
    <p>/Users/.../NotificationService/src/Server/index.js:5
    var app = express_1.default();
                              ^
    TypeError: express_1.default is not a function
       at Object. (/Users/.../NotificationService/src/Server/inde> x.js:5:28)</p>
  </blockquote>
  
  <p>I am using es6 target and commonjs module.
  How can I properly test my server?</p>
  
  <p><strong>Update 1</strong>
  I now fiddled a bit and it turned out that deleting the <code>default()</code> method from the compiled code resolved something.</p>
  
  <p>Now, I get </p>
  
  <blockquote>
    <p>/Users/.../NotificationService/test/node_modules/@types/chai-http/index.d.ts:13
    import * as request from 'superagent';
    SyntaxError: Unexpected token import</p>
  </blockquote>
  
  <p><strong>Update 2</strong>
  My ts-config.json:</p>
  
  <pre><code>{
    "compilerOptions": {
      "target": "es6",
      "module": "commonjs", 
      "outDir": "./../out“,
      "strict": true,
      "esModuleInterop": true   
    }
  }
  </code></pre>