Reputation: 896
I use a http-stubs during an development of application prototype with ember-cli. What I want is to to reuse that stubs in the test environment, but can't figure out how because of looks like ember-cli use a fixture adapter for the test environment.
Upvotes: 1
Views: 166
Reputation: 8251
There was a PR to allow the use of the HTTP Mocks during testing, which sounds like what you are describing, but it was determined that this is not a good way to test your application.
From the issue discussing including the mocks, this comment stated:
...We can to an agreement that mocks are useful for development but are an anti-pattern in testing. We decided that instead of spending time making mocks working in
ember test --server
we are going to show how to do proper mocking in testing using Pretender.Stefan showed me an example of mocking with Pretender and the test code is much more readable than having mock server with responses hidden away in the ./server configuration. I'm going to spend some time this weekend looking at what can be scavenged from related PR...
An example from stefanpenner on how to set up pretender for testing was included in the original issue and can be found here.
An example test from that example looks like this:
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');
});
});
});
Upvotes: 3