[TestSuite][Android] Fix #92 Adjust tests to reflect Reference.on() expected behaviour

This commit is contained in:
Aleck Greenham 2017-05-09 07:51:54 +01:00
parent febbca2e47
commit 4177e3e6bb
1 changed files with 46 additions and 3 deletions

View File

@ -1,9 +1,23 @@
import { Platform } from 'react-native';
import sinon from 'sinon';
import 'should-sinon';
import Promise from 'bluebird';
import DatabaseContents from '../../../support/DatabaseContents';
/**
* On Android, some data types result in callbacks that get called twice every time
* they are updated. This appears to be behaviour coming from the Android Firebase
* library itself.
*
* See https://github.com/invertase/react-native-firebase/issues/92 for details
*/
const DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS = [
'array',
'number'
];
function onTests({ describe, context, it, xit, firebase, tryCatch }) {
describe('ref().on(\'value\')', () => {
// Documented Web API Behaviour
@ -78,7 +92,12 @@ function onTests({ describe, context, it, xit, firebase, tryCatch }) {
// Assertions
callback.should.be.calledWith(newDataValue);
callback.should.be.calledTwice();
if (Platform.OS === 'android' && DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS.includes(dataRef)) {
callback.should.be.calledThrice();
} else {
callback.should.be.calledTwice();
}
// Tear down
@ -222,6 +241,20 @@ function onTests({ describe, context, it, xit, firebase, tryCatch }) {
callbackB.should.be.calledWith(currentDataValue);
callbackB.should.be.calledOnce();
const newDataValue = DatabaseContents.NEW[dataRef];
await ref.set(newDataValue);
callbackA.should.be.calledWith(newDataValue);
callbackB.should.be.calledWith(newDataValue);
if (Platform.OS === 'android' && DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS.includes(dataRef)) {
callbackA.should.be.calledThrice();
callbackB.should.be.calledThrice();
} else {
callbackA.should.be.calledTwice();
callbackB.should.be.calledTwice();
}
// Tear down
ref.off();
@ -280,7 +313,12 @@ function onTests({ describe, context, it, xit, firebase, tryCatch }) {
// Assertions
context.value.should.eql(newDataValue);
context.callCount.should.eql(2);
if (Platform.OS === 'android' && DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS.includes(dataRef)) {
context.callCount.should.eql(3);
} else {
context.callCount.should.eql(2);
}
// Tear down
@ -347,7 +385,12 @@ function onTests({ describe, context, it, xit, firebase, tryCatch }) {
// Assertions
context.value.should.eql(newDataValue);
context.callCount.should.eql(2);
if (Platform.OS === 'android' && DATATYPES_WITH_DUPLICATE_CALLBACK_CALLS.includes(dataRef)) {
context.callCount.should.eql(3);
} else {
context.callCount.should.eql(2);
}
// Tear down