Created
January 24, 2014 01:14
-
-
Save chestozo/8590280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('do not reset model status to ok if it was in error status', function() { | |
beforeEach(function() { | |
ns.Model.define('model1'); | |
ns.Model.define('model2'); | |
this.xhr = sinon.useFakeXMLHttpRequest(); | |
this.xhr.onCreate = function(xhr) { | |
window.setTimeout(function() { | |
xhr.respond( | |
200, | |
{"Content-Type": "application/json"}, | |
JSON.stringify({ | |
models: [ | |
{ error: 'unknown error' } | |
] | |
}) | |
); | |
}, 1); | |
}; | |
}); | |
afterEach(function() { | |
this.xhr.restore(); | |
}); | |
it('if model was requested and request was done it does not mean that we model is ok', function(done) { | |
var wait = 2; | |
var handleModels = function(models) { | |
var model1 = models[0]; | |
var model2 = models[1]; | |
expect(model1.status).to.be.eql(ns.M.STATUS.ERROR); | |
if (model2) { | |
expect(model2.status).to.be.eql(ns.M.STATUS.ERROR); | |
} | |
wait--; | |
if (!wait) { | |
done(); | |
} | |
}; | |
// Тут какая-то хитрая комбинация запросов должна была быть, чтобы в какой-то момент при запросе модели она бы оказалась | |
// уже запрошена и мы бы просто проставили ей руками статус ok. | |
ns.request([ 'model1', 'model2' ]).done(handleModels); | |
ns.request('model1').done(handleModels); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment