-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
How to erase contents in store() after each test? #83
Comments
We've also had issues with what I call the lifecycle of tests in ember and run across similar issues to this.
App.Foo = DS.Model.extend({
});
moduleForModel('foo', 'Foo model 1', {
teardown: function() {
}
});
test('Test 1', function() {
var store = this.store();
var model = this.subject({
id: 1
});
ok(model);
});
moduleForModel('foo', 'Foo model 2', {
teardown: function() {
}
});
test('Test 2', function() {
var store = this.store();
var model = this.subject({
id: 1
});
ok(model);
}); |
I made a helper function: // tests/helpers/store.js
import Ember from 'ember';
const {
run
} = Ember;
function waitForStore(assert, timeout=50) {
const done = assert.async();
run.later(this, function() {
done();
}, timeout);
}
export {
waitForStore
}; my tests look like that: import Ember from 'ember';
import { test, moduleForModel } from 'ember-qunit';
import { waitForStore } from '../../helpers/store';
const {
run
} = Ember;
moduleForModel('project', 'Project', {
needs: ['model:task']
});
test('it creates a simple project', function(assert) {
expect(1);
const store = this.store();
run(this, function() {
let project = store.createRecord('project', {
name: 'Simple project'
});
assert.equal(project.get('name'), 'Simple project');
assert.equal(project.get('tasks.length'), 0);
});
// extend the timeout waitForStore(assert, 100);
waitForStore(assert);
}); |
@fsmanuel Could you expand a little on what |
this seems no longer relevant, closing due to age |
Hi guys,
I am having an issue emptying out the store across my tests. This causes errors when I define models with the same id across multiple tests. Here is a really simply JSbin to illustrate - http://jsbin.com/qiwev/4/edit
The error I get is:
The commented out
this.store().unloadAll('foo');
onteardown
doesn't help either. So any suggestions on how I can reset the store across each test? Should that possibly be the default case as well to keep all tests independent? ThanksThe text was updated successfully, but these errors were encountered: