You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have two different Models that I am trying to test.
cats.spec.js:
var wolfpack = require('wolfpack');
var sinon = require('sinon');
var assert = require('assert');
global.Cat= wolfpack('../../../api/models/Cat');
wolfpack.clearResults();
wolfpack.setFindResults({
catId: 1,
type: 'Siamese'
});
describe('Cat Model', function () {
describe('example test', function() {
it ('should do something', function(done) {
Cat.findOne(1).then(function(results){
//results always contains the results set in the dog test
});
});
});
});
dog.spec.js:
var wolfpack = require('wolfpack');
var sinon = require('sinon');
var assert = require('assert');
global.Dog= wolfpack('../../../api/models/Dog');
wolfpack.clearResults();
wolfpack.setFindResults({
dogId: 1,
type: 'Lab'
});
describe('Dog Model', function () {
describe('example test', function() {
it ('should do something', function(done) {
Dog.findOne(1).then(function(results){
//results contain the correct dog object
});
});
});
});
It looks to me like when I try to run the test:
The results are cleared
Cat find results are set.
The results are cleared
Dog find results are set.
Then the tests are executed and only the Dog results are available in each test. Am I going about this the wrong way? When should I be setting the find results and when should I be clearing them? I want to define results for the Cat model and then have them available while I test the Cat Model. Then when I test the Dog model I want to clear the results, reset them and continue testing.
The text was updated successfully, but these errors were encountered:
Hey @mabashian. The issue you are having is because your code executes asynchronously. Even though you set the results correctly, wolfpack cannot determine which promise is fulfilled first, so by the time the Cat promise executes, the clearResults for the Dog already executed and the setFindResults for it as well. In this case, you must clear and set the results asynchronously as well for the tests
I have two different Models that I am trying to test.
cats.spec.js:
dog.spec.js:
It looks to me like when I try to run the test:
Then the tests are executed and only the Dog results are available in each test. Am I going about this the wrong way? When should I be setting the find results and when should I be clearing them? I want to define results for the Cat model and then have them available while I test the Cat Model. Then when I test the Dog model I want to clear the results, reset them and continue testing.
The text was updated successfully, but these errors were encountered: