Created
February 8, 2013 23:16
-
-
Save aaronksaunders/4742743 to your computer and use it in GitHub Desktop.
sample test spec for testing async calls in alloy application using behave.js
This file contains hidden or 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
//Setup module to run Behave tests | |
require('behave').andSetup(this); | |
describe('The model helper package: login USER', function() { | |
var ACSModels = new (require('models').MODELS)(Alloy); | |
it.eventually('*** logs in user', function(done) { | |
var model = ACSModels.createModel('user', { | |
"username" : "[email protected]", | |
"password" : "password", | |
}); | |
model.login(model.get("username"), model.get("password"), { | |
success : function() { debugger; | |
expect(model.id).notToBe(null); | |
expect(model.get("username")).toBe("[email protected]"); | |
//model.destroy(); | |
done(); | |
it.eventually('*** creates a book', function(_done) { | |
var book = ACSModels.createModel('object', { | |
"title" : "a book", | |
"author" : "Aaron K. Saunders" | |
}, 'book'); | |
book.save({}, { | |
success : function() { debugger; | |
expect(book.id).notToBe(null); | |
expect(book.get("title")).toBe("a book"); | |
expect(book.get("author")).toBe("Aaron K. Saunders"); | |
//book.destroy(); | |
_done(); | |
}, | |
error : function(_model, _response) { debugger; | |
expect(_response.meta.message).toBe(""); | |
_done(); | |
} | |
}); | |
}, 10000); | |
}, | |
error : function(_model, _response) { debugger; | |
expect(_response.meta.message).toBe(""); | |
done(); | |
} | |
}); | |
}, 10000); | |
}); | |
describe('The model helper package: LOGOUT USER', function() { | |
var ACSModels = new (require('models').MODELS)(Alloy); | |
it.eventually('*** logs in user', function(done) { | |
var model = ACSModels.createModel('user', { | |
"username" : "[email protected]", | |
"password" : "password", | |
}); | |
model.login(model.get("username"), model.get("password"), { | |
success : function() { debugger; | |
expect(model.id).notToBe(null); | |
expect(model.get("username")).toBe("[email protected]"); | |
//model.destroy(); | |
done(); | |
it.eventually('*** logs out user', function(_done) { | |
model.logout(null, { | |
success : function() { debugger; | |
//book.destroy(); | |
_done(); | |
}, | |
error : function(_model, _response) { debugger; | |
expect(_response.meta.message).toBe(""); | |
_done(); | |
} | |
}); | |
}, 10000); | |
}, | |
error : function(_model, _response) { debugger; | |
expect(_response.meta.message).toBe(""); | |
done(); | |
} | |
}); | |
}, 10000); | |
}); |
thx for the info
Great catch @sudsy!
Using @sudsy fix for me it doesn't work. I have some expectations that are not evaluated and test pass event.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't know if you noticed this but there is a bug in behave.js from the codestrong site that means that async tests pass even though they have not executed their callback. I found the changing line 65 of behave.js to the following worked for me.
else if ((that.expectations.length === 0 && that.done) || (time > that.timeout|| time > 10000)) {