title: Aurelia Unit Testing error due to aurelia.setRoot('shell/shell');
body: <p>I'm trying to implement unit test on login method but I'm getting <strong>"Cannot read property 'setRoot' of undefined"</strong> error.</p>
  
  <p>Here is my Login Method:</p>
  
  <pre><code>import { inject, Aurelia, NewInstance, computedFrom } from 'aurelia-framework';
  import { Router } from 'aurelia-router';
  import { Server, User } from 'backend/server';
  import { ValidationRules, ValidationController, validateTrigger } from 'aurelia-validation';
  import { ValidationRenderer } from 'resources/validation-renderer';
  </code></pre>
  
  <p>@inject(Aurelia, Router, Server, NewInstance.of(ValidationController), NewInstance.of(User))</p>
  
  <pre><code>constructor(aurelia, router, server, validationController, user) {
          this.router = router;
          this.aurelia = aurelia;
          this.validationController = validationController;
          this.server = server;
          this.user = user;
      }
  
  
   activate() {
      this.validationController.validateTrigger = validateTrigger.blur;
      this.validationController.addRenderer(new ValidationRenderer());
  
      ValidationRules
          .ensure(u =&gt; u.email)
          .required()
          .matches(/^(([^&lt;&gt;()\[\]\\.,;:\s@"]+(\.[^&lt;&gt;()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)
          .ensure('password')
          .required()
          .on(this.user);
  }
  
  
  logUserIn()
  {
   let promise = new Promise((resolve, reject) =&gt; 
  {
  
          this.loggingIn = true;
          this.messageColor = 'green';
          this.message = 'Authenticating...';
          this.loginSuccess = false;
          this.validationController.validate().then(errors =&gt; {
              if (!errors.valid) {
                  this.loggingIn = false;
                  return ({error: true});
              }
              return this.server.authenticate(this.user.email, this.user.password);
          }).then(result =&gt; {
              if (!result.error) {
                  this.messageColor = 'green';
                  this.message = 'Login Successful';
                  this.loginSuccess = true;
                  this.aurelia.setRoot('shell/shell');
                  resolve(result);
              } else {
                  this.message = '';
                  resolve();
              }
          }).catch(err =&gt; {
              if(!this.loginSuccess)
              {
                  this.messageColor = 'red';
                  this.message = err.message;
              }
              this.loggingIn = false;
              resolve(err);
          });
      });
      return promise;
  }
  </code></pre>
  
  <hr>
  
  <p>My unit test code:
  <strong>login.spec.js</strong>:   </p>
  
  <pre><code>describe('Login Unit Test', () =&gt; {
  var login = new Login();
  login.validationController = new ValidationController();
  login.server = new Server();
  it("shouldn't allow login", (done) =&gt; {
  console.log(login.messageColor);
    login.logUserIn().then((result) =&gt; {
      console.log(login.messageColor);
      console.log(login.message);
      expect(login.messageColor).toBe('red');
      done();
    });
  });
  it("Should log in", (done) =&gt; {   
    login.user = {email:'a@b.com', password:'abc'};
      console.log(login.user.email);    
    console.log(login.user.password); 
    login.logUserIn().then((result) =&gt; {
      console.log(login.messageColor);
      console.log(login.message);
      expect(login.messageColor).toBe('green');
      done();
      });     
  });
  });
  </code></pre>
  
  <hr>
  
  <p>Here is the error that i'm getting
  <em><a href="https://i.stack.imgur.com/WtOBd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WtOBd.png" alt="emphasized text"></a></em></p>
  
  <p>I would really appreciate any help. 
  Thanks.</p>