ohcibi
ohcibi

Reputation: 2698

Use ember mock server for ember test --server

when running ember server, the mocks in server/mocks are served properly, such that they can be used in the tests as well (as the tests are in localhost:4200/tests by default and the api from the mock server is available at localhost:4200/).

However when running ember test --server the mocks are not available which makes tests that rely on those mocks fail. Is this a bug? How to make the mocks available in the test server?

Upvotes: 1

Views: 266

Answers (1)

Pedro Rio
Pedro Rio

Reputation: 1444

I'm facing that issue myself and from what I could gather, at the moment you can't. There's a Pull Request on GitHUB where people talk about implementing that but it seems the direction is to change towards using the ember-cli-mirage addon (currently in version 0.0.24).

I haven't tried the ember-cli-mirage addon, but I did find an example on how to use it

test('searching', () => {
server.get('/jobs', json(200, {
jobs: [
  job({ title: 'UI Engineer'     }),
  job({ location: 'Palo Alto', title: 'UI Engineer'     }),
  job({ location: 'Palo Alto', title: 'Backend Engineer'}),
]
}));

server.get('/companies', json(200, {
companies: []
}));

return visit('/').then(() => {
equal(numberOfJobs(), 3, 'expected 3 jobs');

fillIn($('#search-field'), 'UI').then(() => {
  equal(numberOfJobs(), 2, 'expected 2 jobs');
});

fillIn($('#search-field'), 'ASDFASDF').then(() => {
  equal(numberOfJobs(), 0, 'expected 0 jobs');
});

fillIn($('#search-field'), 'Palo alto').then(() => {
  equal(numberOfJobs(), 2, 'expected 2 jobs');
});

return fillIn($('#search-field'), '').then(() => {
  equal(numberOfJobs(), 3, 'expected 3 jobs');
});
});
});

I hope that this may be of help.

Upvotes: 1

Related Questions