Firebase Test II
jsFiddle template to run a jasmine test inside jsFiddle. Adds jasmine external resources, and initializes jasmine's HtmlReporter on window load. For more infor check this article: http://opensas.wordpress.com/2013/06/23/sharing-you-javascript-ninja-secrets-run-your-jasmine-tests-on-jsfiddle/
by Alex Cowan
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.2.1/jasmine.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.2.1/jasmine-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.2.1/boot.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.2.1/jasmine.min.css">
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.2.5/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.5/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.5/firebase-analytics.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIzaSyCOPgDQ4PAwNtOxZQtkkRpy0LV37VVEzJg",
authDomain: "hinh-78995.firebaseapp.com",
projectId: "hinh-78995",
storageBucket: "hinh-78995.appspot.com",
messagingSenderId: "389014950808",
appId: "1:389014950808:web:5599635662f42697b091ed",
measurementId: "G-XL6BSRZLQE"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
JavaScript
//TESTING CODE
describe("Email domain validator", function() {
it('validates create of a review', function() {
expect(function() {
check_create_review(6, 'test', 'hUD1fH0lAxbUexRcc3ypmwjJRUG2')
}).toThrow();
});
});
//CODE UNDER TEST
//I can't get this to return true
db = firebase.firestore()
login_user('[email protected]', 'test123')
var userID = {}
function login_user(email, pwd) {
console.log("attempting to login user " + email);
// use the Firebase API to sign in the user
firebase.auth().signInWithEmailAndPassword(email, pwd).then(function(user) {
//clear the form inputs
console.log(firebase.auth().currentUser.uid)
//deal with errors
})
}
function check_create_review(rating1, review1, userid) {
file_path = '/parts/BR2048/reviews'
db.collection(file_path).doc().set({
rating: rating1,
review: review1,
user: userid
}).catch(error => {
console.log(error)
})
}