Kurshith
Kurshith

Reputation: 81

Cli mirage routes not working in acceptace test

I was trying acceptance test for login page, using cli mirage as mock server. Routes defined in a mirage works fine, when accessing it from application. But when trying it in ember test it returns

Mirage: Your Ember app tried to POST 'http://localhost:4200/tests?module=Acceptance | login', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?

Acceptance Test

test('visiting /login', function(assert) {
  server.create('login', { username: '[email protected]', password: 'password' });
  visit('/login');

  fillIn('input[placeholder="Email"]', '[email protected]');
  fillIn('input[placeholder="Password"]', 'password');
  click('button.btn-primary');

  andThen(function() {
    assert.equal(currentURL(), '/route');
  });
});

Mirage/config

import Mirage from 'ember-cli-mirage';
export default function() {
this.post('/token', function(db, request) {
  var params = formEncodedToJson(request.requestBody);

  if(params.username === "[email protected] && params.password === "password") {
    return {
      "auth":"Pass$Word",
      "token_type":"bearer"
    };
  } else{
    var body = { errors: 'Email or password is invalid' };
    return new Mirage.Response(401, {}, body);
  }
});

How to rectify this issue? someone help me please.

Upvotes: 1

Views: 1701

Answers (2)

wen
wen

Reputation: 41

for me, I have explicitly add host etc because without it, it resolves to a different port from my mirage config.js

Upvotes: 0

Kurshith
Kurshith

Reputation: 81

Issue is in environment configuration. After defined configurations for test worked fine.

Upvotes: 1

Related Questions