-
-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mockFindAll, mockQuery, etc weird behavior with fails #224
Comments
This sounds like a pretty good bug. |
Oh well, I think your going to have to write the failing case because I did this: mockQuery('user', { name: 'Bob' }).fails();
mockQuery('user', { name: 'Dan' });
FactoryGuy.store.query('user', { name: 'Dan' })
.then(()=> {
ok(true);
done();
}); and this test passed. So I guess I don't understand how to recreate this bug. |
I also tried: mockQuery('user', { name: 'Bob' }).fails();
mockQuery('user', { name: 'Dan' });
FactoryGuy.store.query('user', { name: 'Bob' }).catch(()=>{
FactoryGuy.store.query('user', { name: 'Dan' })
.then(()=> {
ok(true);
done();
});
}); and that worked fine too so since your issue is between test runs .. maybe you forgot to call mockTeardown() at the end of each test? |
Thanks for the detailed response! My schedule is a bit hectic right now, but sometime this week I will try using |
|
can you show me a few of the component tests with setup |
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import {
make, makeList, manualSetup, mockQueryRecord, mockQuery
} from 'ember-data-factory-guy';
import wait from 'ember-test-helpers/wait';
import Ember from 'ember';
let results;
moduleForComponent(
'index-filter-bar', 'Integration | Component | index filter bar', {
integration: true,
beforeEach: function () {
manualSetup(this.container);
results = makeList('my-model',
{ name: 'Murphy', other_param: 'a' },
{ name: 'Stella', other_param: 'b' }
);
this.set('results', 'cookies');
}
});
test('it sets the filtering variable during filtering', function(assert) {
this.set('filtering', 'bananas');
mockQuery(
'my-model',
{ start_date: '2013/01/02', end_date: '2014/01/01'}
).returns({models: results});
this.render(hbs`{{index-filter-bar isFiltering=filtering}}`);
this.$('#filter').click();
assert.equal(this.get('filtering'), true);
return wait().then(() =>{
assert.equal(this.get('filtering'), false);
});
});
test('it sets componentVariable to [] on a 501 error', function(assert) {
// TypeError: _this2.get(...).get is not a function
// unless I change one of the params to be different
mockQuery(
'my-model',
{ start_date: '2013/01/02', end_date: '2014/01/01'}
).fails({status: 501});
this.render(hbs`{{index-filter-bar from='2013/02/02' componentVariable=results}}`);
this.$('#filter').click();
return wait().then(() =>{
assert.equal(this.get('results').get('length'), 0);
});
}); |
Note: This is actually with 2.7.3 now, not 2.7.2 |
do what you do for acceptance tests: import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import {
make, makeList, manualSetup, mockQueryRecord, mockQuery, mockSetup, mockTeardown
} from 'ember-data-factory-guy';
import wait from 'ember-test-helpers/wait';
import Ember from 'ember';
let results;
moduleForComponent(
'index-filter-bar', 'Integration | Component | index filter bar', {
integration: true,
beforeEach: function () {
manualSetup(this.container);
mockSetup();
results = makeList('my-model',
{ name: 'Murphy', other_param: 'a' },
{ name: 'Stella', other_param: 'b' }
);
this.set('results', 'cookies');
},
afterEach: function() {
mockTeardown();
}
}); |
Nice, that worked.
|
Oops... that was dumb. Feel like giving me a hand and fixing that? |
👍 |
Unrelated question: is there a way to change the mockjax logging level in |
I don't think so. I figured if you did mockSetup you would want to set those so I made it so you could do that in mockSetup: mockSetup({logLevel: 1, responseTime: 1000, mockjaxLogLevel: 4}); |
If I have two tests with different arguments to mockQuery (for example, one test makes it return 2 items and the other returns 3), both tests work fine.
When using
fails
though, the test suite seems to lock on the first assignment. For example, if I have on test dofails({status: 404})
and the other dofails({status: 501})
, both tests will fail with 404 (assuming the 404 test executed first). This also happens with success, so if a test with a success mock runs first, bothfails
tests will not get a failure.This behavior only happens when using the mock methods directly. If I use
TestHelper
, it works fine. This happened both in a component and acceptance test.I was originally on 2.4.4 trying to use mock methods directly. I upgraded to latest (2.7.2) to see if there was a bug fix, and tests that were previously passing with
TestHelper
started failing for hte same reason once I converted to use the helpers directly.The text was updated successfully, but these errors were encountered: