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
class CandidateImage extends HTMLElement { | |
connectedCallback() { | |
this.shadow = this.attachShadow({ mode: 'open' }); | |
// Create an image | |
const image = new Image(); | |
image.src = 'https://cdn-candidates.com/bernie.jpg'; | |
// We can use appendChild just like we do the normal document | |
this.shadow.appendChild(image); |
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
class CandidateImage extends HTMLElement { | |
connectedCallback() { | |
console.log('Adding a candidate!'); | |
this.innerHTML = '<img src="https://cdn-candidates.com/bernie.jpg" />'; | |
} | |
} | |
/** | |
* Register our custom element | |
*/ |
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
class CandidateImage extends HTMLElement { | |
connectedCallback() { | |
console.log('Adding a candidate!'); | |
this.innerHTML = '<img src="https://cdn-candidates.com/bernie.jpg" />'; | |
} | |
} |
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
// These are the mocked version of some firestore methods | |
// And we want to assert they are called correctly | |
const { | |
mockCollection, | |
mockGet, | |
mockWhere, | |
} = require('firestore-jest-mock/mocks/firestore'); | |
const { mockFirebase } = require('firestore-jest-mock'); |
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
const firebase = require('firebase'); | |
function maybeGetEventsByState(state) { | |
const db = firebase.firestore(); | |
const query = db.collection('events'); | |
if (state) { | |
query = query.where('state', '==', state); | |
} |
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
const { mockFirebase } = require('firestore-jest-mock'); | |
mockFirebase({ | |
database: { | |
users: [ | |
{ id: 'abc123', first: 'Bob', last: 'builder', born: 1998 }, | |
{ id: '123abc', first: 'Blues', last: 'builder', born: 1996 } | |
], | |
cities: [ | |
{ id: 'LA', name: 'Los Angeles', state: 'CA', country: 'USA' }, |
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
class FakeFirestore { | |
collection(name) { | |
this.currentCollection = name; | |
return this; | |
} | |
where() { | |
return this; | |
} |
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
const firebase = require('firebase'); | |
function getCurrentEventsByStateForAdmins(state) { | |
const db = firebase.firestore(); | |
db.collection('events') | |
.orderBy('expirationDate', 'asc') | |
.where('expirationDate', '>', new Date().toISOString()) | |
.where('state', '==', state) | |
.where('isAdmin', '==', true) |
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
const firebase = require('firebase'); | |
const db = firebase.firestore(); | |
db.collection("users").add({ | |
first: "Ada", | |
last: "Lovelace", | |
born: 1815 | |
}) | |
.then(function(docRef) { |
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
jest.mock('firebase', () => ({ | |
firestore: jest.fn().mockReturnValue({ | |
collection: jest.fn().mockReturnValue({ | |
add: jest.fn().mockResolvedValue({ | |
id: 'abc123' | |
}) | |
}) | |
}) | |
})); |