mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-15 01:01:43 +10:00
Firebase mock: fix for property ServerValue.TIMESTAMP
This commit is contained in:
@ -157,9 +157,12 @@ const database = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
database.ServerValue = {
|
database.ServerValue = {};
|
||||||
TIMESTAMP: Date.now(),
|
Object.defineProperty(database.ServerValue, 'TIMESTAMP', {
|
||||||
};
|
get() {
|
||||||
|
return new Date().getTime();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export default class firebase {
|
export default class firebase {
|
||||||
static auth = auth;
|
static auth = auth;
|
||||||
|
|||||||
@ -78,7 +78,7 @@ describe('builder', () => {
|
|||||||
|
|
||||||
await ref.update({
|
await ref.update({
|
||||||
...resume,
|
...resume,
|
||||||
updatedAt: firebaseMock.database().ServerValue.TIMESTAMP,
|
updatedAt: firebaseMock.database.ServerValue.TIMESTAMP,
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() =>
|
await waitFor(() =>
|
||||||
|
|||||||
42
src/pages/app/__tests__/mock.test.js
Normal file
42
src/pages/app/__tests__/mock.test.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import { cleanup, waitFor } from '@testing-library/react';
|
||||||
|
|
||||||
|
import firebaseMock from 'gatsby-plugin-firebase';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
firebaseMock.database().__init();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(cleanup);
|
||||||
|
|
||||||
|
describe('builder', () => {
|
||||||
|
let resumeId = null;
|
||||||
|
let resume = null;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
resumeId = firebaseMock.database().__demoResumeId;
|
||||||
|
resume = (
|
||||||
|
await firebaseMock.database().ref(`resumes/${resumeId}`).once('value')
|
||||||
|
).val();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('test 1', async () => {
|
||||||
|
const now = new Date().getTime();
|
||||||
|
const newInputValue = 'test street 123';
|
||||||
|
resume.profile.address.line1 = newInputValue;
|
||||||
|
const ref = firebaseMock.database().ref(`resumes/${resumeId}`);
|
||||||
|
const functionSpy = jest.spyOn(ref, 'update');
|
||||||
|
|
||||||
|
await ref.update({
|
||||||
|
...resume,
|
||||||
|
updatedAt: firebaseMock.database.ServerValue.TIMESTAMP,
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => expect(functionSpy).toHaveBeenCalledTimes(1), {
|
||||||
|
timeout: 4000,
|
||||||
|
});
|
||||||
|
const functionCallArgument = functionSpy.mock.calls[0][0];
|
||||||
|
expect(functionCallArgument.id).toBe(resume.id);
|
||||||
|
expect(functionCallArgument.profile.address.line1).toBe(newInputValue);
|
||||||
|
expect(functionCallArgument.updatedAt).toBeGreaterThanOrEqual(now);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user