mirror of
https://github.com/zhigang1992/reactfire.git
synced 2026-04-22 11:17:10 +08:00
- Got rid of JSXTransformer in test suite since it is not needed - Simplified firebaseRef validation (we ran into a Node bug with this old validation in GeoFire so we should change it here as well) - Added a bunch of tests to improve code coverage - Simplified existing tests
62 lines
2.1 KiB
JavaScript
62 lines
2.1 KiB
JavaScript
/*************/
|
|
/* GLOBALS */
|
|
/*************/
|
|
// Override the default timeout interval for Jasmine
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;
|
|
|
|
// Get a reference to a random demo Firebase
|
|
var demoFirebaseUrl = "https://" + generateRandomString() + ".firebaseio-demo.com";
|
|
|
|
// React test addon
|
|
var ReactTestUtils = React.addons.TestUtils;
|
|
|
|
// Define examples of valid and invalid parameters
|
|
var invalidFirebaseRefs = [null, undefined, true, false, [], 0, 5, "", "a", ["hi", 1]];
|
|
var validBindVars = ["a", "testing", "(e@Xi:4t>*E2)hc<5oa:1s6{B0d?u", Array(743).join("a")];
|
|
var invalidBindVars = ["", 1, true, false, [], {}, [1, 2], {a: 1}, null, undefined, "te.st", "te$st", "te[st", "te]st", "te#st", "te/st", "a#i]$da[s", "te/nst", "te/rst", "te/u0000st", "te/u0015st", "te/007Fst", Array(800).join("a")];
|
|
|
|
/**********************/
|
|
/* HELPER FUNCTIONS */
|
|
/**********************/
|
|
/* Helper function which runs before each Jasmine test has started */
|
|
function beforeEachHelper(done) {
|
|
// Create a new firebase ref with a new context
|
|
firebaseRef = new Firebase(demoFirebaseUrl, Firebase.Context());
|
|
|
|
// Reset the Firebase
|
|
firebaseRef.remove(function() {
|
|
// Create a new firebase ref at a random node
|
|
firebaseRef = firebaseRef.child(generateRandomString());
|
|
|
|
done();
|
|
});
|
|
}
|
|
|
|
/* Helper function which runs after each Jasmine test has completed */
|
|
function afterEachHelper(done) {
|
|
React.unmountComponentAtNode(document.body);
|
|
done();
|
|
}
|
|
|
|
/* Returns a random alphabetic string of variable length */
|
|
function generateRandomString() {
|
|
var possibleCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
var numPossibleCharacters = possibleCharacters.length;
|
|
|
|
var text = "";
|
|
for (var i = 0; i < 10; i++) {
|
|
text += possibleCharacters.charAt(Math.floor(Math.random() * numPossibleCharacters));
|
|
}
|
|
|
|
return text;
|
|
}
|
|
|
|
/* Returns the current data in the Firebase */
|
|
function getFirebaseData() {
|
|
return new RSVP.Promise(function(resolve, reject) {
|
|
firebaseRef.once("value", function(dataSnapshot) {
|
|
resolve(dataSnapshot.val());
|
|
});
|
|
});
|
|
};
|